This tool provides a way to convert ONNX models to Chainer models.
The Python packages can be install via pip3 install chainer onnx numpy
.
pip3 install -e .
python3 -c "import onnx2chainer"
python3 setup.py test
import onnx
import onnx2chainer
model_onnx = onnx.load("path/to/onnx/model")
model_chainer = onnx2chainer.onnxToChainer(model_onnx)
x = a_xp_array
y = model_chainer(x)
See onnx2chainer_test.py
for more details.
The test script onnx2chainer_test.py
- downloads ONNX models as well as test datasets from The ONNX Model Zoo (might be O(GiB)),
- generate a Chainer model from each of them, and
- verify the generated models by comparing output of the models and grand-truth outputs, as follows.
Testing bvlc_alexnet.tar.gz with test_data_set_0: |y_chainer - y_true| / |y_true| = 5.27e-07
Testing bvlc_reference_caffenet.tar.gz with test_data_set_0: |y_chainer - y_true| / |y_true| = 5.24e-08
Testing bvlc_googlenet.tar.gz with test_data_set_0: |y_chainer - y_true| / |y_true| = 9.00e-07
Testing resnet50.tar.gz with test_data_set_0: |y_chainer - y_true| / |y_true| = 3.70e-08
Testing mnist.tar.gz with test_data_set_0: |y_chainer - y_true| / |y_true| = 5.78e-04
Testing vgg19.tar.gz with test_data_set_0: |y_chainer - y_true| / |y_true| = 9.68e-07
Note that the error of MNIST is relatively larger than others because the model does not have softmax.