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

Issue

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!

Solution

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.

Answered By – Frightera

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published