AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo

Namespace(augment=False, batch_size=32, conf_thres=0.001, data=‘/yolov5-5.0/data/coco128.yaml’, device=‘’, exist_ok=False, img_size=640, iou_thres=0.6, name=‘exp’, project=‘runs/test’, save_conf=False, save_hybrid=False, save_json=False, save_txt=False, single_cls=False, task=‘val’, verbose=False, weights=[‘/yolov5-5.0/weights/’])
YOLOv5 🚀 2021-4-11 torch 1.10.1+cu111 CUDA:0 (NVIDIA GeForce RTX 3090, 24268.3125MB)

Traceback (most recent call last):
File “/yolov5-5.0/”, line 313, in
File “/yolov5-5.0/”, line 56, in test
model = attempt_load(weights, map_location=device) # load FP32 model
File “/yolov5-5.0/models/”, line 118, in attempt_load
ckpt = torch.load(w, map_location=map_location) # load
File “/opt/conda/lib/python3.8/site-packages/torch/”, line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File “/opt/conda/lib/python3.8/site-packages/torch/”, line 882, in _load
result = unpickler.load()
File “/opt/conda/lib/python3.8/site-packages/torch/”, line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can’t get attribute ‘SPPF’ on <module ‘models.common’ from ‘/yolov5-5.0/models/’>


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))
        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([x, y1, y2, self.m(y2)], 1))


物联沃-IOTWORD物联网 » AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo