module onnxrt.onnx_micro_runtime#

Inheritance diagram of mlprodict.onnxrt.onnx_micro_runtime

Short summary#

module mlprodict.onnxrt.onnx_micro_runtime

Micro runtime for ONNX.

Classes#

class

truncated documentation

OnnxMicroRuntime

Implements a micro runtime for ONNX graphs. It does not implements all the operator types.

Properties#

property

truncated documentation

input_names

Returns input names.

output_names

Returns output names.

Methods#

method

truncated documentation

__init__

_op_abs

Runtime for operator Op.Abs.

_op_add

Runtime for operator Op.Add.

_op_concat

Runtime for operator Op.Concat.

_op_gather

Runtime for operator Op.Gather.

_op_gemm

Runtime for operator Op.Gemm.

_op_identity

Runtime for operator Op.Identity.

_op_matmul

Runtime for operator Op.MatMul.

_op_max

Runtime for operator Op.Max.

_op_mul

Runtime for operator Op.Mul.

_op_reduceprod

Runtime for operator Op.ReduceProd.

_op_reducesum

Runtime for operator Op.ReduceSum.

_op_reshape

Runtime for operator Op.Reshape.

_op_shape

Runtime for operator Op.Shape.

_op_squeeze

Runtime for operator Op.Squeeze.

_op_transpose

Runtime for operator Op.Transpose.

_op_unsqueeze

Runtime for operator Op.Unsqueeze.

run

Computes the outputs of the graph.

Documentation#

Micro runtime for ONNX.

New in version 0.6.

source on GitHub

class mlprodict.onnxrt.onnx_micro_runtime.OnnxMicroRuntime(model_onnx)#

Bases: object

Implements a micro runtime for ONNX graphs. It does not implements all the operator types.

Parameters:

model_onnx – ONNX model

<<<

import pprint
import numpy
from mlprodict.onnxrt.onnx_micro_runtime import OnnxMicroRuntime
from mlprodict.npy.xop import loadop

OnnxAdd = loadop('Add')

dtype = numpy.float32
opset = 15
x = numpy.array([1, 2, 4, 5, 5, 4]).astype(
    numpy.float32).reshape((3, 2))
cop = OnnxAdd('X', numpy.array([1], dtype=dtype), op_version=opset)
cop4 = OnnxAdd(cop, numpy.array([2], dtype=dtype), op_version=opset,
               output_names=['Y'])
model_def = cop4.to_onnx({'X': x}, target_opset=opset)
rt = OnnxMicroRuntime(model_def)
out = rt.run({'X': x})
pprint.pprint(out)

>>>

    somewhere/workspace/mlprodict/mlprodict_UT_39_std/_doc/sphinxdoc/source/mlprodict/npy/xop_variable.py:64: DeprecationWarning: `mapping.NP_TYPE_TO_TENSOR_TYPE` is now deprecated and will be removed in the next release or so.To silence this warning, please use `helper.{self._future_function}` instead.
      return NP_TYPE_TO_TENSOR_TYPE[dtype]
    {'X': array([[1., 2.],
           [4., 5.],
           [5., 4.]], dtype=float32),
     'Y': array([[4., 5.],
           [7., 8.],
           [8., 7.]], dtype=float32),
     'init': array([1.], dtype=float32),
     'init_1': array([2.], dtype=float32),
     'out_add_0': array([[2., 3.],
           [5., 6.],
           [6., 5.]], dtype=float32)}

source on GitHub

__init__(model_onnx)#
_op_abs(x)#

Runtime for operator Op.Abs.

_op_add(x, y)#

Runtime for operator Op.Add.

_op_concat(*args, axis=None)#

Runtime for operator Op.Concat.

_op_gather(x, indices, axis=None)#

Runtime for operator Op.Gather.

_op_gemm(a, b, c=None, alpha=None, beta=None, transA=False, transB=False)#

Runtime for operator Op.Gemm.

_op_identity(x)#

Runtime for operator Op.Identity.

_op_matmul(x, y)#

Runtime for operator Op.MatMul.

_op_max(*inps)#

Runtime for operator Op.Max.

_op_mul(x, y)#

Runtime for operator Op.Mul.

_op_reduceprod(data, axes=None, keepdims=None)#

Runtime for operator Op.ReduceProd.

_op_reducesum(data, axes, keepdims=None, noop_with_empty_axes=None)#

Runtime for operator Op.ReduceSum.

_op_reshape(x, shape)#

Runtime for operator Op.Reshape.

_op_shape(x)#

Runtime for operator Op.Shape.

_op_squeeze(x, axes=None)#

Runtime for operator Op.Squeeze.

_op_transpose(x, perm=None)#

Runtime for operator Op.Transpose.

_op_unsqueeze(x, axes=None)#

Runtime for operator Op.Unsqueeze.

property input_names#

Returns input names.

property output_names#

Returns output names.

run(inputs)#

Computes the outputs of the graph.

Parameters:

inputs – dictionary

Returns:

all intermediates results and output as a dictionary

source on GitHub