yolo模型转换:pytorch -> onnx -> caffe
第一步:pytorch转onnx(pytorch版,yolov3-9.0开始提供脚本export.py)
(1)设置onnx算子版本(按需)
修改代码:
torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'],为:
torch.onnx.export(model, img, f, verbose=True, opset_version=9, input_names=['images'], do_constant_folding=True,
(2)导出onnx
python3 ./models/export.py --weights ./weights/yolov3.pt
(3)onnx模型简化,项目地址: https://github.com/daquexian/onnx-simplifier,否则下一步报错TypeError: ONNX node of type Shape is not supported.
pip install onnx-simplifierpython3 -m onnxsim ./weights/yolov3.onnx ./weights/yolov3-si.onnx
第二步:onnx转caffe
git clone https://github.com/xxradon/ONNXToCaffe.gitcd ONNXToCaffepython3 convertCaffe.py ./model/yolov3-si.onnx ./model/yolov3-si.prototxt ./model/yolov3-si.caffemodel
报错一:
Traceback (most recent call last):File "convertCaffe.py", line 122, in <module>convertToCaffe(graph, opset_version, prototxt_path, caffemodel_path)File "convertCaffe.py", line 67, in convertToCaffelayer = converter_fn(node,graph,err)File "/home/ubuntu/ONNXToCaffe-master/onnx2caffe/_operators.py", line 257, in _convert_Reshapereturn err.unsupported_op_configuration(node, "Reshape dimention number shall be 2 or 4")File "/home/ubuntu/ONNXToCaffe-master/onnx2caffe/_error_utils.py", line 44, in unsupported_op_configurationraise TypeError(
TypeError: Error while converting op of type: Reshape. Error message: Reshape dimention number shall be 2 or 4
修改_operators.py(yolo的数据shape是5维数组)
vim ./onnx2caffe/_operators.py修改代码:
elif len(shape) == 4:为
elif len(shape) == 4 or len(shape) == 5:
报错二:AttributeError: permute_param 或者 AttributeError: Upsample_param
Traceback (most recent call last):File "convertCaffe.py", line 122, in <module>convertToCaffe(graph, opset_version, prototxt_path, caffemodel_path)File "convertCaffe.py", line 79, in convertToCaffelayers[id] = layer._to_proto()File "/home/ubuntu/ONNXToCaffe-master/MyCaffe.py", line 100, in _to_protoassign_proto(layer, k, v)File "/home/ubuntu/ONNXToCaffe-master/MyCaffe.py", line 29, in assign_protois_repeated_field = hasattr(getattr(proto, name), 'extend')
AttributeError: permute_param
添加Upsample层、permute层,重新编译caffe,项目地址 :https://github.com/jnulzl/caffe_plus
git clone https://github.com/jnulzl/caffe_plus.gitcp caffe_plus/include/caffe/layers/upsample_layer.hpp caffe/include/caffe/layers/
cp caffe_plus/src/caffe/layers/upsample_layer.cpp caffe/src/caffe/layers/
cp caffe_plus/src/caffe/layers/upsample_layer.cu caffe/src/caffe/layers/
cp caffe_plus/include/caffe/layers/permute_layer.hpp caffe/include/caffe/layers/
cp caffe_plus/src/caffe/layers/permute_layer.cpp caffe/src/caffe/layers/
cp caffe_plus/src/caffe/layers/permute_layer.cu caffe/src/caffe/layers/# 修改caffe.proto文件vim caffe/src/caffe/proto/caffe.proto在optional WindowDataParameter window_data_param = 129;(约第423行)后增加代码:optional PermuteParameter permute_param = 150;
optional UpsampleParameter upsample_param = 151;在末尾增加代码:
message PermuteParameter {// The new orders of the axes of data. Notice it should be with// in the same range as the input data, and it starts from 0.// Do not provide repeated order.repeated uint32 order = 1;
}message UpsampleParameter { optional int32 height = 1 [default = 32];optional int32 width = 2 [default = 32];optional int32 height_scale = 3 [default = 2];optional int32 width_scale = 4 [default = 2];enum UpsampleOp {NEAREST = 0;BILINEAR = 1;}optional UpsampleOp mode = 5 [default = BILINEAR];
}# 重新编译cd caffe
make all -j8
make pycaffe -j8
相关文章:一文带你熟悉Pytorch->Caffe->om模型转换流程 ,海思开发:yolo v5s :pytorch->onnx->caffe->nnie
相关项目:https://github.com/Wulingtian/yolov5_onnx2caffe
yolo模型转换:pytorch -> onnx -> caffe相关推荐
- darknet cpp weights模型转换成ONNX模型
整理不易,如果觉得有用,记得点赞收藏和分享哦 1. 下载转换需要的代码文件 在下面地址下载代码文件 https://gitee.com/liangjiaxi2019/pytorch-YOLOv4 2. ...
- pytorch模型(.pt)转onnx模型(.onnx)的方法详解(1)
1. pytorch模型转换到onnx模型 2.运行onnx模型 3.比对onnx模型和pytorch模型的输出结果 我这里重点是第一点和第二点,第三部分 比较容易 首先你要安装 依赖库:onnx ...
- 轻松入门模型转换和可视化
点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 本文给大家介绍一个模型转换格式ONNX和可视化工具Netron.ONNX是微软设计的一种多平台的通用文 ...
- 模型转换、压缩、加速工具
20210618 sky_hole: 回成都工作了吗?wang shi yang: 嗯 我现在已经在成都上班了sky_hole: 不用付费,我之前发你的视频你好好看看就可以入门了sky_hole: 成 ...
- 模型转换、模型压缩、模型加速工具汇总
点击上方"计算机视觉工坊",选择"星标" 干货第一时间送达 编辑丨机器学习AI算法工程 一.场景需求解读 在现实场景中,我们经常会遇到这样一个问题,即某篇论 ...
- 将训练好的pytorch模型的pth文件转换成onnx模型(亲测成功)
将训练好的pytorch模型的pth文件转换成onnx模型(亲测成功) 模型转换 声明:本文原创,未经许可严禁转载,原文地址https://blog.csdn.net/hutao1030813002/ ...
- linux caffe生成的模型,深度学习之pytorch转caffe转ncnn模型转换(三)
搭建caffe平台: 先在Linux系统下搭建caffe环境,安装依赖包: sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy- ...
- 【地平线开发板 模型转换】将pytorch生成的onnx模型转换成.bin模型
文章目录 1 获取onnx模型 2 启动docker容器 3 onnx模型检查 3.1 为什么要检查? 3.2 如何操作 4 图像数据预处理 4.1 一些问题的思考 4.2 图片挑选与放置 4.2 使 ...
- pytorch模型转ONNX转TensorRT,模型转换和推理部署
一.pth模型转ONNX import os import sys import torch import numpy as npfrom feat.model import ResNet # 导入自 ...
最新文章
- https 证书验证等原理
- Python 多进程/Event 重复使用唤醒
- TF之LiR:基于tensorflow实现机器学习之线性回归算法
- Waymo 2020 | 2D/3D目标检测、跟踪和域自适应性冠军解决方案解析
- 性能测试工具系列(一):性能测试工具对比分析
- 新零售场景下的AIPL分析
- 互联网公司端午节礼盒歧视指南
- JSONObject以及json(转)
- Html5 学习系列(二)HTML5新增结构标签
- SCI英文论文写作- Latex 进阶
- 交换机(三层)接入层、汇聚层和核心层交换机的特点
- python 动画场景_clarisse电影级CG场景渲染中文教学
- KEIL设置程序起始地址无效解决方法,STM32 IAP程序起始地址
- 朱会灿:搜索引擎演变史 视频及PPT放出 - 讲堂活动 - 腾讯大讲堂
- Odoo产品分析 (三) -- 人力资源板块(1) -- 员工目录(1)
- 台式安装nas系统_从0开始使用“矿渣”低成本打造家庭NAS,黑群晖系统安装(中)...
- Vxworks7运行在树莓派 3B/3B+
- 只会 Python 不行,不会 Python 万万不行
- 电脑好用的ftp软件,推荐10款电脑好用的ftp软件
- 微型计算机2018年7月pdf,《微型计算机》2012年7月下 高清电子版 PDF格式
热门文章
- Unreal4 入门
- Windows系统的正版与盗版
- mvcnn代码详解_使用colab运行tensorflow版本的faster-rcnn
- 微信群聊图灵机器人 复制直接用
- c语言c4700错误,C编译错误,运行错误以及常见问题。
- 独立站运营 | FaceBook营销神器——聊天机器人ManyChat
- 用c语言switch写运费的,超级新手,用switch写了个计算器程序,求指导
- ode45matlab例子,ode45(ode45用法举例)
- 运用遗传算法求解函数极值(fortran)
- 感知机(Perceptron)