I trained my CNN (VGG) through google colab and generated .h5 file. Now problem is, I can predict my output successfully through google colab but when i download that .h5 trained model file and try to predict output on my laptop, I am getting error when loading the model.
Here is the code:
import tensorflow as tf
from tensorflow import keras
import h5py
# Initialization
loaded_model = keras.models.load_model('./train_personCount_model.h5')
And the error:
ValueError: Unknown initializer: GlorotUniform
Changing
to
solved my problem!
To eliminate errors, import all things directly from Keras or TensorFlow. Mixing both of them in same project may result in problems.
Something that helped me which wasn't in any of the answers:
custom_objects={'GlorotUniform': glorot_uniform()}
I had the same problem with a model built with tensorflow 1.11.0 (using tensorflow.python.keras.models.save_model) and loaded with tensoflow 1.11.0 (using tensorflow.python.keras.models.load_model).
I solved it by upgrading everything to tensorflow 1.13.1, after building the model again with the new version, I could load it without this error.