question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to load Sequential model created containing a Model layer

See original GitHub issue

To get help from the community, check out our Google group.

TensorFlow.js version

0.4.0 (This is the Python library) 0.11.1 (For JavaScript library)

Browser version

I’m using the Python library, but also tried on Google Chrome Version 66.0.3359.139

Describe the problem or feature request

I have a Keras model trained using transfer learning on top of ResNet50. Initially, I trained a separate model using bottleneck features from ResNet50. Later, I attempted to combine these two models. The model summary is as below:

In [8]: model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
resnet50 (Model)             (None, None, None, 2048)  23587712
_________________________________________________________________
reshape_2 (Reshape)          (None, 1, 1, 2048)        0
_________________________________________________________________
sequential_4 (Sequential)    (None, 133)               272517
=================================================================
Total params: 23,860,229
Trainable params: 23,807,109
Non-trainable params: 53,120
_________________________________________________________________

I was successful in using this combined model to perform predictions without generating bottleneck features – despite a warning saying I have an uncompiled model.

I then attempted to use tensorflowjs to save this keras model, and read it again. This is the error I received:

In [9]: tfjs.converters.save_keras_model(model, './letstry3')


In [10]: tfjs.converters.load_keras_model('./letstry3/model.json')
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-10-08bba8228c6f> in <module>()
----> 1 tfjs.converters.load_keras_model('./letstry3/model.json')

~/udacity/udacity-dev/lib/python3.6/site-packages/tensorflowjs/converters/keras_tfjs_loader.py in load_keras_model(config_json_path, weights_path_prefix, weights_data_buffers, load_weights, use_unique_name_scope)
    206   return _deserialize_keras_model(config_json['modelTopology'],
    207                                   weight_entries=weight_entries,
--> 208                                   use_unique_name_scope=use_unique_name_scope)

~/udacity/udacity-dev/lib/python3.6/site-packages/tensorflowjs/converters/keras_tfjs_loader.py in _deserialize_keras_model(model_topology_json, weight_entries, use_unique_name_scope)
     72     weights_list = []
     73     for weight_name in weight_names:
---> 74       weights_list.append(weights_dict[weight_name])
     75     model.set_weights(weights_list)
     76

KeyError: 'conv1_2/kernel'

I also attempted to load this model via your JavaScript library, and I got this error:

Uncaught (in promise) Error: Could not find weights in manifest with names: conv1/kernel, conv1/bias, bn_conv1/gamma, ..(truncated)

I am pretty new to Keras and Tensorflow so it is entirely possible I am doing something completely out of the intended use case. In the event that is true, I would really love some advice on what to do instead.

Thanks!

Code to reproduce the bug / link to feature request

Please see above.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
bileschicommented, Jun 1, 2018

FYI: as a temporary work around, the command line seems to work here:

tensorflowjs_converter --input_format keras ./my_model.h5 ./my_model_as_tfjs 

Still investigating on the code side.

1reaction
bileschicommented, May 29, 2018

Alright, I’m able to reproduce the error locally. Looking to find the root cause.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load a Keras saved model (Error: unable to open file)
Try like this, model.save("my_model"). Calling model.save('my_model') creates a folder named my_model, containing the following:
Read more >
Save and load models | TensorFlow.js
js provides functionality for saving and loading models that have been created with the Layers API or converted from existing TensorFlow models.
Read more >
Model Sub-Classing and Custom Training Loop from Scratch ...
In this article, we will try to understand the Model Sub-Classing API and Custom Training Loop from Scratch in TensorFlow 2.
Read more >
Save and load models in Tensorflow - GeeksforGeeks
We can not load the weights of a model(having 2 dense layers) to a sequential model with 1 Dense layer, as both are...
Read more >
The Sequential model - TensorFlow for R - RStudio
Loaded Tensorflow version 2.9.1. # Call model on a test input x <- tf$ones(shape(3, 3)) y <- model(x). is equivalent to this function:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found