Skip to content

ModuleNotFoundError: No module named 'models.yolo' on custom trained weight. Is it a bug? #12999

@dilwolf

Description

@dilwolf

Search before asking

Question

After training the Yolov5 model on a custom dataset with yolov5/train.py in the repository for multi-gpu and loss_weight purposes, I am able to do inference with yolov5/detect.py in the repository. However, when I use the fine tuned weight with short code for customization, model is returning ModuleNotFoundError:. Below is my short Python script and error logging:

inference.py:

from ultralytics import YOLO
model = YOLO("models/best.pt")
results = model.predict(source="videos/video.mp4", show=True, save=True)

Error>>>>>:

WARNING ⚠️ models/best.pt appears to require 'models.yolo', which is not in ultralytics requirements.
AutoInstall will run now for 'models.yolo' but this feature will be removed in the future.
Recommend fixes are to train a new model using the latest 'ultralytics' package or to run a command with an official YOLOv8 model, i.e. 'yolo predict model=yolov8n.pt'
requirements: Ultralytics requirement ['models.yolo'] not found, attempting AutoUpdate...
ERROR: Could not find a version that satisfies the requirement models.yolo (from versions: none)
ERROR: No matching distribution found for models.yolo
Retry 1/2 failed: Command 'pip install --no-cache "models.yolo" ' returned non-zero exit status 1.
requirements: AutoUpdate success ✅ 2.7s, installed 1 package: ['models.yolo']
requirements: ⚠️ Restart runtime or rerun command for updates to take effect

Traceback (most recent call last):
File "/home/imes-server2/anaconda3/envs/dilwolf/lib/python3.10/site-packages/ultralytics/nn/tasks.py", line 732, in torch_safe_load
ckpt = torch.load(file, map_location="cpu")
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/torch/serialization.py", line 1025, in load
return _load(opened_zipfile,
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/torch/serialization.py", line 1446, in _load
result = unpickler.load()
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/torch/serialization.py", line 1439, in find_class
return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'models.yolo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/user/Dilwolf/football_analysis/inference.py", line 3, in
model = YOLO('models/best_weighted.pt')
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/ultralytics/models/yolo/model.py", line 23, in init
super().init(model=model, task=task, verbose=verbose)
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/ultralytics/engine/model.py", line 151, in init
self._load(model, task=task)
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/ultralytics/engine/model.py", line 240, in _load
self.model, self.ckpt = attempt_load_one_weight(weights)
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/ultralytics/nn/tasks.py", line 806, in attempt_load_one_weight
ckpt, weight = torch_safe_load(weight) # load ckpt
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/ultralytics/nn/tasks.py", line 752, in torch_safe_load
ckpt = torch.load(file, map_location="cpu")
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/torch/serialization.py", line 1025, in load
return _load(opened_zipfile,
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/torch/serialization.py", line 1446, in _load
result = unpickler.load()
File "/home/user/anaconda3/envs/dilwolf/lib/python3.10/site-packages/torch/serialization.py", line 1439, in find_class
return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'models.yolo'

Tried restarting runtime and other installations, did not work....

Additional

When I trained with !yolo task=detect mode=train model=yolov5x.pt data=data.yaml epochs=100 imgsz=640 command on jupyter notebook, I am able to run fine tuned weight with my inference.py. Current ultralystics==8.2.11 I also tried with little bit previous version of ultralytics but it did not help.

Furthermore, is it possible use mult-gpu, when I train with !yolo task=detect ..... on jupter notebook? I tried !yolo -m torch.distributed.run nproc_per_node=2 train.py batch=64 data=data.yaml --weights yolov5s.pt --device 0,1 but did not work?

Thanks in advance !!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleStale and schedule for closing soonquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions