Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train Yolov8m Incremental #16283

Open
1 task done
giantonti1801 opened this issue Sep 14, 2024 · 3 comments
Open
1 task done

Train Yolov8m Incremental #16283

giantonti1801 opened this issue Sep 14, 2024 · 3 comments
Labels
detect Object Detection issues, PR's question Further information is requested Stale Stale and schedule for closing soon

Comments

@giantonti1801
Copy link

Search before asking

  • I have searched the Ultralytics YOLO issues and discussions and found no similar questions.

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.

@giantonti1801 giantonti1801 added the question Further information is requested label Sep 14, 2024
@UltralyticsAssistant UltralyticsAssistant added the detect Object Detection issues, PR's label Sep 14, 2024
@UltralyticsAssistant
Copy link
Member

👋 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! 😊

Copy link
Collaborator

Sep 14, 2024

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

Copy link

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detect Object Detection issues, PR's question Further information is requested Stale Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

3 participants