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

使用自己的训练模型,在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日

悬赏问题

  • ¥200 内网渗透测试 横向渗透 Windows漏洞 Windows权限维持
  • ¥15 数据结构图的相关代码实现
  • ¥20 求友友们解惑,感激不尽
  • ¥15 python中aiohttp.client_exceptions.ContentTypeError
  • ¥30 DeepLung肺结节检测生成最大froc值对应的epoch报错
  • ¥15 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家
  • ¥20 使用Matlab APP设计一个插补小程序
  • ¥15 evo评估时曲线出现问题