Closed Gheith-Abandah closed 4 years ago
@Gheith-Abandah thanks for reporting , can you please check here for similar issue.
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.
Using tfjs version 2.0.1 solves this problem thank you.
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