Unknown initializer: GlorotUniform when loading Keras model

前端 未结 10 1884
心在旅途
心在旅途 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:21

    I had a same problem and was fixed this way. just don't save the optimizer with the model! just change the save line like this:

    the_model.save(file_path,True/False,False)
    

    Second parameter tells Keras to overwrite the model if the file existed or not and the 3rd one tells it not to save the optimizer with the model.


    Edit: I ran over the problem again on another system today and this did not helped me this time. so i saved the model conf as json and weights as h5 and used them to rebuild the model in another machine. you can do it like this. save like this:

    json = model.to_json()
    # Save the json on a file
    model.save_weights(weights_filepath,save_format="h5")
    

    rebuild the model like this:

    # load the json file
    # here i use json as loaded content of json file
    model = keras.models.model_from_json(json)
    model.load_weights(weights_file_path)
    

提交回复
热议问题