Skip to main content

caffe-onnx

This tool converts caffe model convert to onnx model
only use for inference

中文文档请参阅 README_CN.md

Introduction

This is the second version of converting caffe model to onnx model. In this version, all the parameters will be transformed to tensor and tensor value info when reading .caffemodel file and each operator node is constructed directly into the type of NodeProto in onnx.

Dependencies

  • protobuf
  • onnx==1.4.0
$ pip install -r requirements.txt

( caffe environment is not required! )

How to Use

usage: convert2onnx.py [-h] [caffe_graph_path] [caffe_params_path] [onnx_name] [save_dir]

positional arguments:
  caffe_graph_path          caffe's prototxt file path
  caffe_params_path         caffe's caffemodel file path
  onnx_name                 onnx model name
  save_dir                  onnx model file saved path

Take ResNet-50 as an example, you can follow the instructions.

  1. Download resnet50 .caffemodel file from BaiduDisk and put resnet-50-model.caffemodel to ./caffemodel/resnet-50/
    Link:https://pan.baidu.com/s/10YB42muAd0vGiNTCetvLsA
    Code:7az4

  2. Convert resnet50 caffe model to onnx model

    $ python convert2onnx.py \
              caffemodel/resnet-50/resnet-50-model.prototxt \
              caffemodel/resnet-50/resnet-50-model.caffemodel \
              resnet50 onnxmodel
    
  3. Visualize onnx model by netron

    $ netron onnxmodel/resnet50.onnx --host 0.0.0.0 --port 8008
    
  4. Run test scripts

    $ python onnxmodel/test_resnet.py \
              --input_shape 224 224 \
              --img_path onnxmodel/airplane.jpg \
              --onnx_path onnxmodel/resnet50.onnx
    
    # you will get result 404 which is the class id of airplane in IMAGENET.
    
  5. If you have custom layers in caffe which makes your caffe.proto is different than the one in the origin caffe code. The things you should do before convertion is:

    • First of all, compile your proto file with protoc

      # for example
      $ protoc /your/path/to/caffe_ssd.proto --python_out ./proto
      
    • Then specify the caffe proto file by replacing the line from proto import caffe_upsample_pb2 as caffe_pb2 with your module.

Current Support Operator

BatchNorm
Convolution
Deconvolution
Concat
Dropout
InnerProduct(Reshape+Gemm)
LRN
Pooling
Unpooling
ReLU
Softmax
Eltwise
Upsample
Scale

Test Caffe Model

  • Resnet50
  • AlexNet
  • Agenet
  • Yolo V3
  • vgg16

Visualization

netron is recommended: https://github.com/lutzroeder/netron
netron Browser

Development Guide

See Develop Guide

Metadata

Release files for caffe-onnx 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caffe-onnx 0.1.2
File Size Uploaded Provenance Actions
caffe_onnx-0.1.2.tar.gz 57.3 kB Without provenance Details for caffe_onnx-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for caffe-onnx 0.1.2
File Interpreter ABI Platform Actions
caffe_onnx-0.1.2-py3-none-any.whl Python 3 none any Details for caffe_onnx-0.1.2-py3-none-any.whl

Total release size: 123.8 kB

Release files / caffe_onnx-0.1.2.tar.gz

Download URL caffe_onnx-0.1.2.tar.gz
Size 57.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aeb472711563efe51e76194efd10e27925743e264a48cbf4debb880f7e1f553a
BLAKE2b-256 checksum
How to use checksums
f0de1b389df56a9bad89d626ad529d03ab628b66e5ece2a80bc88544d478e7de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.2

Release files / caffe_onnx-0.1.2-py3-none-any.whl

Download URL caffe_onnx-0.1.2-py3-none-any.whl
Size 66.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09f1284ec13afe4d09a63d1c921980b3149786511fee3f9ea5a757ed09443469
BLAKE2b-256 checksum
How to use checksums
4042c4af2d1445bab6c3b60593dab615a26fdf03d3699dceb5f5595b3fc6b379
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.2

Security for caffe-onnx 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page