Unknown initializer: GlorotUniform when loading Ke

2020-01-29 06:27发布

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

9条回答
兄弟一词,经得起流年.
2楼-- · 2020-01-29 07:26

Changing

from keras.models import load_model

to

from tensorflow.keras.models import load_model

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.

查看更多
smile是对你的礼貌
3楼-- · 2020-01-29 07:26

Something that helped me which wasn't in any of the answers:

custom_objects={'GlorotUniform': glorot_uniform()}

查看更多
【Aperson】
4楼-- · 2020-01-29 07:26

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.

查看更多
登录 后发表回答