YOLOv5配置过程中:AttributeError: Can‘t get attribute ‘C3‘ on <module ‘models.common‘ from ‘xxx‘

在新的环境中配置YOLOv5过程之中出现了如下错误

(venv) (base) liyi@liyi:~/yolov5-CSDN$ python detect.py --source inference/images/bus.jpg --weights ./runs/train/exp1/weights/best.pt
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', fourcc='mp4v', half=False, img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='inference/images/bus.jpg', view_img=False, weights='./runs/train/exp1/weights/best.pt')
Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1050', total_memory=2000MB)

Traceback (most recent call last):
  File "detect.py", line 162, in 
    detect()
  File "detect.py", line 20, in detect
    model = torch.load(weights, map_location=device)['model']
  File "/home/liyi/yolov5-CSDN/venv/lib/python3.8/site-packages/torch/serialization.py", line 607, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/liyi/yolov5-CSDN/venv/lib/python3.8/site-packages/torch/serialization.py", line 882, in _load
    result = unpickler.load()
  File "/home/liyi/yolov5-CSDN/venv/lib/python3.8/site-packages/torch/serialization.py", line 875, in find_class
    return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'C3' on 

在网上查阅了一些资料,并没有人说与原因是什么,我思考了以下发现是如下原因:

权重pt文件和新环境的YOLOv5的小版本不相同,导致无法使用。


解决方法:

方法一:在新的环境重新训练出权重文件即可成功运行。

方法二:将新的环境中的YOLOv5替换为当时训练权重文件时候的版本即可

你可能感兴趣的:(深度学习,深度学习,pytorch,python)