Unknown initializer: GlorotUniform when loading Keras model Unknown initializer: GlorotUniform when loading Keras model python python

Unknown initializer: GlorotUniform when loading Keras model


I ran into the same issue. After changing:

from tensorflow import keras

to:

import keras

life is once again worth living.


I fixed the problem:

Before:

from keras.models import load_modelclassifierLoad = load_model('model/modeltest.h5')

Works for me

import tensorflow as tf classifierLoad = tf.keras.models.load_model('model/modeltest.h5')


Wow I, just spent 6 Hours of my life trying to figure this out.. Dmitri posted a solution to this here: I trained a keras model on google colab. Now not able to load it locally on my system.

I'm just basically reposting it here because it worked for me.

This looks like some kind of a serialization bug in keras. If you wrap your load_model with the below CustomObjectScope thingy... all should work..

import kerasfrom keras.models import load_modelfrom keras.utils import CustomObjectScopefrom keras.initializers import glorot_uniformwith CustomObjectScope({'GlorotUniform': glorot_uniform()}):        model = load_model('imdb_mlp_model.h5')