Issue doing transfer learning on YOLOv8

215 views Asked by At

I have trained a custom YOLOv8s model on my dataset which has 1 class - "Employee". I want the original YOLOv8s model (with 80 classes) to be my base model and do transfer learning from my custom model. I tried achieving this with the following command:

yolo task=detect mode=train data=data.yaml model=yolov8s.yaml pretrained=yolov8s.pt epochs=25 imgsz=640 plots=True

But this returns me the following error:

RuntimeError: Dataset 'data.yaml' error  data.yaml 'names' length 1 and 'nc: 80' must match.

This issue arises because the number of classes in the base YOLOv8 model is not matching the number of classes in the custom model I have trained with. Is it necessary that the number of classes in the base and custom YOLOv8 model should be the same?

The YOLOv8 Docs doesn't give a proper code which explains how transfer learning can be done.

1

There are 1 answers

0
Proxy Prochy On

I found this answer, it seems to apply to your issue. https://github.com/ultralytics/ultralytics/issues/7793#issuecomment-1908622002

Especially this part:

For transfer learning, you should ensure that your new dataset includes the original classes plus the additional ones. The model.yaml file should reflect the total number of classes (original + new). When you initiate training with the .train() method, the model should automatically detect the number of classes from the dataset provided.