ERROR 1:AttributeError: Can’t get attribute ‘SPPF’ on <module ‘models.common’ from '地址
在 common.py 文件中添加SPPF类
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))
warrings会标红,记得 import warrings
ERROR2:RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension 3
这个我猜可能是预训练权重yolov5s.pt]的问题,因为小土堆是5.0的工程,默认下载的是最新的模型,所以不匹配
所以我又去下载了一个,然后把 yolov5s.pt 给覆盖掉了,这个错误就消失了
附上下载链接:https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
————————————————
参考 王十二er
原文链接:https://blog.csdn.net/qq_41885018/article/details/132697325