yolov5--Can't get attribute 'SPPF' on
测试yolov5时报错 :
Can't get attribute 'SPPF' on <module 'models.common
解决方法:
到tags的版本V6.0的models 目录下的common.py目录复制类SPPF到报错的类文件中
同时倒入头文件 warnings
如下:
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))
还报错:
The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension
下载对应的v5.0版本的.pt文件,地址如下:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
因为默认下载的不是v5.0的,所以要重新下载.pt文件。
再在运行 detect.py
Ok