yolov5--Can't get attribute 'SPPF' on
測試yolov5時報錯 :
Can't get attribute 'SPPF' on <module 'models.common
解決方法:
到tags的版本V6.0的models 目錄下的common.py目錄復(fù)制類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
下載對應(yīng)的v5.0版本的.pt文件,地址如下:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
因為默認(rèn)下載的不是v5.0的,所以要重新下載.pt文件。
?
再在運行 detect.py
Ok