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

Added support for gradual unfreezing while training (transfer-learning) #9684

Closed
wants to merge 2 commits into from
Closed

Added support for gradual unfreezing while training (transfer-learning) #9684

wants to merge 2 commits into from

Conversation

senhorinfinito
Copy link
Contributor

@senhorinfinito senhorinfinito commented Oct 3, 2022

Unfreezing layers during training is one the strategy used in ULMFIT to fine-tune model. Based on that, I have updated code to unfreeze layers during training.

Compatibility Changes

  • Added --grad_unfreeze , to able the gradual unfreezing.
  • --unfreezing_layers , layer ids, (it is basically decided on number of layers has already frozen)
  • --unfreeze_epochs, Epoch number, where you want to unfreeze the layer.

Usage

To use gradual unfreeze, if only backbone is frozen & trained for 50 epochs.
python train.py --data coco.yaml --cfg yolov5n.yaml --weights '' --batch-size 128 --grad_unfreeze --unfreezing_layers 9 --unfreezing_layers 8 --unfreezing_layers 7 --unfreezing_layers 6 --unfreeze_epochs 15 20 25 30 35

You can find issue here #9677

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Implemented Gradual Unfreezing in YOLOv5 training 🚀.

📊 Key Changes

  • Added the gradual_unfreeze function to allow selective unfreezing of model layers during training.
  • Updated train.py to support new command-line arguments for gradual unfreezing.
  • Modified training loop to perform gradual unfreezing based on specified layers and epochs.

🎯 Purpose & Impact

  • Purpose: To improve model fine-tuning by gradually unfreezing layers during training, allowing for more controlled learning.
  • Impact: Users can now fine-tune models more effectively, potentially leading to better performance and quicker convergence. This could be especially useful when adapting pre-trained models to new datasets or tasks. 🆕✨

@senhorinfinito senhorinfinito deleted the grad_unfreeze branch October 26, 2022 15:10
@WangQvQ
Copy link

WangQvQ commented Jan 2, 2023

在训练期间解冻层是 ULMFIT 中用于微调模型的策略之一。基于此,我更新了代码以在训练期间解冻层。

兼容性更改

  • 添加,以便能够逐渐解冻。--grad_unfreeze
  • --unfreezing_layers,层 ID,(基本上决定了层数已经冻结了)
  • --unfreeze_epochs、纪元编号,用于解冻图层的位置。

用法

使用渐进解冻,如果只有骨干被冻结和训练50个epoch。 python train.py --data coco.yaml --cfg yolov5n.yaml --weights '' --batch-size 128 --grad_unfreeze --unfreezing_layers 9 --unfreezing_layers 8 --unfreezing_layers 7 --unfreezing_layers 6 --unfreeze_epochs 15 20 25 30 35

您可以在此处找到问题 #9677

Thank you for your contribution. I modified the file according to your way, but there was an error:
AssertionError: Length of unfreezeing layers [[9], [8], [7], [6]] not matched with [[9], [8], [7], [6]]

@anantsakhare
Copy link

anantsakhare commented Jan 4, 2023

在训练期间解冻层是 ULMFIT 中用于微调模型的策略之一。基于此,我更新了代码以在训练期间解冻层。

兼容性更改

  • 添加,以便能够逐渐解冻。--grad_unfreeze
  • --unfreezing_layers,层 ID,(基本上决定了层数已经冻结了)
  • --unfreeze_epochs、纪元编号,用于解冻图层的位置。

用法

使用渐进解冻,如果只有骨干被冻结和训练50个epoch。 python train.py --data coco.yaml --cfg yolov5n.yaml --weights '' --batch-size 128 --grad_unfreeze --unfreezing_layers 9 --unfreezing_layers 8 --unfreezing_layers 7 --unfreezing_layers 6 --unfreeze_epochs 15 20 25 30 35
您可以在此处找到问题 #9677

Thank you for your contribution. I modified the file according to your way, but there was an error: AssertionError: Length of unfreezeing layers [[9], [8], [7], [6]] not matched with [[9], [8], [7], [6]]

Please use an equal number of epoch & equal number of layers if you want to unfreeze 4 layers, use 4 different epoch values.
@WangQvQ Thanks for showing interest in implementations.
eg.
python train.py --data coco.yaml --cfg yolov5n.yaml --weights '' --batch-size 128 --grad_unfreeze --unfreezing_layers 9 --unfreezing_layers 8 --unfreezing_layers 7 --unfreezing_layers 6 --unfreeze_epochs 15 20 25 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants