Keras ValueError: Unknown layer:name, when trying

2019-08-13 09:41发布

问题:

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