Hey guys,
I’m trying to train using yolov8n, it runs, trains but the validation doesn’t seem to work, the graphs based on the validation doesn’t appear and the prediction of the validation is always empty, the paths seems to be correct either, considering that it can pull the images and labels for the trains, that work and are in the same folder.
Here’s the code I’m using
import os
os.environ['MPLBACKEND'] = 'Agg' # ou 'TkAgg' ou outro backend disponível
import matplotlib
import matplotlib.pyplot as plt
import ultralytics
ultralytics.checks()
# Caminhos para os dados de treinamento e validação
train_path_img = "./yolo_varejo/images/train/"
train_path_label = "./yolo_varejo/labels/train/"
val_path_img = "./yolo_varejo/images/val/"
val_path_label = "./yolo_varejo/labels/val/"
# Comando para iniciar o treinamento com YOLO, assumindo que o script YOLO automaticamente usa GPU se disponível
!yolo task=detect mode=train model=yolov8n.pt data=data.yaml epochs=2 imgsz=448 batch=2 device=0
@Barthos_Menbosa does your data.yaml
look exactly like this?
# Ultralytics YOLO 🚀, AGPL-3.0 license
# Custom dataset for Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/detect/coco8/
# Example usage: yolo train data=coco8.yaml
# parent
# ├── ultralytics
# └── yolo_varejo
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./yolo_varejo # dataset root dir
train: images/train # train images (relative to 'path')
val: images/val # val images (relative to 'path')
test: # test images (optional)
If it looks exactly the same (suggest using a diff
tool) then check if the val
directory has a *.cache
file. If you find one, delete it and try running !yolo task=detect mode=val model=path/to/best.pt data=data.yaml
to see if it works. It should also print out how many images/labels it finds before running val
or train
for validation, or print an error message if it doesn’t find any. I’m guessing that it’s not finding the labels, which could be an issue with the cache or an annotation issue.
Hi!
Thanks for the tips!
The strange part is that it is finding the labels, but in the pred part of the process it doesn´t do it.
My data.yaml:
path: D:/Desktop/IA_barthos/yolo_varejo
train: train/images
val: val/images
nc: 3
names:
0: Cliente
1: Funcionário
2: Sacola
# Augmentations settings
augmentation:
flip: 0 # desativa flip
mosaic: 1
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
translate: 0.1
scale: 0.5
shear: 0.0
perspective: 0.0
rotate: 0 # desativa rotação
augment: true # mantém outras augmentations
The results also look something like this:
It starts plotting based on the data, but it looks like it skips some processes
Yeah that’s definitely strange. What if you try this command:
!yolo task=detect mode=train model=yolov8n.pt data=data.yaml epochs=2 imgsz=448 batch=2 device=0 val=True
If that doesn’t work, a couple things you could test out.
- Try using the same command, but use
data=coco128.yaml
to test using one of our standard datasets
- Create a new Python environment, reinstall
ultralytics
and try in that environment
It’s tough to see the metrics in your screenshot, but I’m guessing that the model isn’t making predictions that are confident enough to pass the filter. Three epochs isn’t going to be enough to really learn anything but more a test to make sure things are working. The default training duration is 100 epochs, I would start there. Additionally, you’ll want to make sure to have lots of annotated data for the model to learn well. Even tho it’s under YOLOv5 tutorials, most (if not all) of the concepts are valid for YOLOv8 and YOLO11 models as well Tips for Best Training Results - Ultralytics YOLO Docs