3个outPut层版本 yolov3 转换推理【pt模型转onnx转ncnn】
【摘要】
文章目录
基础准备detect.py 测试运行pt 模型导出为 onnxonnxsim 对 yolov3.onnx 进行 simplifier 处理得到 yolov3_sim.onnxyolov3...
文章目录
基础准备
所下载模型链接
# 激活一个 独立 yolo 环境
conda activate torchYolo
# 下载zip源码
unzip yolov3-9.5.0.zip
# 脚本下载模型,失败的话,手动copy即可,我这里 copy 到 weights/ 目录下了
./weights/download_weights.sh
detect.py 测试运行
python detect.py --source data/images --weights weights/yolov3.pt --conf 0.25
# 运行输出如下
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', nosave=False, project='runs/detect', save_conf=False, save_txt=False, source='data/images', update=False, view_img=False, weights=['weights/yolov3.pt'])
YOLOv3 🚀 2021-4-12 torch 1.9.0+cu102 CUDA:0 (Quadro RTX 5000, 16125.3125MB)
Fusing layers...
Model Summary: 261 layers, 61922845 parameters, 0 gradients, 156.3 GFLOPS
image 1/2 /home/moli/project/project21Next/modelTrans/ncnnLearn/yolov3-9.5.0/data/images/bus.jpg: 640x480 4 persons, 1 bus, Done. (0.013s)
image 2/2 /home/moli/project/project21Next/modelTrans/ncnnLearn/yolov3-9.5.0/data/images/zidane.jpg: 384x640 2 persons, 3 ties, Done. (0.011s)
Results saved to runs/detect/exp
Done. (0.099s)
pt 模型导出为 onnx
python models/export.py --weights ./weights/yolov3.pt --img 640 --batch 1
Namespace(batch_size=1, device='cpu', dynamic=False, grid=False, img_size=[640, 640], weights='./weights/yolov3.pt')
YOLOv3 🚀 2021-4-12 torch 1.9.0+cu102 CPU
Fusing layers...
Model Summary: 261 layers, 61922845 parameters, 0 gradients, 156.3 GFLOPS
Starting TorchScript export with torch 1.9.0+cu102...
TorchScript export success, saved as ./weights/yolov3.torchscript.pt
Starting ONNX export with onnx 1.10.1...
ONNX export success, saved as ./weights/yolov3.onnx
Starting CoreML export with coremltools 4.1...
...
onnxsim 对 yolov3.onnx 进行 simplifier 处理得到 yolov3_sim.onnx
cd weights/
python -m onnxsim yolov3.onnx yolov3_sim.onnx
# 运行输出如下
Simplifying...
Checking 0/3...
Checking 1/3...
Checking 2/3...
Ok!
yolov3_sim.onnx 转 ncnn
cd ncnn/build/tools/onnx
./onnx2ncnn yolov3_sim.onnx
# 不指定转换名字的话,默认运行得到 ncnn.bin 和 ncnn.param
对 ncnn.param 进行修正
对 ncnn.param 进行 ncnnoptimize 优化
cd ..
./ncnnoptimize onnx/ncnn.param onnx/ncnn.bin yolov3-opt.param yolov3-opt.bin 1
# 运行输出如下
fuse_convolution_activation Conv_0 LeakyRelu_1
fuse_convolution_activation Conv_2 LeakyRelu_3
fuse_convolution_activation Conv_4 LeakyRelu_5
fuse_convolution_activation Conv_6 LeakyRelu_7
fuse_convolution_activation Conv_9 LeakyRelu_10
fuse_convolution_activation Conv_11 LeakyRelu_12
fuse_convolution_activation Conv_13 LeakyRelu_14
fuse_convolution_activation Conv_16 LeakyRelu_17
fuse_convolution_activation Conv_18 LeakyRelu_19
fuse_convolution_activation Conv_21 LeakyRelu_22
fuse_convolution_activation Conv_23 LeakyRelu_24
fuse_convolution_activation Conv_25 LeakyRelu_26
fuse_convolution_activation Conv_28 LeakyRelu_29
fuse_convolution_activation Conv_30 LeakyRelu_31
fuse_convolution_activation Conv_33 LeakyRelu_34
fuse_convolution_activation Conv_35 LeakyRelu_36
fuse_convolution_activation Conv_38 LeakyRelu_39
fuse_convolution_activation Conv_40 LeakyRelu_41
fuse_convolution_activation Conv_43 LeakyRelu_44
fuse_convolution_activation Conv_45 LeakyRelu_46
fuse_convolution_activation Conv_48 LeakyRelu_49
fuse_convolution_activation Conv_50 LeakyRelu_51
fuse_convolution_activation Conv_53 LeakyRelu_54
fuse_convolution_activation Conv_55 LeakyRelu_56
fuse_convolution_activation Conv_58 LeakyRelu_59
fuse_convolution_activation Conv_60 LeakyRelu_61
fuse_convolution_activation Conv_63 LeakyRelu_64
fuse_convolution_activation Conv_65 LeakyRelu_66
fuse_convolution_activation Conv_67 LeakyRelu_68
fuse_convolution_activation Conv_70 LeakyRelu_71
fuse_convolution_activation Conv_72 LeakyRelu_73
fuse_convolution_activation Conv_75 LeakyRelu_76
fuse_convolution_activation Conv_77 LeakyRelu_78
fuse_convolution_activation Conv_80 LeakyRelu_81
fuse_convolution_activation Conv_82 LeakyRelu_83
fuse_convolution_activation Conv_85 LeakyRelu_86
fuse_convolution_activation Conv_87 LeakyRelu_88
fuse_convolution_activation Conv_90 LeakyRelu_91
fuse_convolution_activation Conv_92 LeakyRelu_93
fuse_convolution_activation Conv_95 LeakyRelu_96
fuse_convolution_activation Conv_97 LeakyRelu_98
fuse_convolution_activation Conv_100 LeakyRelu_101
fuse_convolution_activation Conv_102 LeakyRelu_103
fuse_convolution_activation Conv_105 LeakyRelu_106
fuse_convolution_activation Conv_107 LeakyRelu_108
fuse_convolution_activation Conv_109 LeakyRelu_110
fuse_convolution_activation Conv_112 LeakyRelu_113
fuse_convolution_activation Conv_114 LeakyRelu_115
fuse_convolution_activation Conv_117 LeakyRelu_118
fuse_convolution_activation Conv_119 LeakyRelu_120
fuse_convolution_activation Conv_122 LeakyRelu_123
fuse_convolution_activation Conv_124 LeakyRelu_125
fuse_convolution_activation Conv_127 LeakyRelu_128
fuse_convolution_activation Conv_129 LeakyRelu_130
fuse_convolution_activation Conv_131 LeakyRelu_132
fuse_convolution_activation Conv_133 LeakyRelu_134
fuse_convolution_activation Conv_135 LeakyRelu_136
fuse_convolution_activation Conv_137 LeakyRelu_138
fuse_convolution_activation Conv_139 LeakyRelu_140
fuse_convolution_activation Conv_144 LeakyRelu_145
fuse_convolution_activation Conv_146 LeakyRelu_147
fuse_convolution_activation Conv_148 LeakyRelu_149
fuse_convolution_activation Conv_150 LeakyRelu_151
fuse_convolution_activation Conv_152 LeakyRelu_153
fuse_convolution_activation Conv_154 LeakyRelu_155
fuse_convolution_activation Conv_156 LeakyRelu_157
fuse_convolution_activation Conv_161 LeakyRelu_162
fuse_convolution_activation Conv_163 LeakyRelu_164
fuse_convolution_activation Conv_165 LeakyRelu_166
fuse_convolution_activation Conv_167 LeakyRelu_168
fuse_convolution_activation Conv_169 LeakyRelu_170
fuse_convolution_activation Conv_171 LeakyRelu_172
Input layer images without shape info, shape_inference skipped
Input layer images without shape info, estimate_memory_footprint skipped
推理验证ncnn模型【 yolov3-opt.param 和 yolov3-opt.bin 】
该版本的 yolov3模型 和 mobilenetv2_yolov3.param 相比是不一样的风格
有 3个 outPut 层,接近于 yolov5 的推理风格 ,有待补充,暂不展开推理
文章来源: positive.blog.csdn.net,作者:墨理学AI,版权归原作者所有,如需转载,请联系作者。
原文链接:positive.blog.csdn.net/article/details/120172949
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)