More operators for onnx reference implementation
Project description
onnx-extended extends the list of supported operators in onnx reference implementation, or implements faster versions in C++. Documentation onnx-extended. Source are available on github/onnx-extended.
import numpy as np
from onnx import TensorProto
from onnx.helper import (
make_graph,
make_model,
make_node,
make_opsetid,
make_tensor_value_info,
)
from onnx.reference import ReferenceEvaluator
from onnxruntime import InferenceSession
from onnx_extended.ext_test_case import measure_time
from onnx_extended.reference import CReferenceEvaluator
X = make_tensor_value_info("X", TensorProto.FLOAT, [None, None, None, None])
Y = make_tensor_value_info("Y", TensorProto.FLOAT, [None, None, None, None])
B = make_tensor_value_info("B", TensorProto.FLOAT, [None, None, None, None])
W = make_tensor_value_info("W", TensorProto.FLOAT, [None, None, None, None])
node = make_node(
"Conv",
["X", "W", "B"],
["Y"],
pads=[1, 1, 1, 1],
dilations=[1, 1],
strides=[2, 2],
)
graph = make_graph([node], "g", [X, W, B], [Y])
onnx_model = make_model(graph, opset_imports=[make_opsetid("", 16)])
sH, sW = 64, 64
X = np.arange(sW * sH).reshape((1, 1, sH, sW)).astype(np.float32)
W = np.ones((1, 1, 3, 3), dtype=np.float32)
B = np.array([[[[0]]]], dtype=np.float32)
sess1 = ReferenceEvaluator(onnx_model)
sess2 = CReferenceEvaluator(onnx_model) # 100 times faster
expected = sess1.run(None, {"X": X, "W": W, "B": B})[0]
got = sess2.run(None, {"X": X, "W": W, "B": B})[0]
diff = np.abs(expected - got).max()
print(f"difference: {diff}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
onnx-extended-0.1.0.tar.gz
(23.7 kB
view details)
Built Distribution
File details
Details for the file onnx-extended-0.1.0.tar.gz
.
File metadata
- Download URL: onnx-extended-0.1.0.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7332dcaeb097a4788ba73377f6969eb27963e1ca855a63e60f22b34181ba3a8a |
|
MD5 | 38b4ecd494585b71d7430b6856b7d458 |
|
BLAKE2b-256 | 3c1cc4ca2c44ea41beaa864f54aa5fb234714c084ef2175d97e68844b96d0b7b |
File details
Details for the file onnx_extended-0.1.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: onnx_extended-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 166.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c9f379b20fe1fd30d052028419a446f703a1ed2b96994f8a526a50858fb3d5d |
|
MD5 | 470004f4247cdd67ef07aebc77c3d505 |
|
BLAKE2b-256 | e16b0f6ea981e0243dc4f1f1f014f7163fe352cdcada1c589f5c9d8a59977337 |