在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
作者仓库地址为:https://github.com/DataXujing/YOLOv8
首先看错误原因:'ultralytics.nn.modules'
is not a package,说明ultralytics.nn
模块有问题。
查看作者ultralytics
包的内容,并与最新版本对比:
8.0.0:
8.0.229:
可以看出,两者的modules
不同
解决办法很简单,把下载下来的nn
模块替换掉即可,问题解决。