ultralytics / ultralytics

NEW - YOLOv8 ๐Ÿš€ in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
28.59k stars 5.68k forks source link

Train Yolov8m Incremental #16283

Open giantonti1801 opened 6 days ago

giantonti1801 commented 6 days ago

Search before asking

Question

Hello friend, I am resorting to this means because I am about to give up. I am trying to do an incremental training with yolov8 and ultralitycs in google colab, the first training I did with the people class, the annotations at 0 in yaml perfectly configured with a single class and the pretrained model used yolov8m, I trained it with 50 epochs and used a data ser of just over 5000 images:! yolo train data = '/content/dataset/persona.v1/data.yaml' model = 'yolov8m.pt' epochs = 50 batch = 64 imgsz = 640 lr0 = 0.0005 name = 'primer_train_incremental' and so far so good, then the second training! yolo train data = '/content/dataset/carro.v1/data.yaml' model = '/content/runs/detect/primer_train_incremental2/weights/best.pt' epochs=50 batch=64 imgsz=640 lr0=0.0005 freeze=10 name='segundo_train_incremental' and use as pre-trained model the best.pt result of the first training with a car dataset of just over 5000 images and the annotations in 1 the yaml: nc: 2 names: ['persona','car'], but whatever I do I lose the previous training, that is, it stops detecting the person, I tried to freeze 5, 10, 15 and 20 layers, it is the maximum that my equipment allows me, but I always lose what was trained previously. What am I doing wrong?

Additional

I trained with Google Colab by freezing 5, 10, 15, 20 and I managed to freeze one with 30 layers but without any result so I lost the knowledge of the previous 79 classes which I want to take advantage of by adding more classes.

UltralyticsAssistant commented 6 days ago

๐Ÿ‘‹ Hello @giantonti1801, thank you for reaching out to us at Ultralytics ๐Ÿš€! This is an automated response, and an Ultralytics engineer will assist you soon.

Youโ€™re tackling an interesting challenge with incremental learning. Let's go through some steps and tips to help you succeed:

Incremental Training with YOLOv8

It looks like you're trying to add new classes without losing the knowledge of the existing ones. Here are some recommendations:

  1. Verify Class Mapping: Ensure that your classes are correctly mapped in your YAML files during the second training:

    nc: 2
    names: ['persona', 'car']

    This ensures that the model knows both the old and new classes.

  2. Use Consistent Annotation: Confirm that all datasets are correctly annotated with the same class index for consistency across incremental training sessions.

  3. Gradually Increase freeze: Freezing layers prevents them from updating during training, which might affect your results if too many are frozen. You've tried various settings; consider starting with a lower number and gradually increasing as necessary.

  4. Learning Rate Adjustments: Sometimes, a lower learning rate can prevent overwriting the learned features of previous classes. Test slightly smaller values than you've used before:

    lr0=0.0001
  5. Fine-tuning Strategy: Use different training strategies, such as fine-tuning previously trained models with different batch sizes and epochs to strike a balance.

Example Training Command

Here's a refined training command:

yolo train data='/content/dataset/persona.v1/data.yaml' model='yolov8m.pt' epochs=50 batch=64 imgsz=640 lr0=0.0001 name='initial_train'
yolo train data='/content/dataset/carro.v1/data.yaml' model='/content/runs/detect/initial_train/weights/best.pt' epochs=50 batch=64 imgsz=640 lr0=0.0001 freeze=10 name='incremental_train'

Resources and Community Support

For detailed guides and support, check out these resources:

Keep experimenting and tweaking your settings. The community and the Ultralytics team are here to support you. If you have more specific details or logs, feel free to share them to get more precise assistance.

Happy training! ๐Ÿ˜Š

Y-T-G commented 6 days ago

You need to have all the classes you want to keep in your dataset during training. Otherwise, the model will forget.