问题描述:
运行yolov5-train.py文件时候,出现问题:
AttributeError: Cant get attribute SPPF on module models.common......(后面是文件路径)
解决办法:
1. 双击打开common.py文件:
2.增加代码:
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)) 直接复制粘贴到common.py文件中去。亲测有效! Tips:把import warnings放在上面去!
声明:上述链接为原创。
本篇内容仅作个人学习记录使用。