-
-
Notifications
You must be signed in to change notification settings - Fork 15.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ModuleNotFoundError: No module named 'models.yolo' on custom trained weight. Is it a bug? #12999
Comments
Hi there! 👋 It looks like you're encountering issues related to model package dependencies. From the error logs, it appears that the Please ensure you are using the latest version of YOLOv5 from the Ultralytics GitHub repository. If you've trained your model with a custom setup or modified version of YOLO, make sure all your imports and custom modules are correctly aligned with the Ultralytics library structures. For the multi-GPU training query, ensure you’re using the latest updates of YOLOv5 and PyTorch with correct syntax: python -m torch.distributed.run --nproc_per_node=2 train.py --img 640 --batch 32 --epochs 100 --data data.yaml --weights yolov5s.pt --device 0,1 If issues persist, try retracing your steps or consider training a fresh model with the official scripts to see if the issue is ongoing. For further detailed guidance, please check the docs. |
Hey there! Thank you so much for your help and effort on this. Today, I retrained my model again with fresh source code by cloning it after getting your response. I reinstalled It may seem very childish, but being meticulous may solve our error. Let me briefly explain what I did again today. I started cloning the official repo and fine tuned the pre-trained inference.py:
Any help or suggestion are really appreciated !!! |
Hello! 👋 Thank you for your detailed follow-up and the efforts you’ve put into resolving this issue. The error you're encountering is quite peculiar, especially after following all the correct steps. Just to ensure that we're on the exact same page, the Given your situation, here's a simple thing you can try:
Here's a slightly modified script that makes sure the weights are being pointed to from the correct relative path: from ultralytics import YOLO
# Assuming your 'best.pt' is in the 'models' directory relative to your script
model = YOLO("./models/best.pt")
results = model.predict(source="videos/video.mp4", show=True, save=True) Additionally, if this continues to fail, could you check the version of YOLOv5 directly in your environment to make certain it aligns with your operations? Sometimes, discrepancies in versioning can lead to unexpected issues. If the problem persists, feel free to consult our docs or respond here with any updates or further details. We'll find a solution together! 🚀 |
Thank you so much for your help on this issue! As I mentioned earlier, I am using yolov5/train.py by customizing Today, I tried with latest version
I am not using any kind of verbose function. inference.py:
|
I checked that I can not do this customization using yolo CLI. Because I can use fine-tuned weights using yolo CLI. Or is there a way to do the above |
Hi there! 👋 It looks like you're running into a fairly specific error after customizing and training your model. The error being thrown when using your custom-trained model with the Since the issue arises specifically with customized training configurations and not with the default pre-trained weights, this suggests that the customization itself (i.e., weighting in the loss) might be modifying the model architecture or saved state in a way that isn't fully compatible with the current Regarding the error with A temporary solution would be to use For now, unfortunately, there isn't a direct way to implement this specific Thanks for bringing this to attention, and we appreciate your input as it helps improve the tool! Let us know if there are any further details or changes, and we'll try to assist further! 🚀 |
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 withyolov5/detect.py
in the repository. However, when I use the fine tuned weight with short code for customization, model is returningModuleNotFoundError:
. Below is my short Python script and error logging:inference.py:
Error>>>>>:
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 myinference.py
. Currentultralystics==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 !!!
The text was updated successfully, but these errors were encountered: