sima_utils.onnx.model_builderο
Attributesο
Classesο
Helper class to build onnx model. |
Functionsο
|
Gets the output name of the given node with only one output. |
Module Contentsο
- sima_utils.onnx.model_builder.OnnxNodeο
- sima_utils.onnx.model_builder.get_onnx_node_output_name(node: OnnxNode) strο
Gets the output name of the given node with only one output.
Args: node: A node in ONNX model.
- Returns:
A string corresponding to the nodeβs single output.
- class sima_utils.onnx.model_builder.OnnxModelBuilderο
Helper class to build onnx model.
- Usage:
# Initialization builder = OnnxModelBuilder()
# Create arbitrary number of model inputs input_node = builder.create_input_node(βinputβ, input_shape, input_dtype)
# Create nodes; use helper functions provided for each operation type. conv_node = builder.make_conv_node(input_node, np_weights, np_bias, **conv_attrs) β¦
# Create model outputs; use get_onnx_node_output_name to get the names from output nodes builder.create_output_node(get_onnx_node_output_name(conv_node), output_shape, output_dtype)
# Finalize model and save to a file builder.create_and_save_model(Path(onnx_file_path))
- IR_VERSIONο
IR version of the onnx model.
- OPSET_IDο
Operator set id of the onnx model.
- _input_nodesο
Input nodes of the onnx model.
- _output_nodesο
Output nodes of the onnx model.
- _initializer_listο
List of initializers (constants) used in the model.
- _node_listο
List of nodes created for a model.
- _op_countο
Dictionary keeping track of quantity of created nodes per op_type.
- IR_VERSION: ClassVar[int] = 8ο
- OPSET_ID: ClassVar[int] = 17ο
- create_model(model_name: str) onnx.ModelProtoο
Creates the model.
- Parameters:
model_name β The name of the model.
- Returns:
An ONNX ModelProto object defining the ONNX model.
- create_and_save_model(onnx_file_name: pathlib.Path)ο
Creates and saves the model, performing also shape inference in the process.
- Parameters:
onnx_file_name β A path to the file in which the ONNX model will be saved.
- create_input_node(name: str, shape: collections.abc.Sequence[int], dtype: type = np.float32) OnnxNodeο
Creates an input node with the provided name, shape and data type.
- Parameters:
name β Inputβs name.
shape β Inputβs shape.
dtype β Inputβs data type.
- Returns:
The OnnxNode object (onnx.ValueInfoProto) for the created input node.
- create_output_node(name: str, shape: collections.abc.Sequence[int], dtype: type = np.float32)ο
Creates an output node with the provided name, shape and data type.
- Parameters:
name β Outputβs name.
shape β Outputβs shape.
dtype β Outputβs data type.
- create_initializer(name: str | None, value: int | float | numpy.ndarray) OnnxNodeο
Creates an initializer with the name.
- Parameters:
name β Name of the initializer. If name is None, use βConstant_{idx}β.
value β Value of the initializer.
- Returns:
An OnnxNode object (onnx.TensorProto) created for the initializer.
- build_op(input_nodes: collections.abc.Sequence[OnnxNode], op_type: str, **kwargs) OnnxNodeο
Builds an ONNX node.
- Parameters:
input_nodes β A list of input nodes.
op_type β Name of the operator type.
**kwargs β Operator attributes.
- Returns:
Created OnnxNode (onnx.NodeProto) object.
- make_conv_node(input_node: OnnxNode, weight: numpy.ndarray, bias: numpy.ndarray | None = None, auto_pad: str | None = None, dilations: collections.abc.Sequence[int] | None = None, strides: collections.abc.Sequence[int] | None = None, group: int | None = None, kernel_shape: collections.abc.Sequence[int] | None = None, pads: collections.abc.Sequence[int] | None = None) OnnxNodeο
Create an ONNX Conv operator node. https://onnx.ai/onnx/operators/onnx__Conv.html#conv-11
- Parameters:
input_node β Input node to Conv operator node.
weight β Weight tensor numpy array.
bias β Optional 1D bias tensor numpy array.
auto_pad β Optional string value for Conv βauto_padβ attribute. Valid values are NOTSET, SAME_UPPER, SAME_LOWER and VALID. If None, the βauto_padβ attribute will take the default (NOTSET) value.
dilations β Optional sequence of integers for Conv βdilationsβ attribute. If None, the βdilationsβ attribute will be set to 1 along each spatial axis.
strides β Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.
group β Optional integer value for Conv βgroupsβ attribute. If None, the βgroupsβ attribute will be set to 1.
kernel_shape β Optional sequence of integers for Conv βkernel_shapeβ attribute. If None, the βkernel_shapeβ attribute will be inferred from weight shape.
pads β Optional sequence of integers for Conv βpadsβ attribute. If None, the βpadsβ attribute will be set to 0 along start and end of each spatial axis.
- Returns:
Onnx NodeProto instance containing the Conv operation.
- make_conv_transpose_node(input_node: OnnxNode, weight: numpy.ndarray, bias: numpy.ndarray | None = None, auto_pad: str | None = None, dilations: collections.abc.Sequence[int] | None = None, strides: collections.abc.Sequence[int] | None = None, group: int | None = None, kernel_shape: collections.abc.Sequence[int] | None = None, pads: collections.abc.Sequence[int] | None = None, output_padding: collections.abc.Sequence[int] | None = None, output_shape: collections.abc.Sequence[int] | None = None) OnnxNodeο
Create an ONNX ConvTranspose operator node. https://onnx.ai/onnx/operators/onnx__ConvTranspose.html#convtranspose-11
- Parameters:
input_node β Input node to ConvTranspose operator node.
weight β Weight tensor numpy array.
bias β Optional 1D bias tensor numpy array.
auto_pad β Optional string value for Conv βauto_padβ attribute. Valid values are NOTSET, SAME_UPPER, SAME_LOWER and VALID. If None, the βauto_padβ attribute will take the default (NOTSET) value.
dilations β Optional sequence of integers for Conv βdilationsβ attribute. If None, the βdilationsβ attribute will be set to 1 along each spatial axis.
strides β Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.
group β Optional integer value for Conv βgroupsβ attribute. If None, the βgroupsβ attribute will be set to 1.
kernel_shape β Optional sequence of integers for Conv βkernel_shapeβ attribute. If None, the βkernel_shapeβ attribute will be inferred from weight shape.
pads β Optional sequence of integers for Conv βpadsβ attribute. If None, the βpadsβ attribute will be set to 0 along start and end of each spatial axis.
output_padding β Optional sequence of ints to add output shape padding (per spatial axis). Defaults to 0 per spatial axis if None. Typically not used together with output_shape.
output_shape β Optional sequence of ints to explicitly set the output spatial shape.
- Returns:
Onnx NodeProto instance containing the ConvTranspose operation.
- make_avg_pool_node(input_node: OnnxNode, kernel_shape: collections.abc.Sequence[int], strides: collections.abc.Sequence[int] | None = None, pads: collections.abc.Sequence[int] | None = None, ceil_mode: bool = False, count_include_pad: bool = False, auto_pad: str = 'NOTSET') OnnxNodeο
Create an ONNX AveragePool operator node. https://onnx.ai/onnx/operators/onnx__AveragePool.html#averagepool-11
- Parameters:
input_node β Input node to the AveragePool operator node.
kernel_shape β The size of the kernel along each axis.
strides β Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
pads β Padding for the beginning and ending along each spatial axis. If None, pads default to 0 along start and end of each spatial axis.
ceil_mode β Whether to use ceil or floor (default) to compute the output shape.
count_include_pad β Whether include pad pixels when calculating values for the edges. Default is 0, doesnβt count include pad.
auto_pad β Valid values are NOTSET, SAME_UPPER, SAME_LOWER, and VALID. Default is βNOTSETβ.
- Returns:
Onnx NodeProto instance containing the AveragePool operation.
- make_global_avg_pool_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX GlobalAveragePool operator node. https://onnx.ai/onnx/operators/onnx__GlobalAveragePool.html#globalaveragepool-1
- Parameters:
input_node β Input node to the GlobalAveragePool operator node.
- Returns:
Onnx NodeProto instance containing the GlobalAveragePool operation.
- make_global_max_pool_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX GlobalMaxPool operator node. https://onnx.ai/onnx/operators/onnx__GlobalMaxPool.html#globalmaxpool-1
- Parameters:
input_node β Input node to the GlobalMaxPool operator node.
- Returns:
Onnx NodeProto instance containing the GlobalMaxPool operation.
- make_max_pool_node(input_node: OnnxNode, kernel_shape: collections.abc.Sequence[int], dilations: collections.abc.Sequence[int] | None = None, strides: collections.abc.Sequence[int] | None = None, pads: collections.abc.Sequence[int] | None = None, ceil_mode: bool = False, storage_order: int = 0, auto_pad: str = 'NOTSET') OnnxNodeο
Create an ONNX MaxPool operator node. https://onnx.ai/onnx/operators/onnx__MaxPool.html#maxpool-12
- Parameters:
input_node β Input node to the MaxPool operator node.
kernel_shape β The size of the kernel along each axis.
dilations β Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.
strides β Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
pads β Padding for the beginning and ending along each spatial axis. If None, pads default to 0 along start and end of each spatial axis.
ceil_mode β Whether to use ceil or floor (default) to compute the output shape.
storage_order β The storage order of the tensor. 0 is row major, and 1 is column major.
auto_pad β Valid values are NOTSET, SAME_UPPER, SAME_LOWER, and VALID. Default is βNOTSETβ.
- Returns:
Onnx NodeProto instance containing the MaxPool operation.
- make_batch_normalization_node(input_node: OnnxNode, scale: OnnxNode | numpy.ndarray, bias: OnnxNode | numpy.ndarray, input_mean: OnnxNode | numpy.ndarray, input_var: OnnxNode | numpy.ndarray, epsilon: float = 1e-05, momentum: float = 0.9) OnnxNodeο
Create an ONNX BatchNormalization operator node. https://onnx.ai/onnx/operators/onnx__BatchNormalization.html#batchnormalization-15
- Parameters:
input_node β Input node to the BatchNormalization operator node.
scale β Scale tensor of shape C. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
bias β Bias tensor of shape C. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
input_mean β Mean tensor of shape C. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
input_var β Variance tensor of shape C. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
epsilon β The epsilon value to use to avoid division by zero. Default is 1e-05.
momentum β Float value for the momentum used in running mean and variance computation.
- Returns:
Onnx NodeProto instance containing the BatchNormalization operation.
- make_clip_node(input_node: OnnxNode, min: numpy.ndarray | None = None, max: numpy.ndarray | None = None) OnnxNodeο
Create an ONNX Clip operator node. https://onnx.ai/onnx/operators/onnx__Clip.html#clip-13
- Parameters:
input_node β Input node to the Clip operator node.
min β Minimum value for clipping. If None, no lower bound is applied.
max β Maximum value for clipping. If None, no upper bound is applied.
- Returns:
Onnx NodeProto instance containing the Clip operation.
- make_concat_node(input_nodes: list[OnnxNode], axis: int) OnnxNodeο
Create an ONNX Concat operator node. https://onnx.ai/onnx/operators/onnx__Concat.html#concat-13
- Parameters:
input_nodes β List of input nodes to be concatenated.
axis β Which axis to concat on.
- Returns:
Onnx NodeProto instance containing the Concat operation.
- make_einsum_node(input_nodes: list[OnnxNode], equation: str) OnnxNodeο
Create an ONNX Einsum operator node. https://onnx.ai/onnx/operators/onnx__Einsum.html#einsum-12
- Parameters:
input_nodes β List of input nodes for the Einsum operation.
equation β Einsum expression string.
- Returns:
Onnx NodeProto instance containing the Einsum operation.
- make_erf_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX Erf operator node. https://onnx.ai/onnx/operators/onnx__Erf.html#erf-13
- Parameters:
input_node β Input node to the Erf operator node.
- Returns:
Onnx NodeProto instance containing the Erf operation.
- make_flatten_node(input_node: OnnxNode, axis: int = 1) OnnxNodeο
Create an ONNX Flatten operator node. https://onnx.ai/onnx/operators/onnx__Flatten.html#flatten-13
- Parameters:
input_node β Input node to the Flatten operator node.
axis β Integer specifying the axis from which to flatten the input tensor. All dimensions up to (but not including) this axis are preserved, and all following dimensions are flattened into one. Default is 1.
- Returns:
Onnx NodeProto instance containing the Flatten operation.
- make_gemm_node(input_a: OnnxNode, input_b: OnnxNode, input_c: OnnxNode | None = None, alpha: float = 1.0, beta: float = 1.0, transA: int = 0, transB: int = 0) OnnxNodeο
Create an ONNX Gemm (General Matrix Multiplication) operator node. https://onnx.ai/onnx/operators/onnx__Gemm.html#gemm-13
- Parameters:
input_a β First input matrix (A).
input_b β Second input matrix (B).
input_c β Optional bias matrix (C). If None, no bias is added.
alpha β Scalar multiplier for A * B. Default is 1.0.
beta β Scalar multiplier for C. Default is 1.0.
transA β Whether A should be transposed.
transB β Whether B should be transposed.
- Returns:
Onnx NodeProto instance containing the Gemm operation.
- make_reduce_mean_node(input_node: OnnxNode, axes: collections.abc.Sequence[int] | None = None, keepdims: int = 1) OnnxNodeο
Create an ONNX ReduceMean operator node. https://onnx.ai/onnx/operators/onnx__ReduceMean.html#reducemean-13
- Parameters:
input_node β Input node to the ReduceMean operator node.
axes β A list of integers, along which to reduce. If None, reduction is performed over all dimensions.
keepdims β Keep the reduced dimension or not, default 1 means keep reduced dimension.
- Returns:
Onnx NodeProto instance containing the ReduceMean operation.
- make_reduce_sum_node(input_node: OnnxNode, axes: numpy.ndarray | None = None, keepdims: int = 1, noop_with_empty_axes: int = 0) OnnxNodeο
Create an ONNX ReduceSum operator node. https://onnx.ai/onnx/operators/onnx__ReduceSum.html#reducesum-13
- Parameters:
input_node β Input node to the ReduceSum operator node.
axes β Optional numpy array specifying the axes along which to reduce. If None, reduction is performed over all dimensions.
keepdims β Keep the reduced dimension or not, default 1 means keep reduced dimension.
noop_with_empty_axes β Defines behavior when axes is not provided or is empty. Integer flag (0 or 1). If 1 and axes is empty, input is unchanged and reduce sum behaves like no-op. If 0, reduction happens over all dimensions.
- Returns:
Onnx NodeProto instance containing the ReduceSum operation.
- make_reshape_node(input_node: OnnxNode, shape: numpy.ndarray, allowzero: int = 0) OnnxNodeο
Create an ONNX Reshape operator node. https://onnx.ai/onnx/operators/onnx__Reshape.html#reshape-14
- Parameters:
input_node β Input node to the Reshape operator node.
shape β 1D numpy array specifying the new shape for the input tensor.
allowzero β By default, when any value in the βshapeβ input is equal to zero the corresponding dimension value is copied from the input tensor dynamically. allowzero=1 indicates that if any value in the βshapeβ input is set to zero, the zero value is honored, similar to NumPy.
- Returns:
Onnx NodeProto instance containing the Reshape operation.
- make_resize_node(input_node: OnnxNode, roi: numpy.ndarray | None = None, scales: numpy.ndarray | None = None, sizes: numpy.ndarray | None = None, coordinate_transformation_mode: str = 'half_pixel', cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, mode: str = 'nearest', nearest_mode: str = 'round_prefer_floor') OnnxNodeο
Create an ONNX Resize operator node. https://onnx.ai/onnx/operators/onnx__Resize.html#resize-13
- Parameters:
input_node β Input node to the Resize operator node.
roi β Optional numpy array specifying the region of interest for resizing.
scales β Optional numpy array specifying scale factors for each dimension.
sizes β Optional numpy array specifying the target size for each dimension.
coordinate_transformation_mode β Specifies how to transform coordinates. Common values: βhalf_pixelβ, βalign_cornersβ, βasymmetricβ. Default is βhalf_pixelβ.
cubic_coeff_a β Coefficient for cubic interpolation. Default is -0.75.
exclude_outside β Integer flag (0 or 1). If 1, exclude values outside the input boundaries. Default is 0.
extrapolation_value β Value used for extrapolation when sampling outside input boundaries. Default is 0.0.
mode β Interpolation mode. Valid values: βnearestβ, βlinearβ, βcubicβ. Default is βnearestβ.
nearest_mode β Specifies rounding mode for nearest interpolation. Default is βround_prefer_floorβ.
- Returns:
Onnx NodeProto instance containing the Resize operation.
- make_matmul_node(lhs: OnnxNode | numpy.ndarray, rhs: OnnxNode | numpy.ndarray) OnnxNodeο
Create an ONNX MatMul operator node. https://onnx.ai/onnx/operators/onnx__MatMul.html#matmul-13
At least one of the inputs (lhs, rhs) must be a variable (onnx.NodeProto object).
- Parameters:
lhs β Input lhs node or numpy array to MatMul operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
rhs β Input rhs node or numpy array to MatMul operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
- Returns:
Onnx NodeProto instance containing the MatMul operation.
- make_pad_node(input_node: OnnxNode, pads: numpy.ndarray, constant_value: int | str | bool = 0, mode: str = 'constant') OnnxNodeο
Create an ONNX Pad operator node. https://onnx.ai/onnx/operators/onnx__Pad.html#pad-13
- Parameters:
input_node β The input tensor node to pad.
pads β Tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis.
constant_value β A scalar value to be used if the mode chosen is constant (by default it is 0, empty string or False).
mode β Padding mode. Can be βconstantβ (default), βreflectβ, or βedgeβ.
- Returns:
Onnx NodeProto instance containing the Pad operation.
- make_slice_node(data_node: OnnxNode, starts: numpy.ndarray, ends: numpy.ndarray, axes: numpy.ndarray | None = None, steps: numpy.ndarray | None = None) OnnxNodeο
Create an ONNX Slice operator node. https://onnx.ai/onnx/operators/onnx__Slice.html#slice-13
- Parameters:
data_node β The input tensor node to slice.
starts β 1D numpy array of int64 specifying start indices.
ends β 1D numpy array of int64 specifying end indices.
axes β (Optional) 1D numpy array of int64 specifying axes.
steps β (Optional) 1D numpy array of int64 specifying steps.
- Returns:
Onnx NodeProto instance containing the Slice operation.
- make_split_node(input_node: OnnxNode, output_names: list[str], axis: int = 0, split: numpy.ndarray | None = None) OnnxNodeο
Create an ONNX Split operator node. https://onnx.ai/onnx/operators/onnx__Split.html#split-13
- Parameters:
input_node β The input tensor node to split.
output_names β List of output names.
axis β Axis along which to split. Default is 0.
split β (Optional) 1D numpy array of int64 specifying sizes for each output. Values should be >= 0. Sum of the values must be equal to the dim value at βaxisβ specified.
- Returns:
Onnx NodeProto instance containing the Split operation.
- make_sqrt_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX Sqrt operator node. https://onnx.ai/onnx/operators/onnx__Sqrt.html#sqrt-13
- Parameters:
input_node β The input tensor node.
- Returns:
Onnx NodeProto instance containing the Sqrt operation.
- make_tanh_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX Tanh operator node. https://onnx.ai/onnx/operators/onnx__Tanh.html#tanh-13
- Parameters:
input_node β The input tensor node.
- Returns:
Onnx NodeProto instance containing the Sqrt operation.
- make_add_node(lhs: OnnxNode | numpy.ndarray, rhs: OnnxNode | numpy.ndarray) OnnxNodeο
Create an ONNX Add operator node. https://onnx.ai/onnx/operators/onnx__Add.html#add-14
At least one of the inputs (lhs, rhs) must be a variable (onnx.NodeProto object).
- Parameters:
lhs β Input lhs node or numpy array to Add operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
rhs β Input rhs node or numpy array to Add operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
- Returns:
Onnx NodeProto instance containing the Add operation.
- make_sub_node(lhs: OnnxNode | numpy.ndarray, rhs: OnnxNode | numpy.ndarray) OnnxNodeο
Create an ONNX Sub operator node. https://onnx.ai/onnx/operators/onnx__Sub.html#sub-14
At least one of the inputs (lhs, rhs) must be a variable (onnx.NodeProto object).
- Parameters:
lhs β Input lhs node or numpy array to Sub operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
rhs β Input rhs node or numpy array to Sub operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
- Returns:
Onnx NodeProto instance containing the Sub operation.
- make_mul_node(lhs: OnnxNode | numpy.ndarray, rhs: OnnxNode | numpy.ndarray) OnnxNodeο
Create an ONNX Mul operator node. https://onnx.ai/onnx/operators/onnx__Mul.html#mul-14
At least one of the inputs (lhs, rhs) must be a variable (onnx.NodeProto object).
- Parameters:
lhs β Input lhs node or numpy array to Mul operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
rhs β Input rhs node or numpy array to Mul operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
- Returns:
Onnx NodeProto instance containing the Mul operation.
- make_div_node(lhs: OnnxNode | numpy.ndarray, rhs: OnnxNode | numpy.ndarray) OnnxNodeο
Create an ONNX Div operator node. https://onnx.ai/onnx/operators/onnx__Div.html#div-14
At least one of the inputs (lhs, rhs) must be a variable (onnx.NodeProto object).
- Parameters:
lhs β Input lhs node or numpy array to Div operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
rhs β Input rhs node or numpy array to Div operator node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
- Returns:
Onnx NodeProto instance containing the Div operation.
- make_elu_node(input_node: OnnxNode, alpha: float = 1.0) OnnxNodeο
Create an ONNX Elu operator node. https://onnx.ai/onnx/operators/onnx__Elu.html
- Parameters:
input_node β Input node of Elu operator.
alpha β Coefficient of ELU.
- Returns:
Onnx NodeProto instance containing the Elu operation.
- make_hardsigmoid_node(input_node: OnnxNode, alpha: float = 0.2, beta: float = 0.5) OnnxNodeο
Create an ONNX HardSigmoid operator node. https://onnx.ai/onnx/operators/onnx__HardSigmoid.html
- Parameters:
input_node β Input node of HardSigmoid operator.
alpha β Value of alpha inside hardsigmoid equation.
beta β Value of beta inside hardsigmoid equation.
- Returns:
Onnx NodeProto instance containing the HardSigmoid operation.
- make_hardswish_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX HardSwish operator node. https://onnx.ai/onnx/operators/onnx__HardSwish.html
- Parameters:
input_node β Input node of hardswish operator.
- Returns:
Onnx NodeProto instance containing the HardSwish operation.
- make_leakyrelu_node(input_node: OnnxNode, alpha: float = 0.01) OnnxNodeο
Create an ONNX LeakyRelu operator node. https://onnx.ai/onnx/operators/onnx__LeakyRelu.html
- Parameters:
input_node β Input node of leakyrelu operator.
alpha β Defines the coefficient of leakage.
- Returns:
Onnx NodeProto instance containing the LeakyRelu operation.
- make_relu_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX Relu operator node. https://onnx.ai/onnx/operators/onnx__Relu.html
- Parameters:
input_node β Input node of relu operator.
- Returns:
Onnx NodeProto instance containing the Relu operation.
- make_prelu_node(input_node: OnnxNode, slope: OnnxNode | numpy.ndarray) OnnxNodeο
Create an ONNX PRelu operator node. https://onnx.ai/onnx/operators/onnx__PRelu.html
Slope parameter must be unidirectionally broadcastable to input_node.
- Parameters:
input_node β Input node of prelu operator.
slope β Input slope node or numpy array to PRelu operator node. In the case of a numpy
array
list. (the onnx.TensorProto object would be created and added to initializer)
- Returns:
Onnx NodeProto instance containing the PRelu operation.
- make_sigmoid_node(input_node: OnnxNode) OnnxNodeο
Create an ONNX Sigmoid operator node. https://onnx.ai/onnx/operators/onnx__Sigmoid.html
- Parameters:
input_node β Input node of sigmoid operator.
- Returns:
Onnx NodeProto instance containing the Sigmoid operation.
- make_softmax_node(input_node: OnnxNode, axis: int = -1) OnnxNodeο
Create an ONNX Softmax operator node. https://onnx.ai/onnx/operators/onnx__Softmax.html
- Parameters:
input_node β Input node of softmax operator.
axis β Defines the dimension operator will be applied on.
- Returns:
Onnx NodeProto instance containing the Softmax operation.
- make_instance_normalization_node(input_node: OnnxNode, scale: OnnxNode | numpy.ndarray, bias: OnnxNode | numpy.ndarray, epsilon: float = 1e-05) OnnxNodeο
Create an ONNX InstanceNormalization operator node. https://onnx.ai/onnx/operators/onnx__InstanceNormalization.html
- Parameters:
input_node β Input node of InstanceNormalization operator.
scale β The 1D input scale tensor of the same size as the channel dim of the input_node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
bias β The 1D input bias tensor of the same size as the channel dim of the input_node. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
epsilon β The epsilon value to use to avoid division by zero.
- Returns:
Onnx NodeProto instance containing the InstanceNormalization operation.
- make_layer_normalization_node(input_node: OnnxNode, scale: OnnxNode | numpy.ndarray, bias: OnnxNode | numpy.ndarray | None = None, axis: int = -1, epsilon: float = 1e-05, stash_type: int = 1) OnnxNodeο
Create an ONNX LayerNormalization operator node. https://onnx.ai/onnx/operators/onnx__LayerNormalization.html
Scale and bias (if present) parameters must be unidirectionally broadcastable to input_node.
- Parameters:
input_node β Input node of LayerNormalization operator.
scale β Input scale tensor. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list.
bias β Optional input bias tensor. In the case of a numpy array, the onnx.TensorProto object would be created and added to initializer list. If None, bias would not be used in the layer_norm equation.
axis β The first normalization dimension. If rank(input_node) is r, axisβ allowed range is [-r, r). Negative value means counting dimensions from the back.
epsilon β The epsilon value to use to avoid division by zero.
stash_type β Type of Mean and InvStdDev. This also specifies stage oneβs computation precision.
- Returns:
Onnx NodeProto instance containing the LayerNormalization operation.
- make_squeeze_node(input_node: OnnxNode, axes: collections.abc.Sequence[int] | None = None) OnnxNodeο
Create an ONNX Squeeze operator node. https://onnx.ai/onnx/operators/onnx__Squeeze.html
- Parameters:
input_node β Input node of Squeeze operator.
axes β List of integers indicating the dimensions to squeeze. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input_node).
- Returns:
Onnx NodeProto instance containing the Squeeze operation.
- make_transpose_node(input_node: OnnxNode, perm: collections.abc.Sequence[int] | None = None) OnnxNodeο
Create an ONNX Transpose operator node. https://onnx.ai/onnx/operators/onnx__Transpose.html
- Parameters:
input_node β Input node of Transpose operator.
perm β A list of integers. By default, reverse the dimensions, otherwise permute the axes
given. (according to the values)
- Returns:
Onnx NodeProto instance containing the Transpose operation.
- make_unsqueeze_node(input_node: OnnxNode, axes: collections.abc.Sequence[int]) OnnxNodeο
Create an ONNX Unsqueeze operator node. https://onnx.ai/onnx/operators/onnx__Unsqueeze.html
- Parameters:
input_node β Input node of Unsqueeze operator.
axes β List of integers indicating the dimensions to be inserted. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(expanded_node).
- Returns:
Onnx NodeProto instance containing the Unsqueeze operation.