Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in loading a Keras model in TensorFlow.js #3458

Closed
Gheith-Abandah opened this issue Jun 16, 2020 · 4 comments
Closed

Error in loading a Keras model in TensorFlow.js #3458

Gheith-Abandah opened this issue Jun 16, 2020 · 4 comments
Assignees

Comments

@Gheith-Abandah
Copy link

TensorFlow.js version

2.0.0

Browser version

Chrome Version 83.0.4103.97 (Official Build) (64-bit)

Summary

I have a problem in loading a trained model that was developed using Python and TensorFlow Keras into TensorFlow.js.

Procedure

The model was developed using Python, TensorFlow, and Keras using:
model.fit(...)
model.save('./model_python_tf_keras.h5)
This model is attached.

I then converted this Keras model into a TensorFlow.js model using:
$ tensorflowjs_converter --input_format=keras ./model_python_tf_keras.h5 ./model_js
The resulting folder is attached.

Problem

I get a problem when I try to load the new model in an HTML document (index_min.html is attached) using the following Javascript code:
model = await tf.loadLayersModel('http://localhost:63342/powem_meters/model_js/model.json');
The error message is:
Uncaught (in promise) Error: Provided weight data has no target variable: bidirectional/forward_lstm/lstm_cell_1/kernel

As a result, I am not able to use my model in a Javascript program.

Notes

I have tried to save the model directly from Python using:
tfjs.converters.save_keras_model(model, "./model_js")
And I tried running the tensorflowjs_converted using tf version 1.4.0 and tfjs version 1.2.6. But I keep getting the same error.

I have also noticed that the above procedure works for a simple fully-connected model. However, my model is not a custom one. The model definition code is:
model = Sequential()
model.add(Embedding(num_tokens+1, 32, input_length=max_seq_length))
model.add(Bidirectional(LSTM(latent_dim, input_shape=(None,num_tokens), return_sequences=True, dropout=0.1, recurrent_dropout=0.3), merge_mode='concat'))
model.add(Bidirectional(LSTM(latent_dim, dropout=0.1, recurrent_dropout=0.3), merge_mode='concat'))
model.add(Dense(output_data.shape[1], activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

Details

My environment is as follows:
OS: Ubuntu 20.04
Python version 3.8.2
tensorflow 2.2.0rc4
tensorflowjs 2.0.0
files.zip

@rthadur rthadur self-assigned this Jun 16, 2020
@rthadur rthadur added comp:converter type:support user support questions labels Jun 16, 2020
@rthadur
Copy link
Contributor

rthadur commented Jun 16, 2020

@Gheith-Abandah thanks for reporting , can you please check here for similar issue.

@Gheith-Abandah
Copy link
Author

Gheith-Abandah commented Jun 18, 2020

Thank you for this hint. I have checked Issue #755 before. I am now checking it again and I will come back to you when I reach a conclusion.

@rthadur
Copy link
Contributor

rthadur commented Jun 18, 2020

@Gheith-Abandah thank you , please check this comment as well.

@Gheith-Abandah
Copy link
Author

Using tfjs version 2.0.1 solves this problem thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants