Unknown initializer: GlorotUniform when loading Keras model

前端 未结 10 1845
心在旅途
心在旅途 2020-11-29 04:43

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 tr

相关标签:
10条回答
  • 2020-11-29 05:00

    I fixed the problem:

    Before:

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

    Works for me

    import tensorflow as tf 
    classifierLoad = tf.keras.models.load_model('model/modeltest.h5')
    
    0 讨论(0)
  • 2020-11-29 05:02

    I ran into the same issue. After changing:

    from tensorflow import keras

    to:

    import keras

    life is once again worth living.

    0 讨论(0)
  • 2020-11-29 05:02
    from tensorflow.keras.initializers import glorot_uniform
    
    loaded_model = tf.keras.models.load_model("pruned.h5",custom_objects={'GlorotUniform': glorot_uniform()})
    
    

    this worked for me when importing tensorflow keras

    0 讨论(0)
  • 2020-11-29 05:03

    if you are loading the architecture and weights separtly, while loading archtiecture of the model change :

    models.model_from_json(json)
    

    to :

    tf.keras.models.model_from_json(json)
    

    and the problem is solved

    0 讨论(0)
  • 2020-11-29 05:03

    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.

    0 讨论(0)
  • 2020-11-29 05:06

    In either kaggle or colabs

    tf.keras.models.load_model("model_path")
    

    works well

    0 讨论(0)
提交回复
热议问题