当前位置:   article > 正文

解决yolov8推理报错:ModuleNotFoundError: No module named ‘ultralytics.nn.modules.conv‘_modulenotfounderror: no module named 'ultralytics.

modulenotfounderror: no module named 'ultralytics.nn.modules.conv'; 'ultraly

1.项目场景:

GitHub上下载了一个yolov8的代码,训练好检测模型,运行作者给的推理代码报错:

Traceback (most recent call last):
  File "E:\Pycharm\pytorch-project\YOLOv8\inference.py", line 9, in <module>
    model = YOLO("./runs/detect/train/weights/last.pt")
  File "E:\Pycharm\pytorch-project\YOLOv8\ultralytics\yolo\engine\model.py", line 55, in __init__
    {'.pt': self._load, '.yaml': self._new}[Path(model).suffix](model)
  File "E:\Pycharm\pytorch-project\YOLOv8\ultralytics\yolo\engine\model.py", line 83, in _load
    self.model, self.ckpt = attempt_load_one_weight(weights)
  File "E:\Pycharm\pytorch-project\YOLOv8\ultralytics\nn\tasks.py", line 341, in attempt_load_one_weight
    ckpt = torch.load(attempt_download(weight), map_location='cpu')  # load
  File "E:\Anaconda3\envs\pytorch\lib\site-packages\torch\serialization.py", line 809, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "E:\Anaconda3\envs\pytorch\lib\site-packages\torch\serialization.py", line 1172, in _load
    result = unpickler.load()
  File "E:\Anaconda3\envs\pytorch\lib\site-packages\torch\serialization.py", line 1165, in find_class
    return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'ultralytics.nn.modules.conv'; 'ultralytics.nn.modules' is not a package
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

2.原因分析:

作者仓库地址为:https://github.com/DataXujing/YOLOv8
首先看错误原因:'ultralytics.nn.modules'is not a package,说明ultralytics.nn模块有问题。
查看作者ultralytics包的内容,并与最新版本对比:
8.0.0:
在这里插入图片描述
8.0.229:
在这里插入图片描述

可以看出,两者的modules不同


3.解决方案:

解决办法很简单,把下载下来的nn模块替换掉即可,问题解决。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/738125
推荐阅读
相关标签
  

闽ICP备14008679号