【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton
你可以去github上,这儿我用的是YOLOv5.5的版本,就去Tags6里面的model/common.py里面去找到这个SPPF的类,把它拷过来到你这个Tags5的model/common.py里面,这样你的代码就也有这个类了,还要引入一个warnings包就行了。替换默认下载的yolov5s.pt,因为默认下载的是V6.1的。替换后,在运行detect.py就OK了。将这个复制到对应的类就行
·
在运行yolov5的时候报错:
一、错误1
Can't get attribute 'SPPF' on <module 'models.common' from 'D:\\Pycharm\\Code\\yolov5-5.0\\models\\common.py'>
没有找到SPPF属性
解决方法:
你可以去github上,这儿我用的是YOLOv5.5的版本,就去Tags6里面的model/common.py里面去找到这个SPPF的类,把它拷过来到你这个Tags5的model/common.py里面,这样你的代码就也有这个类了,还要引入一个warnings包就行了
点开common.py文件
import warnings
class 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))
将这个复制到对应的类就行了。
二、 错误2
解决完上一个问题后又报了一个错误:
RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton
解决方案:
下载:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
替换默认下载的yolov5s.pt,因为默认下载的是V6.1的
替换后,在运行 detect.py就OK了
参考资料:
更多推荐
所有评论(0)