This is an add-on package for ONNX support by Chainer.
- Python 3.5.5, 3.6.7
- ONNX 1.4.0, 1.4.1
- opset version 7, 8, 9
- Chainer stable, preview
- ONNX-Runtime 0.3.0
(You can still specify all opset versions <= 9, but please noted that opset versions <= 6 are not tested)
pip install onnx-chainer
$ pip install onnx-chainer[test-cpu]
Or, on GPU environment
$ pip install cupy # or cupy-cudaXX is useful
$ pip install onnx-chainer[test-gpu]
$ CHAINER_TEST_GPU_LIMIT=0 pytest
Or, on GPU environment
$ pytest
First, install ChainerCV to get the pre-trained models.
import numpy as np
import chainer
import chainercv.links as C
import onnx_chainer
model = C.VGG16(pretrained_model='imagenet')
# Pseudo input
x = np.zeros((1, 3, 224, 224), dtype=np.float32)
onnx_chainer.export(model, x, filename='vgg16.onnx')
Currently 76 Chainer Functions are supported to export in ONNX format.
- ClippedReLU
- ELU
- HardSigmoid
- LeakyReLU
- LogSoftmax
- PReLUFunction
- ReLU
- Sigmoid
- Softmax
- Softplus
- Tanh
- Cast
- Concat
- Copy
- Depth2Space
- Dstack
- ExpandDims
- GetItem
- Hstack
- Pad 12
- Repeat
- Reshape
- ResizeImages
- Separate
- Space2Depth
- SplitAxis
- Squeeze
- Stack
- Swapaxes
- Tile
- Transpose
- Vstack
- Where
- Convolution2DFunction
- ConvolutionND
- Deconvolution2DFunction
- DeconvolutionND
- EmbedIDFunction 3
- LinearFunction
- SoftmaxCrossEntropy
- Absolute
- Add
- AddConstant
- BroadcastTo
- Clip
- Div
- Exp
- Identity
- LinearInterpolate
- LogSumExp
- MatMul
- Max
- Maximum
- Mean
- Min
- Minimum
- Mul
- MulConstant
- Neg
- PowVarConst
- Prod
- Sqrt
- Square
- Sub
- Sum
- Dropout 4
- BatchNormalization
- FixedBatchNormalization
- LocalResponseNormalization
- NormalizeL2
- AveragePooling2D
- AveragePoolingND
- MaxPooling2D
- MaxPoolingND
- ROIPooling2D
- Unpooling2D
Any contribution to ONNX-Chainer is welcome!
- Python codes follow Chainer Coding Guidelines
1: mode should be either 'constant', 'reflect', or 'edge'
2: ONNX doesn't support multiple constant values for Pad operation
3: Current ONNX doesn't support ignore_label for EmbedID
4: In test mode, all dropout layers aren't included in the exported file