yolov5代码移植报错问题ModuleNotFoundError: No module named ‘models‘

  • 移植yolov5代码加载模型时有如下报错
Traceback (most recent call last):
  File "D:/workshop/project/CT/DR_Package/DRImgDetect.py", line 156, in 
    CT_det = DRPredicate(path = modelPath)
  File "D:/workshop/project/CT/DR_Package/DRImgDetect.py", line 41, in __init__
    self.model = attempt_load(self.weights, map_location=self.device)  # load FP32 model
  File "D:\workshop\project\CT\DR_Package\DRDetect\models\experimental.py", line 118, in attempt_load
    ckpt = torch.load(w, map_location=map_location)  # load
  File "D:\anaconda\envs\torch\lib\site-packages\torch\serialization.py", line 592, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "D:\anaconda\envs\torch\lib\site-packages\torch\serialization.py", line 851, in _load
    result = unpickler.load()
ModuleNotFoundError: No module named 'models'
  • 解决方法

在出错的文件目录下,构建yolov5的目录结构。即需要存在yolov5的models和utils,复制这两个文件夹到该文件目录下。例如,此时我报错的位置是yolov5/train.py,因为我是使用yolo5做移植,yolov5目录下并不是真正的yolov5,所以会报缺失models。

即运行的脚本程序需跟models,utils在同一目录

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