Skip to content

Freezing specific layers when using Tensorflow Object Detection API #10797

Open
@adithya1-7

Description

@adithya1-7

Greetings,

1. The entire URL of the file you are using

https://github.com/tensorflow/models/blob/master/research/object_detection/model_main_tf2.py
https://github.com/tensorflow/models/blob/master/research/object_detection/model_lib_v2.py

2. Describe the bug

When I provide something in the freeze_variables config, e.g. freeze_variables: ['.*conv.'], and then run training with model_main_tf2.py as in the tutorial, no variables are frozen, and all layers are trained. I went through the model and training protocol configuration steps in model_lib_v2.py, in the train_loop method which is called in model_main_tf2.py, and it never seems to touch the freeze_variables option.

3. Steps to reproduce

Follow the steps of the tutorial to set up a training run for the CenterNet MobileNetV2 FPN 512x512 model, and use the config file included with the model. Add freeze_variables: ['.*conv.'] to train_config. If you add print(detection_model.trainable_variables) to line 673 of model_lib_v2.py (right before the training begins), it outputs all variables, i.e. all variables are still trainable.

4. Expected behavior

Variables matching the provided freeze_variable regex should no longer be trainable.

6. System information

== python version ==============================================
(major, minor, micro, releaselevel, serial)
(3, 7, 10, 'final', 0)

== bazel version ===============================================
Build label: 5.3.1

== check os platform ===============================================
os: Linux
machine: x86_64

== check pips ===================================================
numpy 1.21.6
proto-plus 1.20.3
protobuf 3.19.4
tensorflow 2.8.0
tensorflow-addons 0.14.0
tensorflow-datasets 4.5.2
tensorflow-estimator 2.3.0
tensorflow-hub 0.12.0
tensorflow-io 0.25.0
tensorflow-io-gcs-filesystem 0.25.0
tensorflow-metadata 1.8.0
tensorflow-model-optimization 0.7.2
tensorflow-probability 0.15.0
tensorflow-text 2.8.2
tensorflowjs 3.20.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions