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.

python tfjs.converter.load_keras_model fails if Variable names already used

See original GitHub issue

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

TensorFlow.js version

tensorflowjs version 0.4.0 keras version 2.1.4

Browser version

None ( this is a python issue)

Describe the problem or feature request

If you create a model, save it to it to tfjs.json format and try to load it within the same python session, it will fail because of a weight renaming issue.

Code to reproduce the bug / link to feature request

import os
import tensorflowjs as tfjs
import keras
OUTPUT_DIR = "/tmp/tfjs-output-dir"

dense_a = keras.layers.Dense(2, input_dim = 3)
model = keras.models.Sequential([dense_a])
tfjs.converters.save_keras_model(model os.path.join(OUTPUT_DIR, "seq_a_tfjs"))
model_prime = tfjs.converters.load_keras_model(os.path.join(
    OUTPUT_DIR, "seq_a_tfjs", "model.json"))

outputs

Using TensorFlow backend.
Traceback (most recent call last):
  File "tiny_nested_model_a_min.py", line 26, in <module>
    model_prime = tfjs.converters.load_keras_model(os.path.join(OUTPUT_DIR, "seq_a_tfjs", "model.json"))
  File "/usr/local/google/home/bileschi/env/a/local/lib/python2.7/site-packages/tensorflowjs/converters/keras_tfjs_loader.py", line 208, in load_keras_model
    use_unique_name_scope=use_unique_name_scope)
  File "/usr/local/google/home/bileschi/env/a/local/lib/python2.7/site-packages/tensorflowjs/converters/keras_tfjs_loader.py", line 74, in _deserialize_keras_model
    weights_list.append(weights_dict[weight_name])
KeyError: u'dense_1_1/kernel'

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bileschicommented, Jun 3, 2018

If you load the model three times you get three versions o the same model, no weight sharing. It modifies the eight names with the number plus underscore method.

On Sat, Jun 2, 2018 at 1:49 PM Daniel Smilkov notifications@github.com wrote:

What does Keras do if you save and load the model in the same session. That is:

model.save(‘my_model.h5’) # creates a HDF5 file ‘my_model.h5’# Will the next line error? model = load_model(‘my_model.h5’)

I’m assuming it will error as well since in their example snippet https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model they do call del model in between.

So it might actually be better to explicitly error than to silently create a whole new graph and double the memory usage.

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/tensorflow/tfjs/issues/373#issuecomment-394104744, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhZTtAhuKlaLgCttzt8v5rHp7eVHEb5ks5t4tAagaJpZM4UXM3l .

– Stan Bileschi Ph.D. | SWE | bileschi@google.com | 617-230-8081

0reactions
caisqcommented, Feb 12, 2019

Reassigning to @davidsoergel for follow-up investigation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught (in promise) Error: Provided weight data has no ...
Unfortunately, when I try to load the JSON model I get this error: Uncaught (in promise) Error: Provided weight data has no target...
Read more >
Can't load keras model exported with tfjs.converters
Hi Timothee,. It's freezing up for me too - then I get an error about weights names. When you write the model, can...
Read more >
How to Convert a Keras SavedModel into a Browser-based ...
If you're a Python developer who works with Keras SavedModels, this article is for you. Perhaps you're not sure how to use SavedModels...
Read more >
@tensorflow/tfjs-converter - npm
A python pip package to convert a TensorFlow SavedModel or TensorFlow Hub module to a web friendly format. If you already have a...
Read more >
Unclear error from tensorflowjs_converter of USE large from ...
When I run tensorflowjs_converter --input_format=tf_hub ... I correctly followed the directions in tensorflow/tfjs/tree/master/tfjs-converter on Github.
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