I have trained a Keras model based on this repo.
After the training I save the model as checkpoint files like this:
sess=tf.keras.backend.get_session(
This is bug with Tensorflow 1.1x and as another answer stated, it is because of the internal batch norm learning vs inference state. In TF 1.14.0 you actually get a cryptic error when trying to freeze a batch norm layer.
Using set_learning_phase(0)
will put the batch norm layer (and probably others like dropout) into inference mode and thus the batch norm layer will not work during training, leading to reduced accuracy.
My solution is this:
K.set_learning_phase(0)
):def create_model():
inputs = Input(...)
...
return model
model = create_model()
model.save_weights("weights.h5")
K.clear_session()
K.set_learning_phase(0)
model = create_model()
model.load_weights("weights.h5")