当前位置:首页 » 《随便一记》 » 正文

在运行yolo5的v5.0版本detect.py时遇到的一些错误

10 人参与  2022年12月24日 12:33  分类 : 《随便一记》  评论

点击全文阅读


        跟着小土堆的视频教学自己遇到的一些问题。

        出现错误的原因:由于yolov5目前最新版本为v6.1,但我跑的是5.0版本,则运行detect.py时自动从github上下载的训练好的模型为最新版本v6.1。从而导致运行环境和模型版本不一致,从而报错。

一、AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\

二、yolov5 ERROR: AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

三、yolov5中The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension 3

四、UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:2228.)  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]

一、AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\

解决方案:在新版本的models/common.py里面去找到这个SPPF的类,把它拷过来到你的models/common.py里面,这样你的代码就也有这个类了,还要引入一个warnings包就行了!还要引入一个warnings包就行了!

有的同学找不到SPPF这个类,那我现在直接粘贴在这里,你们只需要复制到你们的common.py里面即可,记得把import warnings放在上面去:

import warningsclass SPPF(nn.Module):    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))        super().__init__()        c_ = c1 // 2  # hidden channels        self.cv1 = Conv(c1, c_, 1, 1)        self.cv2 = Conv(c_ * 4, c2, 1, 1)        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)     def forward(self, x):        x = self.cv1(x)        with warnings.catch_warnings():            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning            y1 = self.m(x)            y2 = self.m(y1)            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

二、yolov5 ERROR: AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

解决方案:

找到\torch\nn\modules\upsampling.py下的文件

import torch.nn.modules.upsampling,然后摁住ctrl+鼠标左键就会跳转到该文件下,或者摁提示报错的地方也可以跳转到该文件下

之后将如下图所示154行注释掉就行了

三、yolov5中The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension 3

下载:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt

替换默认下载的yolov5s.pt,因为默认下载的是V6.1的

替换后,在运行 detect.py就OK了

四、UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:2228.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]

 找到functional.py的第568行,

将 return _VF.meshgrid(tensors, **kwargs)改为 return _VF.meshgrid(tensors, **kwargs,indexing='ij')

 


点击全文阅读


本文链接:http://zhangshiyu.com/post/50313.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 新章速递汤安甯,白子奕,汤贝贝是什么小说(结婚十年,回归家庭的老婆在外有二胎了)完本阅读无广告(结婚十年,回归家庭的老婆在外有二胎了)
  • 娇牛马导师偷我论文99篇成功升博导,我让他牢底坐穿精校文本_周老师师姐师兄爽文_小说后续在线阅读_无删减免费完结_
  • 独家顾宇,罗薇:结局+番外精编之作(资助生装阔气,我可不参加)电子书畅享阅读
  • 宗门全员重生,小师妹摆烂不干了(君拂君芙蓉)_宗门全员重生,小师妹摆烂不干了
  • 成了高考状元后,我倒欠两百万完结txt_阿姨叶青江安TOP10_小说后续在线阅读_无删减免费完结_
  • 嫁绝嗣长官,好孕作精在七零躺赢小说(顾嘉宁)序章+全章阅读(嫁绝嗣长官,好孕作精在七零躺赢)最新章节
  • 秦安,温千雪:+后续现已上架(大宋:开局错把皇帝当亲爹):结局+番外评价五颗星
  • 八零我被判黑五类下矿区后,手撕兼祧两房的丈夫无法释怀_陈叙张悦翠花新鲜出炉_小说后续在线阅读_无删减免费完结_
  • 开局签到天人修为,建立无上神朝无法释怀_叶玄后续+完结_小说后续在线阅读_无删减免费完结_
  • ,沐小暖番外(恶毒后娘她真香)TXT+后续+结局在线阅读
  • 萌萌,多多,阿钰小说(我妈的执念)+前传(萌萌,多多,阿钰)阅读
  • 沈菲,楚思明,楚砚洲(哥哥急需颅内手术,黄金右手的我却拒绝执刀)小说***下载_章节前文+后续(沈菲,楚思明,楚砚洲)

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1