models icon indicating copy to clipboard operation
models copied to clipboard

Fine-tuning in model_main_tf2.py

Open StoyanBoyukliyski opened this issue 3 years ago • 2 comments

Prerequisites

Please answer the following question for yourself before submitting an issue.

  • [x] I checked to make sure that this issue has not been filed already.

1. The entire URL of the documentation with the issue

https://github.com/tensorflow/models/tree/master/research/object_detection

2. Describe the issue

I have been looking around the source code, but I can't find how the actual fine-tuning is done. I know there is an option to train from a "detection" and from a "classification" checkpoint and I understand that this involves loading the weights from a previous checkpoint. But when it comes to training what layers are actually trained? Do you do transfer learning or do pertaining on the entire architecture?

I looked at the tutorials: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/inference_from_saved_model_tf2_colab.ipynb and I understand that here you are fine-tuning only the final 6 layers from the classification and regression heads and that makes sense, but when you train using the model_main_tf2.py file I can't find how the trainable_variables are selected.

There doesn't seem to be a selection class or function in the project. Can you customize in the model_main_tf2.py the layers that you want to fine-tune?

StoyanBoyukliyski avatar Nov 02 '22 15:11 StoyanBoyukliyski

Hi @StoyanBoyukliyski ,

In the new tensor-flow model garden, official models repository has new experiment configuration where you can train layers using task.build_model() to select the trainable variables.

The Task object has all the methods necessary for building the dataset, building the model, and running training & evaluation. These methods are driven by tfm.core.train_lib.run_experiment

Please refer new tensor-flow model garden example and the new official repository for your reference.

I have attached gist file for your reference. Please let us know if this can help you to solve your problem.

laxmareddyp avatar Nov 02 '22 23:11 laxmareddyp

Hi,

Thank you for that. I will have a look at it.

However, my current project is using model/research/object_detection and I will need to understand how the fine-tuning works there: namely if the fine-tuning done in model_main_tf2.py is on the whole network or on the final layers and where this is configured.

StoyanBoyukliyski avatar Nov 03 '22 08:11 StoyanBoyukliyski

Hi,

Thank you for that. I will have a look at it.

However, my current project is using model/research/object_detection and I will need to understand how the fine-tuning works there: namely if the fine-tuning done in model_main_tf2.py is on the whole network or on the final layers and where this is configured.

Just from thinking about I guess the training process adjusts all the weights in the architecture for transfer learning. You always do transfer learning with the OD API.

Petros626 avatar Jun 24 '23 07:06 Petros626