Skip to content

pytorch -> onnx -> caffe, pytorch to caffe, or other deep learning framework to onnx and onnx to caffe.

Notifications You must be signed in to change notification settings

xxradon/ONNXToCaffe

Repository files navigation

Code mainly come from https://github.com/MTlab/onnx2caffe https://github.com/seanxcwang/onnx2caffe and https://github.com/205418367/onnx2caffe,thanks for their contribution.

onnx to Caffe

we can convert onnx operations to caffe layer which not only from https://github.com/BVLC/caffe but also from many other caffe modified branch like ssd-caffe,and only onnx opset_version=9 is supported.

  1. Convert pytorch to Caffe by ONNX

This tool converts pytorch model to Caffe model by ONNX
only use for inference

  1. Convert tensorflow to Caffe by ONNX

you can use this repo https://github.com/onnx/tensorflow-onnx.

  1. other deeplearning frame work to caffe bt ONNX

Dependencies

  • caffe (with python support)
  • pytorch (optional if you want to convert onnx)
  • onnx
  • onnxruntime

we recomand using protobuf 2.6.1 and install onnx from source

git clone --recursive https://github.com/onnx/onnx.git
cd onnx 
python setup.py install

or just using pip

pip install onnx

How to use

  1. To convert onnx model to caffe:
python convertCaffe.py ./model/MobileNetV2.onnx ./model/MobileNetV2.prototxt ./model/MobileNetV2.caffemodel

pytorch to onnx Tips

  1. you can refer model_generator folder to learn how to generate onnx from pytorch,or just learn from pytorch.org.
  2. in pytorch,speeding up model with fusing batch normalization and convolution,so before convert pytorch pth model to onnx fusing fusing batch normalization and convolution is a good choice.you may refer this https://learnml.today/speeding-up-model-with-fusing-batch-normalization-and-convolution-3.
  3. Sometimes you need to use onnx-simplifier to simplify onnx model and then run convertCaffe.py to convert it into caffe model.

Current support operation

  • Conv
  • Relu
  • LeakyRelu
  • PRelu
  • Transpose
  • ReduceMean
  • MatMul
  • BatchNormalization
  • Add
  • Mul
  • Add
  • Reshape
  • MaxPool
  • AveragePool
  • GlobalAveragePool
  • Dropout
  • Gemm (InnerProduct only)
  • Upsample (nearest and bilinear all supported)
  • Concat
  • ConvTranspose
  • Sigmoid
  • Flatten
  • Sqrt
  • Softmax
  • Unsqueeze
  • Slice

About

pytorch -> onnx -> caffe, pytorch to caffe, or other deep learning framework to onnx and onnx to caffe.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages