I trained a keras model on google colab. Now not able to load it locally on my system.

前端 未结 3 412
梦毁少年i
梦毁少年i 2020-12-20 21:18
with open(\'2model.json\',\'r\') as f:
json = f.read()
model = model_from_json(json)
model.load_weights(\"color_tensorflow_real_mode.h5\")

I traine

相关标签:
3条回答
  • 2020-12-20 21:51

    I had similar error (Unknown layer:name) when I was trying to locally load model trained on Colab. I was trying to change keras version, tensorflow version, conda version etc. and nothing helped. I solved this by saving my model's weights on Colab, locally creating the same model and loading the weights to this model.

    0 讨论(0)
  • 2020-12-20 21:53

    load the model using

     from tensorflow.keras.models import load_model
    

    instead of

    from keras.models import load_model
    

    I tried using many methods but this is the one that finally worked!

    0 讨论(0)
  • 2020-12-20 22:04
    1. Make sure you have the newest version of Keras and tensorflow (which are 2.4.4 and 1.11.0) by running either pip install keras tensorflow or conda install keras tensorflow.

    2. In case it is Google Colab that uses deprecated objects, you may need to use custom objects:

    from keras.utils import CustomObjectScope
    from keras.initializers import glorot_uniform
    
    with CustomObjectScope({'GlorotUniform': glorot_uniform()}):
        model = load_model('my_model.h5')
    

    Not sure if this is your case though.

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