yolov5部署1——pytorch->onnx

yolov5部署1——pytorch->onnx

目标:pytorch->onnx->ncnn->android
一,环境部署
代码来自:https://github.com/ultralytics/yolov5
在训练完yolov5模型后,在yolov5主目录下打开终端,输入:

pip3 install onnx>=1.7.0  # for ONNX export
pip3 install coremltools==4.0  # for CoreML export

二,pytorch->onnx转化
1.输入指令

python models/export.py --weights yolov5s.pt --img 640 --batch 1  # export at 640x640 with batch size 1

出现问题如图
在这里插入图片描述
原因:export.py文件太深,调出来就行
在这里插入图片描述
修改指令:

python3 export.py --weights weights/yolov5s.pt --img 640 --batch 1

结果如图:
在这里插入图片描述
三,查看文件
在这里插入图片描述
生成三个文件:yolov5s.mlmodel , yolov5s.onnx , yolov5s.torchscript.pt
四,Netron查看网络结构
1.安装netron

pip3 install netron

在这里插入图片描述
2.使用netron看图
在有.onnx文件的文件夹下打开终端

python3
import netron
netron.start('yolov5s.onnx')

如图:
在这里插入图片描述

会打开浏览器,如图:
在这里插入图片描述
显示网络结构
五,简化onnx文件
1.安装简化器

pip3 install onnx-simplifier

2.执行指令

python3 -m onnxsim  onnx_inputpath onnx_outputpath

在这里插入图片描述
简化后就可以进行onnx->ncnn的操作了

  • 8
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
UnsatisfiableError: The following specifications were found to be incompatible with the existing python installation in your environment: Specifications: - torchaudio -> python[version='2.7.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|3.4.*'] Your python: python=3.10 If python is on the left-most side of the chain, that's the version you've asked for. When python appears to the right, that indicates that the thing on the left is somehow not available for the python version you are constrained to. Note that conda will not change your python version to a different minor version unless you explicitly specify that. The following specifications were found to be incompatible with each other: Output in format: Requested package -> Available versions Package pytorch-cuda conflicts for: pytorch -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8|>=11.8,<11.9'] torchvision -> pytorch==2.0.1 -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8|>=11.8,<11.9'] torchvision -> pytorch-cuda[version='11.6.*|11.7.*|11.8.*'] torchaudio -> pytorch-cuda[version='11.6.*|11.7.*|11.8.*'] torchaudio -> pytorch==2.0.1 -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8|>=11.8,<11.9'] Package requests conflicts for: python=3.10 -> pip -> requests torchvision -> requests Package pytorch conflicts for: torchaudio -> pytorch[version='1.10.0|1.10.1|1.10.2|1.11.0|1.12.0|1.12.1|1.13.0|1.13.1|2.0.0|2.0.1|1.9.1|1.9.0|1.8.1|1.8.0|1.7.1|1.7.0|1.6.0'] torchvision -> pytorch[version='1.10.0|1.10.1|1.10.2|1.11.0|1.12.0|1.12.1|1.13.0|1.13.1|2.0.0|2.0.1|1.9.1|1.9.0|1.8.1|1.8.0|1.7.1|1.7.0|1.6.0|1.5.1'] Package msvc_runtime conflicts for: torchvision -> python[version='>=3.5,<3.6.0a0'] -> msvc_runtime pytorch -> python[version='>=3.5,<3.6.0a0'] -> msvc_runtime Package setuptools conflicts for: python=3.10 -> pip -> setuptools pytorch -> jinja2 -> setuptools torchvision -> setuptools什么意思
06-09
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小俊俊的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值