qq_43799658 2022-03-27 17:38 采纳率: 100%
浏览 680
已结题

使用自己的训练模型,在opencv调用yolov5时遇到的问题

环境 win11 yolov5 v6.0 opencv450

通过谷歌colab训练结果为last.pt
https://download.csdn.net/download/qq_43799658/85044175

在终端中使用

python export.py --weights './last.pt'


转换后是这样

img

yolo.h
文件修改为

img


main.cpp文件修改为

img

运行程序出错,在VS的调试控制台出现

[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (392) cv::dnn::dnn4_v20200908::ONNXImporter::populateNet DNN/ONNX: loading ONNX v7 model produced by 'pytorch':1.10. Number of nodes = 351, inputs = 1, outputs = 4

OpenCV(4.5.0) Error: Unspecified error (> Slice layer only supports steps = 1 (expected: 'countNonZero(step_blob != 1) == 0'), where
>     'countNonZero(step_blob != 1)' is 1
> must be equal to
>     '0' is 0
) in void __cdecl cv::dnn::dnn4_v20200908::ONNXImporter::handleNode(const class opencv_onnx::NodeProto &), file C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp, line 697
[ERROR:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1788) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 5 inputs and 1 outputs: [Slice]:(130)
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1791) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode     Input[0] = 'images'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1791) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode     Input[1] = '127'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1791) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode     Input[2] = '128'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1791) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode     Input[3] = '126'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1791) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode     Input[4] = '129'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1795) cv::dnn::dnn4_v20200908::ONNXImporter::handleNode     Output[0] = '130'
OpenCV(4.5.0) Error: Unspecified error (> Node [Slice]:(130) parse error: OpenCV(4.5.0) C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp:697: error: (-2:Unspecified error) in function 'void __cdecl cv::dnn::dnn4_v20200908::ONNXImporter::handleNode(const class opencv_onnx::NodeProto &)'
> > Slice layer only supports steps = 1 (expected: 'countNonZero(step_blob != 1) == 0'), where
> >     'countNonZero(step_blob != 1)' is 1
> > must be equal to
> >     '0' is 0
> ) in cv::dnn::dnn4_v20200908::ONNXImporter::handleNode, file C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp, line 1797

因为刚接触机器视觉、图像处理及C++的知识,希望能明示问题所在,也恳求能教我如何解决。万分感谢!

  • 写回答

2条回答 默认 最新

  • 爱晚乏客游 2022-03-27 22:49
    关注

    请更新最新版本的代码,预训练模型适用最新版本的就不会出现这个问题了,导致这个问题的话就是你用的模型是旧版本yolov5-5.0版本直接拷贝过来的吧,没有下载最新的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 创建了问题 3月27日

悬赏问题

  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡