Open dilwolf opened 3 weeks ago
Hi there! ๐ It looks like you're encountering issues related to model package dependencies. From the error logs, it appears that the models.yolo
module is being mistakenly required, which shouldn't be the case with the standard setup.
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 requirements.txt
in the official Yolov5 repository, which includes ultralytics==8.2.13
. Again, it is returning the same error.
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 yolov5x
model on my dataset. I trained using yolov5/train.py
from yolov5 official repository. However, when I use the trained weight with my short inference.py script, it's giving ModuleNotFoundError
. I am curious it should work normally with the YOLO
module when I call from ultralytics import YOLO
. Below is my inference script:
inference.py:
from ultralytics import YOLO model = YOLO("models/best.pt") results = model.predict(source="videos/video.mp4", show=True, save=True)
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 YOLO
class is intended to work directly with the pre-trained models provided or ones trained using Ultralytics official scripts without modification.
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 cls_pw: [15, 0.1, 2]
in data/hyps/hyp.scratch-low.yaml file for weighting loss for imbalanced dataset. I can easily use my fine-tuned weight with predict.py
. However, I can not use my fine-tuned weight with YOLO
class. The YOLO
class just works fine with default pre-trained weight in the original repository.
Today, I tried with latest version ultralytics==8.2.16
but today it has got newtype of Error:
Traceback (most recent call last): File "/home/dilwolf/my_projects/yolov5/inference.py", line 5, in
results = model.predict(source="input_videos/video.mp4", save=True) File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/engine/model.py", line 446, in predict self.predictor.setup_model(model=self.model, verbose=is_cli) File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/engine/predictor.py", line 297, in setup_model self.model = AutoBackend( File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/nn/autobackend.py", line 144, in init model = model.fuse(verbose=verbose) TypeError: BaseModel.fuse() got an unexpected keyword argument 'verbose'
I am not using any kind of verbose function.
inference.py:
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="input_videos/video.mp4", save=True)
Thank you so much for your help on this issue!
As I mentioned earlier, I am using yolov5/train.py by customizing
cls_pw: [15, 0.1, 2]
in data/hyps/hyp.scratch-low.yaml file for weighting loss for imbalanced dataset. I can easily use my fine-tuned weight withpredict.py
. However, I can not use my fine-tuned weight withYOLO
class. TheYOLO
class just works fine with default pre-trained weight in the original repository.Today, I tried with latest version
ultralytics==8.2.16
but today it has got newtype of Error:Traceback (most recent call last): File "/home/dilwolf/my_projects/yolov5/inference.py", line 5, in results = model.predict(source="input_videos/video.mp4", save=True) File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/engine/model.py", line 446, in predict self.predictor.setup_model(model=self.model, verbose=is_cli) File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/engine/predictor.py", line 297, in setup_model self.model = AutoBackend( File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, kwargs) File "/home/dilwolf/anaconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/nn/autobackend.py", line 144, in init** model = model.fuse(verbose=verbose) TypeError: BaseModel.fuse() got an unexpected keyword argument 'verbose'
I am not using any kind of verbose function.
inference.py:
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="input_videos/video.mp4", save=True)
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 weighted_loss
custimization using YOLO CLI?
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 YOLO
class might indicate an incompatibility or an issue with how the custom weights were saved or loaded.
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 YOLO
class handling.
Regarding the error with unexpected keyword argument 'verbose'
, it seems like there might have been changes in the Ultralytics library that are causing this issue. Our team continuously updates the library, so checking the compatibility of different versions might help.
A temporary solution would be to use predict.py
as it works without issues. However, pointing out these discrepancies is crucial for us to update and fix potential bugs in future releases.
For now, unfortunately, there isn't a direct way to implement this specific weighted_loss
customization using the YOLO CLI without diving into the code and modifying the requisite parts as you have done.
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 !!!