Keras ValueError: Unknown layer:name, when trying to load model to another platform

此生再无相见时 提交于 2019-12-13 01:16:55

问题


I have trained a convolutional neural network using Keras 2.2.4 on Nvidia Quadro board. I have saved the trained model in tow separate files: one file (model.json) that describes the architecture and another file (model.h5) that has all the weights.

I want to load the saved model on the Nvidia Jetson TX2 board that runs Keras 2.2.2 and I'm trying to do it as follows:

# load json and create model
    json_file = open(prefix+'final_model.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    loaded_model = model_from_json(loaded_model_json)
# load weights into new model
    loaded_model.load_weights(prefix+"model.h5")
    model = loaded_model

However, when I tried to load I got the following error:

loaded_model = model_from_json(loaded_model_json)

File "/home/nvidia/.local/lib/python3.5/site-packages/keras/engine/saving.py", line 368, in model_from_json return deserialize(config, custom_objects=custom_objects) File "/home/nvidia/.local/lib/python3.5/site-packages/keras/layers/init.py", line 55, in deserialize printable_module_name='layer') File "/home/nvidia/.local/lib/python3.5/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object list(custom_objects.items()))) File "/home/nvidia/.local/lib/python3.5/site-packages/keras/engine/sequential.py", line 292, in from_config custom_objects=custom_objects) File "/home/nvidia/.local/lib/python3.5/site-packages/keras/layers/init.py", line 55, in deserialize printable_module_name='layer') File "/home/nvidia/.local/lib/python3.5/site-packages/keras/utils/generic_utils.py", line 165, in deserialize_keras_object ':' + function_name) ValueError: Unknown layer:name

I've also tried to save the whole model in one file, but got the same error.

I have tried the solution from here but wasn't able to solve it.

Has anyone seen this error before? Any suggestions?


回答1:


I had the same problem yesterday, I just updated keras through conda and everything worked perfectly.




回答2:


just update the keras package to recent one using following command

conda update keras



来源:https://stackoverflow.com/questions/53180589/keras-valueerror-unknown-layername-when-trying-to-load-model-to-another-platf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!