add support for freeze training#6001
add support for freeze training#6001youyuxiansen wants to merge 2 commits intoultralytics:masterfrom
Conversation
for more information, see https://pre-commit.ci
|
@youyuxiansen you can freeze any layers with the --freeze argument, i.e. to freeze the backbone (first 10 layers): python train.py --weights yolov5s.pt --freeze 10See argparser for details: Line 472 in 628817d |
|
Hi @glenn-jocher , looks like you haven’t read my commitment. I Submit this because the freeze cannot meet some needs. For example, what if I want to freeze the 2,3,4,5 layers or the 1,3,5,7 layer. And if I want to train multiple times with different frozen layers each time. It is so inconvenient and not directly. But with my commitment, this all can be easy to do. |
|
@youyuxiansen yes the current freeze argument only supports and 'up to layer' value. I think for most customizations a user may want to modify the freeze logic directly here: Lines 126 to 133 in c1249a4 It is true that I think TF supports a wider variety of freezing strategies. |
|
I suggest you try my submission when you have time. @glenn-jocher |
|
@youyuxiansen yes I've browsed the code. I understand it adds features. The main issue is the scope and complexity of additional code that the PR introduces, and the addition of a new file in the YOLOv5 root directory (which itself introduces duplication of existing code/functionality). For various reasons (maintenance, documentation, simplicity) I would encourage you to find the minimum viable solution with the least amount of code required. |
|
@glenn-jocher Ok, I understand. At last, can this part of the commit be accepted for a more flexible frozen layer specified? |
|
@youyuxiansen yes I was going to say we might be able to smartly handle arguments so that a single value would be 'up to layer' and multiple values would simply index the freeze layers, i.e.: python train.py --freeze 10 # freeze up to 10
python train.py --freeze 5 6 7 8 9 10 # freeze layers 5-10EDIT: we don't want to add additional arguments (unless absolutely necessary for a major feature) to train.py as it already has too many arguments. EDIT2: see detect.py --weights as an example of variable length argument: |
|
@glenn-jocher Oh, I see. I think I might have some time tomorrow to modify this for YOLOV5. |
This tutorial is for freeze training
For what
There may be a need for some peoples to train a model with some structure freezer.
Modify
How to use
Customize the model training process by defining a yaml file.
Demo
TODO
Implementation
Currently the training process is independent from train.py, because it needs a little bit more time to put it into train.py, and I am not sure if this feature is important for this repository for now. If necessary, I can merge the changes into train.py later, and I will maintain the bugs of this feature in time.
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Implementation of layer freezing mechanism during training in YOLOv5.
📊 Key Changes
freeze_train.py, a new training script to handle freeze training.freeze_plansfolder with example YAML files for defining freeze strategies.train.pyto support the freeze options through--freezeand--freeze-typeCLI arguments.freeze_plansdetailing how to use freeze training has been added.🎯 Purpose & Impact