ONE - On-device Neural Engine
|
Public Member Functions | |
__init__ (self, model) | |
make_tensor_with_base_name (self, base_name) | |
make_node (self, opcode, inputs, outputs, *p_args, **k_args) | |
make_split (self, input, split_sizes, axis) | |
make_concat (self, inputs, axis) | |
make_squeeze (self, input, axes) | |
make_unsqueeze (self, input, axes) | |
make_gemm (self, A, B, C, trans_a=False, trans_b=False) | |
make_add (self, a, b) | |
make_mul (self, a, b) | |
make_clip (self, input, min, max) | |
make_act (self, input, act_name) | |
make_constant_tensor (self, tensor_data, base_name) | |
mark_for_deletion (self, node) | |
get_insert_id (self) | |
set_insert_id (self, insert_id) | |
delete_marked_nodes (self) | |
Protected Attributes | |
_model | |
_nodes_to_delete | |
_insert_id | |
_base_name_idx | |
Helper for onnx model transformation This helper is used for convenient operation replacement in onnx model Attributes: _model (onnx.onnx_ml_pb2.ModelProto): target model that should be changed _nodes_to_delete (list of onnx.onnx_ml_pb2.NodeProto): list of replaced operations _insert_id (int): position to insert created operations (should be in topologically sorted) _base_name_idx (dict from str to int): maps tensor "base" name to largest existing serial num. For example model has tensors "t_1", "t_2", "t_4", in that case _base_name_idx["t_"] == 4. This attribute is used for unique tensor name generation.
Definition at line 75 of file onnx_legalizer.py.
onnx_legalizer._ModelTransformerHelper.__init__ | ( | self, | |
model | |||
) |
Definition at line 89 of file onnx_legalizer.py.
onnx_legalizer._ModelTransformerHelper.delete_marked_nodes | ( | self | ) |
Definition at line 293 of file onnx_legalizer.py.
References SingleOperatorTest.SingleOperatorTest._model, ScalarOperandDecl._model, TensorOperandDecl._model, WeightDecl._model, OperationDecl._model, luci::CircleReader._model, mir_onnx::ONNXImporterImpl._model, mir_tflite::TfliteImporter._model, GenericBackend._model, onnx_legalizer._ModelTransformerHelper._model, DotBuilder.DotBuilder._model, luci_interpreter::CircleReader._model, onert_micro::core::reader::OMCircleReader._model, onert::compiler::Compiler._model, onert::exporter::CircleExporter._model, onert::compiler::train::TrainingCompiler._model, onert::loader::BaseLoader< LoaderDomain >._model, and onnx_legalizer._ModelTransformerHelper._nodes_to_delete.
onnx_legalizer._ModelTransformerHelper.get_insert_id | ( | self | ) |
Definition at line 287 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper._insert_id.
onnx_legalizer._ModelTransformerHelper.make_act | ( | self, | |
input, | |||
act_name | |||
) |
Create activation function operation and insert it in graph. Args: input (str): input tensor name act_name (str): name of activation function, one of ['Relu', 'Tanh', 'Sigmoid'] Returns: str: output tensor name
Definition at line 256 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_add | ( | self, | |
a, | |||
b | |||
) |
Creates Add operation and insert it in graph. Args: a (str): name of left operand tensor b (str): name of right operand tensor Returns: str: output tensor name
Definition at line 219 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_clip | ( | self, | |
input, | |||
min, | |||
max | |||
) |
Create Clip operation and insert it in graph. Args: input (str): input tensor name min (int/float): lower clip bound max (int/float ): upper clip bound Returns: str: output tensor name
Definition at line 243 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_concat | ( | self, | |
inputs, | |||
axis | |||
) |
Create Concat operation and insert it in graph. Args: inputs (list of str): list of tensors names to concat axis (int): axis number to concat Returns: str: output tensor name
Definition at line 163 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_constant_tensor | ( | self, | |
tensor_data, | |||
base_name | |||
) |
Creates onnx constant tensor Args: tensor_data (numpy.ndarray): tensor data base_name (str): prefix of constant tensor name Returns: str: name of created constant tensor
Definition at line 269 of file onnx_legalizer.py.
References SingleOperatorTest.SingleOperatorTest._model, ScalarOperandDecl._model, TensorOperandDecl._model, WeightDecl._model, OperationDecl._model, luci::CircleReader._model, mir_onnx::ONNXImporterImpl._model, mir_tflite::TfliteImporter._model, GenericBackend._model, onnx_legalizer._ModelTransformerHelper._model, DotBuilder.DotBuilder._model, luci_interpreter::CircleReader._model, onert_micro::core::reader::OMCircleReader._model, onert::compiler::Compiler._model, onert::exporter::CircleExporter._model, onert::compiler::train::TrainingCompiler._model, onert::loader::BaseLoader< LoaderDomain >._model, and onnx_legalizer._ModelTransformerHelper.make_tensor_with_base_name().
onnx_legalizer._ModelTransformerHelper.make_gemm | ( | self, | |
A, | |||
B, | |||
C, | |||
trans_a = False , |
|||
trans_b = False |
|||
) |
Create Gemm operation and insert it in graph. Result tensor contains A*B + C Args: A (str): name of tensor A B (str): name of tensor B C (str): name of tensor C transA (bool): if True, transpose tensor A before multiplication transB (bool): if True, transpose tensor B before multiplication Returns: str: output tensor name
Definition at line 199 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_mul | ( | self, | |
a, | |||
b | |||
) |
Creates Mul operation and insert it in graph. Args: a (str): name of left operand tensor b (str): name of right operand tensor Returns: str: output tensor name
Definition at line 231 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_node | ( | self, | |
opcode, | |||
inputs, | |||
outputs, | |||
* | p_args, | ||
** | k_args | ||
) |
Create arbitrary node and insert it in graph. Args: opcode (str): opcode name of desired operation inputs (list of str): names of input tensors outputs (list of str or int): names of existing tensors to use as output tensors for operation or number of tensors that should be created p_args: additional arguments for onnx make_node helper k_args: attributes for onnx node Returns: list of str: list of output tensor names
Definition at line 125 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper._insert_id, SingleOperatorTest.SingleOperatorTest._model, ScalarOperandDecl._model, TensorOperandDecl._model, WeightDecl._model, OperationDecl._model, luci::CircleReader._model, mir_onnx::ONNXImporterImpl._model, mir_tflite::TfliteImporter._model, GenericBackend._model, onnx_legalizer._ModelTransformerHelper._model, DotBuilder.DotBuilder._model, luci_interpreter::CircleReader._model, onert_micro::core::reader::OMCircleReader._model, onert::compiler::Compiler._model, onert::exporter::CircleExporter._model, onert::compiler::train::TrainingCompiler._model, onert::loader::BaseLoader< LoaderDomain >._model, and onnx_legalizer._ModelTransformerHelper.make_tensor_with_base_name().
Referenced by onnx_legalizer._ModelTransformerHelper.make_act(), onnx_legalizer._ModelTransformerHelper.make_add(), onnx_legalizer._ModelTransformerHelper.make_clip(), onnx_legalizer._ModelTransformerHelper.make_concat(), onnx_legalizer._ModelTransformerHelper.make_gemm(), onnx_legalizer._ModelTransformerHelper.make_mul(), onnx_legalizer._ModelTransformerHelper.make_split(), onnx_legalizer._ModelTransformerHelper.make_squeeze(), and onnx_legalizer._ModelTransformerHelper.make_unsqueeze().
onnx_legalizer._ModelTransformerHelper.make_split | ( | self, | |
input, | |||
split_sizes, | |||
axis | |||
) |
Create Split operation and insert it in graph. Args: input (str): name of input tensor split_sizes (list of int): list of split sizes axis (int): number of axis to split Returns: list: list of output tensor names
Definition at line 147 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_squeeze | ( | self, | |
input, | |||
axes | |||
) |
Create Squeeze operation and insert it in graph. Args: input (str): name of input tensor axes (list of int): list of dimension containing ones to remove Returns: str: output tensor name
Definition at line 175 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_tensor_with_base_name | ( | self, | |
base_name | |||
) |
Create unique name for given base_name Args: base_name (str): base tensor name Returns: str : unique tensor name that starts with base_name
Definition at line 109 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper._base_name_idx.
Referenced by onnx_legalizer._ModelTransformerHelper.make_constant_tensor(), and onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.make_unsqueeze | ( | self, | |
input, | |||
axes | |||
) |
Create Unsqueeze operation and insert it in graph. Args: input (str): name of input tensor axes (list of int): list of dimension to insert ones Returns: str: output tensor name
Definition at line 187 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper.make_node().
onnx_legalizer._ModelTransformerHelper.mark_for_deletion | ( | self, | |
node | |||
) |
Definition at line 284 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper._nodes_to_delete.
onnx_legalizer._ModelTransformerHelper.set_insert_id | ( | self, | |
insert_id | |||
) |
Definition at line 290 of file onnx_legalizer.py.
References onnx_legalizer._ModelTransformerHelper._insert_id.
|
protected |
Definition at line 98 of file onnx_legalizer.py.
Referenced by onnx_legalizer._ModelTransformerHelper.make_tensor_with_base_name().
|
protected |
Definition at line 92 of file onnx_legalizer.py.
Referenced by onnx_legalizer._ModelTransformerHelper.get_insert_id(), onnx_legalizer._ModelTransformerHelper.make_node(), and onnx_legalizer._ModelTransformerHelper.set_insert_id().
|
protected |
Definition at line 90 of file onnx_legalizer.py.
Referenced by onnx_legalizer._ModelTransformerHelper.delete_marked_nodes(), onnx_legalizer._ModelTransformerHelper.make_constant_tensor(), onnx_legalizer._ModelTransformerHelper.make_node(), and DotBuilder.DotBuilder.save().
|
protected |
Definition at line 91 of file onnx_legalizer.py.
Referenced by onnx_legalizer._ModelTransformerHelper.delete_marked_nodes(), and onnx_legalizer._ModelTransformerHelper.mark_for_deletion().