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

Yannis picture Yannis · Nov 6, 2018 · Viewed 11k times · Source

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?

Answer

user3646527 picture user3646527 · Nov 10, 2018

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