运行YOLOv5时报错:AttributeError: Can't get attribute 'SPPF' on
解决办法如下:首先找到YOLOv5下的这个文件打开
打开文件往下翻找到class SPP这一行,我的是在166行,在这一行上面添加下面的程序添加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))
如图所示:
再运行程序就不会报错啦。
来源地址:https://blog.csdn.net/m0_50004939/article/details/126739291