So, I'm trying to train a YOLO classification model on a custom dataset that contains jpg-images of two different classes. But when I launch training, I get following error:
Traceback (most recent call last):
File "C:\pythonProject\main.py", line 5, in <module>
model.train(data='./training_dataset', epochs=1, imgsz=64)
File "C:\pythonProject\venv\lib\site-packages\ultralytics\engine\model.py", line 341, in train
self.trainer.train()
File "C:\pythonProject\venv\lib\site-packages\ultralytics\engine\trainer.py", line 192, in train
self._do_train(world_size)
File "C:\pythonProject\venv\lib\site-packages\ultralytics\engine\trainer.py", line 288, in _do_train
self._setup_train(world_size)
File "C:\pythonProject\venv\lib\site-packages\ultralytics\engine\trainer.py", line 255, in _setup_train
self.test_loader = self.get_dataloader(self.testset, batch_size=batch_size * 2, rank=-1, mode='val')
File "C:\pythonProject\venv\lib\site-packages\ultralytics\models\yolo\classify\train.py", line 88, in get_dataloader
dataset = self.build_dataset(dataset_path, mode)
File "C:\pythonProject\venv\lib\site-packages\ultralytics\models\yolo\classify\train.py", line 83, in build_dataset
return ClassificationDataset(root=img_path, args=self.args, augment=mode == 'train', prefix=mode)
File "C:\pythonProject\venv\lib\site-packages\ultralytics\data\dataset.py", line 220, in __init__
super().__init__(root=root)
File "C:\pythonProject\venv\lib\site-packages\torchvision\datasets\folder.py", line 309, in __init__
super().__init__(
File "C:\pythonProject\venv\lib\site-packages\torchvision\datasets\folder.py", line 145, in __init__
samples = self.make_dataset(self.root, class_to_idx, extensions, is_valid_file)
File "C:\pythonProject\venv\lib\site-packages\torchvision\datasets\folder.py", line 189, in make_dataset
return make_dataset(directory, class_to_idx, extensions=extensions, is_valid_file=is_valid_file)
File "C:\pythonProject\venv\lib\site-packages\torchvision\datasets\folder.py", line 61, in make_dataset
directory = os.path.expanduser(directory)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\ntpath.py", line 293, in expanduser
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
I've tried two different datasets and that problem occured on both of them.
My full code:
from ultralytics import YOLO
model = YOLO('yolov8n-cls.pt')
model.train(data='./training_dataset', epochs=1, imgsz=64)
Dataset structure:
training_dataset/train/cats;
training_dataset/train/dogs
Nvm, the problem was that my dataset did not contain
'test'
folder which is crucial for that model. After I added it, everything worked just fine.So, your dataset must have following structure: