Convert ONNX model file to Caffe2 model file(pb)

这篇博客介绍了如何使用convert-onnx-to-caffe2命令将ONNX模型转换为Caffe2格式。ONNX模型的数据和结构都存储在一个文件中,而Caffe2则分为init_net.pb(参数)和predict_net.pb(网络结构)两个文件。通过提供的shell命令,可以方便地进行转换操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Convert ONNX model file to Caffe2 model file(pb)

onnx-caffe2 has bundled a shell command convert-onnx-to-caffe2 for converting ONNX model file to Caffe2 model file.

$ convert-onnx-to-caffe2 assets/squeezenet.onnx --output predict_net.pb --init-net-output init_net.pb
Note in ONNX model file, parameters and network structure are all stored in one model file, while in Caffe2, they are normally stored in separated init_net.pb (parameters) and predict_net.pb (network structure) files.

ref:

https://github.com/onnx/tutorials/blob/master/tutorials/OnnxCaffe2Import.ipynb

TensorFlow 保存模型为 PB 文件 & 加载PB文件代码

TensorFlow 保存模型为 PB 文件 & 加载PB文件代码

从Tensorflow模型文件中解析并显示网络结构图(pb模型篇)

https://www.jianshu.com/p/b547c163e202
https://github.com/huachao1001/CNNGraph

ubuntu@ubuntu:~$ mmconvert -sf caffe -iw model.caffemodel -in deploy.prototxt -df onnx -om output.onnx Traceback (most recent call last): File "/home/ubuntu/.local/bin/mmconvert", line 8, in <module> sys.exit(_main()) File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/_script/convert.py", line 102, in _main ret = convertToIR._convert(ir_args) File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/_script/convertToIR.py", line 15, in _convert from mmdnn.conversion.caffe.transformer import CaffeTransformer File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/caffe/transformer.py", line 4, in <module> from mmdnn.conversion.caffe.graph import GraphBuilder, NodeKind, LAYER_IN_TRAIN_PROTO File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/caffe/graph.py", line 9, in <module> from mmdnn.conversion.caffe.mapper import get_handler_name File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/caffe/mapper.py", line 6, in <module> from mmdnn.conversion.caffe.common_graph import Node File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/caffe/common_graph.py", line 9, in <module> from mmdnn.conversion.common.IR.graph_pb2 import GraphDef, NodeDef, TensorShape File "/home/ubuntu/.local/lib/python3.10/site-packages/mmdnn/conversion/common/IR/graph_pb2.py", line 32, in <module> _descriptor.EnumValueDescriptor( File "/home/ubuntu/.local/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 920, in __new__ _message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors cannot be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=p
最新发布
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值