Skip to main content

Convert a Chainer model into ONNX

Project description

ONNX-Chainer

PyPI GitHub license Build Status codecov

This is an add-on package for ONNX support by Chainer.

Tested environment

  • 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)

Installation

On Ubuntu 14.04/16.04

pip install onnx-chainer

Run Test

1. Install test modules

$ pip install onnx-chainer[test-cpu]

Or, on GPU environment

$ pip install cupy  # or cupy-cudaXX is useful
$ pip install onnx-chainer[test-gpu]

2. Run tests

$ CHAINER_TEST_GPU_LIMIT=0 pytest

Or, on GPU environment

$ pytest

Quick Start

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')

Supported Functions

Currently 75 Chainer Functions are supported to export in ONNX format.

Activation

  • ClippedReLU
  • ELU
  • HardSigmoid
  • LeakyReLU
  • LogSoftmax
  • PReLUFunction
  • ReLU
  • Sigmoid
  • Softmax
  • Softplus
  • Tanh

Array

  • Cast
  • Concat
  • Copy
  • Depth2Space
  • Dstack
  • ExpandDims
  • GetItem
  • Hstack
  • Pad 12
  • Repeat
  • Reshape
  • ResizeImages
  • Space2Depth
  • SplitAxis
  • Squeeze
  • Stack
  • Swapaxes
  • Tile
  • Transpose
  • Vstack
  • Where

Connection

  • Convolution2DFunction
  • ConvolutionND
  • Deconvolution2DFunction
  • DeconvolutionND
  • EmbedIDFunction 3
  • LinearFunction

Loss

  • SoftmaxCrossEntropy

Math

  • 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

Noise

  • Dropout 4

Normalization

  • BatchNormalization
  • FixedBatchNormalization
  • LocalResponseNormalization
  • NormalizeL2

Pooling

  • AveragePooling2D
  • AveragePoolingND
  • MaxPooling2D
  • MaxPoolingND
  • ROIPooling2D
  • Unpooling2D

Contribution

Any contribution to ONNX-Chainer is welcome!


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

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-chainer-1.4.1.tar.gz (24.5 kB view details)

Uploaded Source

File details

Details for the file onnx-chainer-1.4.1.tar.gz.

File metadata

  • Download URL: onnx-chainer-1.4.1.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for onnx-chainer-1.4.1.tar.gz
Algorithm Hash digest
SHA256 8dff6aee68db4acd8af1153c11872d0ed42e59af1352f5c48f51b9d49e7e1b2f
MD5 cfd2a43a2bc9c489d333958444126adc
BLAKE2b-256 e0205077c57feab5166343eb01ab77fcf0bddfa42eb40b7262a0d84281e999f1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page