ValueError: Unknown layer: name when trying to load a model in keras

Viewed 686

I trained a Cats vs Dogs classification model on Google Colab, then downloaded the model, its weights, and a .json file as well for its structure, but whenever I try to run the following code:

#read model structure from .json file
with open('./models/cats_vs_dogs_1-15.json', 'r') as json_file:
        json_savedModel = json_file.read()

#load model architecture
model_x = tf.keras.models.model_from_json(json_savedModel)

I get the following error:

Traceback (most recent call last):
  File "ddw.py", line 8, in <module>
    model_x = tf.keras.models.model_from_json(json_savedModel)
  File "/home/hmrbcnt/Documents/thesis/try_2.1.5/trial/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/models.py", line 361, in model_from_json
    return layer_module.deserialize(config, custom_objects=custom_objects)
  File "/home/hmrbcnt/Documents/thesis/try_2.1.5/trial/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/layers/serialization.py", line 63, in deserialize
    printable_module_name='layer')
  File "/home/hmrbcnt/Documents/thesis/try_2.1.5/trial/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/utils/generic_utils.py", line 164, in deserialize_keras_object
    list(custom_objects.items())))
  File "/home/hmrbcnt/Documents/thesis/try_2.1.5/trial/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/models.py", line 1333, in from_config
    layer = layer_module.deserialize(conf, custom_objects=custom_objects)
  File "/home/hmrbcnt/Documents/thesis/try_2.1.5/trial/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/layers/serialization.py", line 63, in deserialize
    printable_module_name='layer')
  File "/home/hmrbcnt/Documents/thesis/try_2.1.5/trial/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/utils/generic_utils.py", line 184, in deserialize_keras_object
    function_name)
ValueError: Unknown layer:name

I'm currently running tensorflow v1.5 since my CPU doesn't support avx, and Keras 2.1.5 since using Keras 2.3 results in an error with tf_utils. I'm not using any custom layers in the model either. The same thing happens when I try to load the model, or the model's weights.

I've also tried training the model using the 1.x version of tensorflow on colab, but I still get the same error when loading it locally. If anyone can help me out, I'd really appreciate it. Thanks!

0 Answers
Related