在用yolov5-5.0训练的时候,基础版,不是u版的会有些问题。
如:
AttributeError: Can’t get attribute ‘SPPF’ on <module ‘models.common’ from ‘/yolov5-5.0/models/common.py’>
解决方法:
在yolov5-5.0/models/common.py中直接加入这一段代码,保存就行了。
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))
用于本人记录修改报错。