-
-
Notifications
You must be signed in to change notification settings - Fork 17.2k
Description
Search before asking
- I have searched the YOLOv5 issues and found no similar bug report.
YOLOv5 Component
Validation
Bug
Hello YOLOv5 team,
I am experiencing a persistent ModuleNotFoundError: No module named 'models' when trying to validate my model using val.py in the original YOLOv5 repository folder. Here are all the details of my setup and what I have tried so far:
Environment:
What I am doing:
I trained a model on the CCPD2019 dataset using YOLOv5 in its original folder.
I am always working inside the original YOLOv5 repository folder (where val.py, train.py, and the models/ directory are located).
I have not created any custom folders or modules named models.
I have no pip packages named models installed (pip show models returns nothing).
My working directory is always the root of the YOLOv5 repo.
I am running the following command:
bash
python val.py --weights runs/train/exp15/weights/best.pt --data ./data/ccpd.yaml --img 640 --save-json
Error message:
text
ModuleNotFoundError: No module named 'models'
This happens during the torch.load() step when loading the weights.
What I have tried:
Verified that there are no conflicting folders or packages named models in my project or installed via pip.
Checked that my working directory is correct and contains the original YOLOv5 structure.
Confirmed that my Python and PyTorch versions are the same as during training.
Tried adding sys.path.insert(0, './yolov5') at the top of my scripts, but since I am already in the repo root, this should not be necessary.
Uninstalled any unnecessary packages like pathlib that could cause conflicts.
Attempted to extract the state_dict from the checkpoint using a workaround, but the error occurs before I can access the checkpoint.
Additional info:
The model was trained and saved in the same environment and folder where I am now trying to validate it.
The error persists even after restarting the environment.
Request:
Could you please help me troubleshoot this issue? Is there something I am missing regarding the environment, repo structure, or model saving/loading process?
Any suggestions or insights would be greatly appreciated!
Thank you very much for your support.
Let me know if you want to add or change any detail!
Environment
Python version: 3.11.7
PyTorch version: 2.3.0+cu121
CUDA: NVIDIA GeForce RTX 4090, 24GB
YOLOv5 version: v7.0-421-g79c4c31d (latest from GitHub)
Minimal Reproducible Example
literally the code provided of val.py from github, there were no changes (like the train file used for training)
Additional
No response
Are you willing to submit a PR?
- Yes I'd like to help by submitting a PR!