onnx.helper#

tools#

onnx.helper.find_min_ir_version_for(opsetidlist: List[OperatorSetIdProto]) int#

Given list of opset ids, determine minimum IR version required

onnx.helper.split_complex_to_pairs(ca: Sequence[complex64]) Sequence[int]#

make function#

All functions uses to create an ONNX graph.

onnx.helper.make_attribute(key: str, value: Any, doc_string: Optional[str] = None) AttributeProto#

Makes an AttributeProto based on the value type.

onnx.helper.make_empty_tensor_value_info(name: str) ValueInfoProto#
onnx.helper.make_function(domain: str, fname: str, inputs: Sequence[str], outputs: Sequence[str], nodes: Sequence[NodeProto], opset_imports: Sequence[OperatorSetIdProto], attributes: Optional[Sequence[str]] = [], doc_string: Optional[str] = None) FunctionProto#
onnx.helper.make_graph(nodes: Sequence[NodeProto], name: str, inputs: Sequence[ValueInfoProto], outputs: Sequence[ValueInfoProto], initializer: Optional[Sequence[TensorProto]] = None, doc_string: Optional[str] = None, value_info: Sequence[ValueInfoProto] = [], sparse_initializer: Optional[Sequence[SparseTensorProto]] = None) GraphProto#

Construct a GraphProto

Parameters:
  • nodes – list of NodeProto

  • name (string) – graph name

  • inputs – list of ValueInfoProto

  • outputs – list of ValueInfoProto

  • initializer – list of TensorProto

  • doc_string (string) – graph documentation

  • value_info – list of ValueInfoProto

  • sparse_initializer – list of SparseTensorProto

Returns:

GraphProto

onnx.helper.make_map(name: str, key_type: int, keys: List[Any], values: SequenceProto) MapProto#

Make a Map with specified key-value pair arguments.

Criteria for conversion: - Keys and Values must have the same number of elements - Every key in keys must be of the same type - Every value in values must be of the same type

onnx.helper.make_model(graph: GraphProto, **kwargs: Any) ModelProto#

Construct a ModelProto

Parameters:
  • graph (GraphProto) – make_graph returns

  • **kwargs – any attribute to add to the returned instance

Returns:

ModelProto

onnx.helper.make_node(op_type: str, inputs: Sequence[str], outputs: Sequence[str], name: Optional[str] = None, doc_string: Optional[str] = None, domain: Optional[str] = None, **kwargs: Any) NodeProto#

Construct a NodeProto.

Parameters:
  • op_type (string) – The name of the operator to construct

  • inputs (list of string) – list of input names

  • outputs (list of string) – list of output names

  • name (string, default None) – optional unique identifier for NodeProto

  • doc_string (string, default None) – optional documentation string for NodeProto

  • domain (string, default None) – optional domain for NodeProto. If it’s None, we will just use default domain (which is empty)

  • **kwargs (dict) – the attributes of the node. The acceptable values are documented in make_attribute().

Returns:

NodeProto

onnx.helper.make_operatorsetid(domain: str, version: int) OperatorSetIdProto#

Construct an OperatorSetIdProto.

Parameters:
  • domain (string) – The domain of the operator set id

  • version (integer) – Version of operator set id

Returns:

OperatorSetIdProto

onnx.helper.make_opsetid(domain: str, version: int) OperatorSetIdProto#

Construct an OperatorSetIdProto.

Parameters:
  • domain (string) – The domain of the operator set id

  • version (integer) – Version of operator set id

Returns:

OperatorSetIdProto

onnx.helper.make_optional(name: str, elem_type: <google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper object at 0x7f68098a80d0>, value: ~typing.Optional[~typing.Any]) OptionalProto#

Make an Optional with specified value arguments.

onnx.helper.make_optional_type_proto(inner_type_proto: TypeProto) TypeProto#

Makes an optional TypeProto.

onnx.helper.make_sequence(name: str, elem_type: <google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper object at 0x7f68098a83a0>, values: ~typing.Sequence[~typing.Any]) SequenceProto#

Make a Sequence with specified value arguments.

onnx.helper.make_sequence_type_proto(inner_type_proto: TypeProto) TypeProto#

Makes a sequence TypeProto.

onnx.helper.make_sparse_tensor(values: TensorProto, indices: TensorProto, dims: Sequence[int]) SparseTensorProto#

Construct a SparseTensorProto

Parameters:
Returns:

SparseTensorProto

onnx.helper.make_sparse_tensor_type_proto(elem_type: int, shape: Optional[Sequence[Optional[Union[str, int]]]], shape_denotation: Optional[List[str]] = None) TypeProto#

Makes a SparseTensor TypeProto based on the data type and shape.

onnx.helper.make_sparse_tensor_value_info(name: str, elem_type: int, shape: Optional[Sequence[Optional[Union[str, int]]]], doc_string: str = '', shape_denotation: Optional[List[str]] = None) ValueInfoProto#

Makes a SparseTensor ValueInfoProto based on the data type and shape.

onnx.helper.make_tensor(name, data_type, dims, vals, raw=False)#

Make a TensorProto with specified arguments. If raw is False, this function will choose the corresponding proto field to store the values based on data_type. If raw is True, use “raw_data” proto field to store the values, and values should be of type bytes in this case.

onnx.helper.make_tensor_sequence_value_info(name: str, elem_type: int, shape: Optional[Sequence[Optional[Union[str, int]]]], doc_string: str = '', elem_shape_denotation: Optional[List[str]] = None) ValueInfoProto#

Makes a Sequence[Tensors] ValueInfoProto based on the data type and shape.

onnx.helper.make_tensor_type_proto(elem_type: int, shape: Optional[Sequence[Optional[Union[str, int]]]], shape_denotation: Optional[List[str]] = None) TypeProto#

Makes a Tensor TypeProto based on the data type and shape.

onnx.helper.make_training_info(algorithm: GraphProto, algorithm_bindings: List[Tuple[str, str]], initialization: Optional[GraphProto], initialization_bindings: Optional[List[Tuple[str, str]]]) TrainingInfoProto#
onnx.helper.make_tensor_type_proto(elem_type: int, shape: Optional[Sequence[Optional[Union[str, int]]]], shape_denotation: Optional[List[str]] = None) TypeProto#

Makes a Tensor TypeProto based on the data type and shape.

onnx.helper.make_tensor_value_info(name: str, elem_type: int, shape: Optional[Sequence[Optional[Union[str, int]]]], doc_string: str = '', shape_denotation: Optional[List[str]] = None) ValueInfoProto#

Makes a ValueInfoProto based on the data type and shape.

onnx.helper.make_value_info(name: str, type_proto: TypeProto, doc_string: str = '') ValueInfoProto#

Makes a ValueInfoProto with the given type_proto.

getter#

onnx.helper.get_attribute_value(attr: AttributeProto) Any#

print#

onnx.helper.printable_attribute(attr: AttributeProto, subgraphs: bool = False) Union[str, Tuple[str, List[GraphProto]]]#
onnx.helper.printable_dim(dim: Dimension) str#
onnx.helper.printable_graph(graph: GraphProto, prefix: str = '') str#

Display a GraphProto as a string.

Parameters:
  • graph (GraphProto) – the graph to display

  • prefix (string) – prefix of every line

Returns:

string

onnx.helper.printable_node(node: NodeProto, prefix: str = '', subgraphs: bool = False) Union[str, Tuple[str, List[GraphProto]]]#
onnx.helper.printable_tensor_proto(t: TensorProto) str#
onnx.helper.printable_type(t: TypeProto) str#
onnx.helper.printable_value_info(v: ValueInfoProto) str#