运行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
m.genealogy-computer-tips.com1 = Conv(c1, c_, 1, 1)
m.genealogy-computer-tips.com2 = Conv(c_ * 4, c2, 1, 1)
self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
def forward(self, x):
x = m.genealogy-computer-tips.com1(x)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
y1 = self.m(x)
y2 = self.m(y1)
return m.genealogy-computer-tips.com2(m.genealogy-computer-tips.com([x, y1, y2, self.m(y2)], 1))
如图所示:
再运行程序就不会报错啦。