Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does tf.keras.backend.set_learning_phase actually do?

I am trying to use Efficientnet for some object detection and are loading its checkpoint before providing some images. If I set tf.keras.backend.set_learning_phase(True) before doing predictions it results in bad predictions. With that I mean it only has 2 detections with a score above 0.5 threshold (there are about 10 people in the images). If I however have tf.keras.backend.set_learning_phase(False) and doing predictions it has far more detections (about 8) and the threshold is ranging from 0.7 - 0.94. Why is this happening based on the tf.keras.backend.set_learning_phase() call?

Thanks for any help!

like image 647
Araw Avatar asked Sep 06 '25 22:09

Araw


1 Answers

That one is a deprecated function in new versions actually. Some layers(BatchNorm - Dropout) behave differently in training and testing.

By tf.keras.backend.set_learning_phase(True) you actually leave them in training mode so they are active. You want them disabled when making a prediction.

For more check the source.

like image 111
Frightera Avatar answered Sep 12 '25 05:09

Frightera