pythonyolov8

YOLOv8 won't recognize my config.yaml file


I keep attempting to make a custom dataset for yolov8 to learn. I'm using this python script:

from ultralytics import YOLO
model = YOLO("yolov8n.yaml")

results = model.train(data="config.yaml", epochs=1)

But I keep getting this error:

Ultralytics YOLOv8.0.92  Python-3.10.11 torch-2.0.0+cpu CPU
yolo\engine\trainer: task=detect, mode=train, model=yolov8n.yaml, data=config.yaml, epochs=1, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=0, resume=False, amp=True, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, cfg=None, v5loader=False, tracker=botsort.yaml, save_dir=runs\detect\train23
Traceback (most recent call last):
  File "C:\Users\harri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ultralytics\yolo\engine\trainer.py", line 122, in __init__
    self.data = check_det_dataset(self.args.data)
  File "C:\Users\harri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ultralytics\yolo\data\utils.py", line 195, in check_det_dataset
    data = check_file(dataset)
  File "C:\Users\harri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ultralytics\yolo\utils\checks.py", line 292, in check_file
    raise FileNotFoundError(f"'{file}' does not exist")
FileNotFoundError: 'config.yaml' does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\harri\Documents\pythonAlgorithms\data\main.py", line 4, in <module>
    results = model.train(data="config.yaml", epochs=1)
  File "C:\Users\harri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ultralytics\yolo\engine\model.py", line 365, in train
    self.trainer = TASK_MAP[self.task][1](overrides=overrides, _callbacks=self.callbacks)
  File "C:\Users\harri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ultralytics\yolo\engine\trainer.py", line 126, in __init__
    raise RuntimeError(emojis(f"Dataset '{clean_url(self.args.data)}' error ❌ {e}")) from e
RuntimeError: Dataset 'config.yaml' error  'config.yaml' does not exist

I have repeatedly deleted my config.yaml file to see if the error would change, but it returns the same error regardless if the config file is there or not. I have it in the same directory as my python script and still nothing.

I also attempted to put the filepath in for

results = model.train(data="config.yaml", epochs=1)

But I still keep getting the same error


Solution

  • I resolve the same issue on Windows 11 (VSCode) by setting an absolute path:

    main.py

    results = model.train(data="C:\\Users\\AJ\\Desktop\\yolov8\\code\\config.yaml", epochs=1) # train the model
    

    config.yaml

    path: 'C:\Users\AJ\Desktop\yolov8\code\data' #dataset root dir