ONNX graph ops utility¶
Collections of utilty to manipulate onnx graph.
-
vortex.runtime.onnx.graph_ops.embed_model_property.
embed_model_property
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, props: Dict[str, Any])¶ Embed information to model, including ‘output_format’ and ‘class_names’
- Parameters
model (onnx.ModelProto) – model
props (Dict[str,Any]) – information, must include ‘output_format’ and ‘class_names’
- Returns
model
- Return type
onnx.ModelProto
-
vortex.runtime.onnx.graph_ops.embed_class_names_metadata.
embed_class_names_metadata
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, class_names: Union[List[str], Dict])¶ Embed class_names information to model
-
vortex.runtime.onnx.graph_ops.embed_output_format_metadata.
embed_output_format_metadata
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, output_format: Dict[str, Union[List[int], int]])¶ Format each ‘output’ in ‘output_format’ and embed it to existing model
- Parameters
- Raises
TypeError – value type of output_format is not dictionary
ValueError – each entry in output_format doesnt contains ‘indices’ and/or ‘axis’
- Returns
model with output_format embedded
- Return type
onnx.ModelProto
-
vortex.runtime.onnx.graph_ops.embed_metadata.
embed_metadata
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, key: str, value: Any) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Embed information to existing model
-
class
vortex.runtime.onnx.graph_ops.embed_metadata.
EmbedMetadata
(key: str, value: Any)¶ -
__call__
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Transform model, call derived run function.
- Parameters
model (onnx.ModelProto) – model to be transformed
- Returns
transformed model
- Return type
onnx.ModelProto
-
classmethod
apply
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, key: str, value: Any) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Embed information to existing model
-
classmethod
parse
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, key: str)¶ Parse metadata stored at model using json
- Parameters
model (onnx.ModelProto) – model to be extracted
key (str) – metadata key
- Returns
json.loads result or None if key not exists
- Return type
Any
-
run
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Run transformation
- Parameters
model (onnx.ModelProto) – model
- Returns
model with embedded metadata
- Return type
onnx.ModelProto
-
-
class
vortex.runtime.onnx.graph_ops.embed_model_property.
EmbedModelProperty
(props)¶ -
__call__
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Transform model, call derived run function.
- Parameters
model (onnx.ModelProto) – model to be transformed
- Returns
transformed model
- Return type
onnx.ModelProto
-
classmethod
apply
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, props: Dict[str, Any])¶ Embed information to model, including ‘output_format’ and ‘class_names’
- Parameters
model (onnx.ModelProto) – model
props (Dict[str,Any]) – information, must include ‘output_format’ and ‘class_names’
- Returns
model
- Return type
onnx.ModelProto
-
classmethod
parse
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → Dict[str, Any]¶ Extract output_format and class_names from model
- Parameters
model (onnx.ModelProto) – model
- Returns
dictionary contains ‘output_format’ and ‘class_names’
- Return type
Dict[str,Any]
-
run
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Run transformation
- Parameters
model (onnx.ModelProto) – model
- Returns
model
- Return type
onnx.ModelProto
-
-
class
vortex.runtime.onnx.graph_ops.embed_class_names_metadata.
EmbedClassNamesMetadata
(class_names: Union[List[str], Dict])¶ -
__call__
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Transform model, call derived run function.
- Parameters
model (onnx.ModelProto) – model to be transformed
- Returns
transformed model
- Return type
onnx.ModelProto
-
classmethod
apply
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, class_names: Union[List[str], Dict])¶ Embed class_names information to model
-
classmethod
parse
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → Dict[int, str]¶ Extract class_names information from model
- Parameters
model (onnx.ModelProto) – model
- Raises
ValueError – if model doesn’t contains class_labels
- Returns
a mapping from class label (int) to class name
- Return type
-
-
class
vortex.runtime.onnx.graph_ops.embed_output_format_metadata.
EmbedOutputFormatMetadata
(output_format: Dict[str, Union[List[int], int]])¶ -
__call__
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto¶ Transform model, call derived run function.
- Parameters
model (onnx.ModelProto) – model to be transformed
- Returns
transformed model
- Return type
onnx.ModelProto
-
classmethod
apply
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto, output_format: Dict[str, Union[List[int], int]])¶ Format each ‘output’ in ‘output_format’ and embed it to existing model
- Parameters
- Raises
TypeError – value type of output_format is not dictionary
ValueError – each entry in output_format doesnt contains ‘indices’ and/or ‘axis’
- Returns
model with output_format embedded
- Return type
onnx.ModelProto
-
classmethod
parse
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto) → Dict[str, Union[List[int], int]]¶ Extract and parse output_format information from model
-
run
(model: onnx.onnx_ONNX_REL_1_6_ml_pb2.ModelProto)¶ run fn, as required by base class
- Parameters
model (onnx.ModelProto) – model to be transformed
- Returns
transformed model
- Return type
onnx.ModelProto
-