module onnxrt.onnx2py_helper
¶
Short summary¶
module mlprodict.onnxrt.onnx2py_helper
Functions which converts ONNX object into readable python objects.
Functions¶
function |
truncated documentation |
---|---|
Single function to create an array. |
|
Single function to create an sparse array (coo_matrix). |
|
Converts a type into a readable string. |
|
Converts a protobuf object into something readable. The current implementation relies on json. That’s not … |
|
Retrieves an array from bytes then protobuf. |
|
Guesses the ONNX dtype given a numpy dtype. |
|
Returns the maximum of an array. Deals with text as well. |
|
Returns the minimum of an array. Deals with text as well. |
|
Converts an array into protobuf and then into bytes. |
Documentation¶
Functions which converts ONNX object into readable python objects.
-
mlprodict.onnxrt.onnx2py_helper.
_elem_type_as_str
(elem_type)¶
-
mlprodict.onnxrt.onnx2py_helper.
_numpy_array
(data, dtype=None, copy=True)¶ Single function to create an array.
- Parameters
data – data
dtype – dtype
copy – copy
- Returns
numpy array
-
mlprodict.onnxrt.onnx2py_helper.
_sparse_array
(shape, data, indices, dtype=None, copy=True)¶ Single function to create an sparse array (coo_matrix).
- Parameters
shape – shape
data – data
indices – indices
dtype – dtype
copy – copy
- Returns
-
mlprodict.onnxrt.onnx2py_helper.
_to_array
(var)¶
-
mlprodict.onnxrt.onnx2py_helper.
_type_to_string
(dtype)¶ Converts a type into a readable string.
-
mlprodict.onnxrt.onnx2py_helper.
_var_as_dict
(var)¶ Converts a protobuf object into something readable. The current implementation relies on json. That’s not the most efficient way.
-
mlprodict.onnxrt.onnx2py_helper.
from_bytes
(b)¶ Retrieves an array from bytes then protobuf.
- Parameters
b – bytes
- Returns
array
Converts bytes into an array (serialization)
Useful to deserialize.
<<<
import numpy from mlprodict.onnxrt.onnx2py_helper import to_bytes, from_bytes data = numpy.array([[0, 1], [2, 3], [4, 5]], dtype=numpy.float32) pb = to_bytes(data) data2 = from_bytes(pb) print(data2)
>>>
[[0. 1.] [2. 3.] [4. 5.]]
-
mlprodict.onnxrt.onnx2py_helper.
guess_proto_dtype
(dtype)¶ Guesses the ONNX dtype given a numpy dtype.
- Parameters
dtype – numpy dtype
- Returns
proto type
-
mlprodict.onnxrt.onnx2py_helper.
numpy_max
(x)¶ Returns the maximum of an array. Deals with text as well.
-
mlprodict.onnxrt.onnx2py_helper.
numpy_min
(x)¶ Returns the minimum of an array. Deals with text as well.
-
mlprodict.onnxrt.onnx2py_helper.
to_bytes
(val)¶ Converts an array into protobuf and then into bytes.
- Parameters
val – array
- Returns
bytes
Converts an array into bytes (serialization)
Useful to serialize.
<<<
import numpy from mlprodict.onnxrt.onnx2py_helper import to_bytes data = numpy.array([[0, 1], [2, 3], [4, 5]], dtype=numpy.float32) pb = to_bytes(data) print(len(pb), data.size * data.itemsize, pb[:10])
>>>
32 24 b'\x08\x03\x08\x02\x10\x01J\x18\x00\x00'