3

I'm using YOLOv5, clone from its official github repo.

During the training I got the following error:

Traceback (most recent call last):
  File "C:\Users\nived\Untitled Folder 1\train.py", line 40, in <module>
    import models
ModuleNotFoundError: No module named 'models'

Train command:

!python train.py --img 416 --batch 16 --epochs 150 --data relative/path/to/data.yaml --weights yolov5s.pt --cache*
Lorenzo Mogicato
  • 138
  • 1
  • 11
NIVEDITHA J
  • 31
  • 1
  • 1
  • 3
  • No module named 'models' usually occurs when the specified directory path for data or weight file is not correct. Correcting it will resolve the issue. – rs_punia Aug 06 '22 at 13:19

2 Answers2

5

Please add mentioned code in the top two lines of the detect.py file and it will work then,

import sys
sys.path.insert(0, './yolov5')

For more details, you can visit link from YOLOv5 Repository

0

The problem is that your python path does not have access to the models module from the yolo repository root. In some scenarios, it is not sufficient to append the path of the repo to the list of python paths -> sys.path.append('./yolov5'). Inserting the path at the beginning should solve the problem:
in train.py add these lines at the top of the file:

ROOT = Path(__file__).resolve().parents[0] # YOLO root directory
sys.path.insert(0, str(ROOT))