第一次运行YOLOv5时可能会出现的问题
1.运行YOLOv5出现报错:AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\yolov5-5.0\models\
2.运行YOLOv5出现报错:RuntimeError: The size of tensor a (60) must match the size of tensor b (56) at non-singLeton dimension 3
1.运行YOLOv5出现报错找不到SPPF错误,进行解决AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\yolov5-5.0\models\
解决办法如下:首先找到YOLOv5下的这个文件打开
点开common.py 往下翻找到class SPP这一行,在我电脑上是157行,在这一行上面添加下面的程序添加class SPPF
class SPPF(nn.Module):
def __init__(self, c1, c2, k=5):
super().__init__()
c_ = c1 // 2
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')
y1 = self.m(x)
y2 = self.m(y1)
return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))