I'm struggling to figure out how to properly save a tensorflow model that was saved as a saved_model method and convert it to tensorflow.js. It would be great if there was an end to end tutorial that shows how to do this.
Anyways, the model I want to convert is from this jupyter notebook "RNN for Human Activity Recognition - 2D Pose Input":
The full code for building and training the graph can be found in that jupyter notebook.
I can successfully run the code:
save_path = "/content/gdrive/My Drive/saved_model/"
tf.saved_model.simple_save(sess,
save_path,
inputs={"x":x},
outputs={"y": y})
From looking at the
graph building code I'm not entirely sure what the
output_node_names should be in the
tensorflowjs_converter command, because when I put in
y I get an error that the node does not exist. I printed out all the graph nodes and am guessing it's
mul_1/y , as this is what's in the graph building code:
def LSTM_RNN(_X, _weights, _biases):
# model architecture based on "guillaume-chevalier" and "aymericdamien" under the MIT license.
_X = tf.transpose(_X, [1, 0, 2]) # permute n_steps and batch_size
# rest of graph building code left out for this post
# Linear activation
return tf.matmul(lstm_last_output, _weights['out']) + _biases['out']
When I run the command:
!tensorflowjs_converter \
--input_format=tf_saved_model \
--output_node_names="mul_1/y" \
--saved_model_tags=serve \
/content/gdrive/My\ Drive/saved_model/ \
/content/gdrive/My\ Drive/web_model/
It succeeds with this message:
Using TensorFlow backend.
2019-02-23 01:46:53.475557: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Writing weight file /content/gdrive/My Drive/web_model/tensorflowjs_model.pb...
However, the tensorflowjs_model.pb file is only 50 bytes, and all that's contained within weights_manifest.json is:
[{"paths": ["group1-shard1of1"], "weights": [{"name": "mul_1/y", "shape": [], "dtype": "int32"}]}]
What am I doing wrong?