Yolov5原作者一直在更新版本,每个版本的模型可能会发生变化,目前本仓库支持两个版本。
如果使用v6.0需要配置json: "yolov5_version": "v6"
如果使用v5.0需要配置json: "yolov5_version": "v5"
git clone https://github.com/ultralytics/yolov5
cd yolov5
git checkout v6.0
pip install -r requirements.txt
pip install -U coremltools onnx scikit-learn==0.19.2
- 生成onnx, 以yolov5s为例,最终得到yolov5s.onnx
python export.py --include onnx --weights yolov5s.pt --img 640 --batch 1 --opset=11
如果报错 AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
(issue 50),可以降级一下 torch 和 torchvision 的版本:
pip install torch==1.9.0
pip install torchvision==0.10.0
- 使用atc转换模型 将model/yuv420sp_aipp.cfg拷贝到yolov5文件夹下,使用atc转换模型。
atc --mode=0 --model yolov5s.onnx --framework=5 --output=yolov5s_v6 --soc_version=Ascend310 --insert_op_conf=yuv420sp_aipp.cfg
- 将得到的yolov5s_v6.om放到model文件夹备用
git clone https://github.com/ultralytics/yolov5
cd yolov5
git checkout e96c74b5a1c4a27934c5d8ad52cde778af248ed8
pip install -r requirements.txt
pip install -U coremltools onnx scikit-learn==0.19.2
- 生成onnx, 以yolov5s为例,最终得到yolov5s.onnx
python export.py --include onnx --weights yolov5s.pt --img 640 --batch 1 --opset=11
- 修改onnx
- 将model/yolov5_remove_nodes.py拷贝到前一步得到的onnx目录下
- 执行以下命令,将yolov5的focus层的slice和concate算子删除
python yolov5_remove_nodes.py yolov5s.onnx -o yolov5s_truncate.onnx
- 使用atc转换模型
atc --mode=0 --model yolov5s_truncate.onnx --framework=5 --output=yolov5s_truncate --soc_version=Ascend310
- 将得到的yolov5s_truncate.om放到model文件夹备用