Can Keras automatically recognize the Drop and BatchNorm in train and test/validate phases?

Viewed 988

I have been a Tensorflow user, In tensorflow, I must explicitly treat the Drop and BatchNorm. For example, in test/validate phases, the Drop rate must be set to be 1, and specifilize the training flag for BatchNorm.

My question is: Can Keras automatically recognize the Drop and BatchNorm in train and test/validate phases? For example, if I use the model.predict(), Keras will know I am in the pjhase of test/validate, so it automatically process the Drop and BatchNorm?

B.T.W., Keras will set the rate to be 0 for Dropout when in validate/test phases, which is contrast to it in Tensorflow. In Tensorflow, Drop rate will set to be 1.

1 Answers

Yes, Keras already tracks the learning/testing phases internally, it does it through an internal variable called learning_phase, which is set to zero when testing, and to one when training.

You can interact this variable with keras.backend functions learning_phase() and set_learning_phase(value) which are fully documented.

Related