yolov5 错误Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘xxx‘ >的解决方案

问题描述

下载 yolov5 的 tag5.0 后,运行 detect.py 报如下错误:

Traceback (most recent call last):
File "G:/yolov5-5.0/detect.py", line 178, in
detect()
File "G:/yolov5-5.0/detect.py", line 34, in detect
model = attempt_load(weights, map_location=device) # load FP32 model
File "G:\yolov5-5.0\models\experimental.py", line 118, in attempt_load
ckpt = torch.load(w, map_location=map_location) # load
File "C:\Users\hp\anaconda3\envs\YOLOv5\lib\site-packages\torch\serialization.py", line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "C:\Users\hp\anaconda3\envs\YOLOv5\lib\site-packages\torch\serialization.py", line 882, in _load
result = unpickler.load()
File "C:\Users\hp\anaconda3\envs\YOLOv5\lib\site-packages\torch\serialization.py", line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'SPPF' on models.common' from 'G:\yolov5-5.0\models\common.py'>

问题解决

  1. 找到utils/google_utils.py 文件并打开
    yolov5 错误Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘xxx‘ >的解决方案_第1张图片

  2. 将第 25 行的内容从原来的 response = requests.get(f'https://api.github.com/repos/{repo}/releases/lastest').json()
    修改为
    response = requests.get(f'https://api.github.com/repos/{repo}/releases/tags/v5.0').json() # github api
    yolov5 错误Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘xxx‘ >的解决方案_第2张图片

  3. 如果之前已经成功下载了 yolov5s.pt ,则需将其删除,然后重新运行 detect.py 进行下载
    yolov5 错误Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘xxx‘ >的解决方案_第3张图片

  4. 重新运行 detect.py,如果 yolov5s.pt 下载错误,可能是网络问题,稍等一段时间后重试即可。

参考链接:https://github.com/ultralytics/yolov5/issues/5175

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