[question] exporting model to tensorflowjs
See original GitHub issueFirst of all, great work with the amazing library!
I am trying to convert the underlying tensorflow model to tensorflowjs to be able to use the model on the browser. But I could not make the conversion work
I followed this github issue to create the necessary tensorflow files using the code:
def generate_checkpoint_from_model(model, checkpoint_name):
tf.saved_model.simple_save(model.sess, checkpoint_name, inputs={"obs": model.act_model.obs_ph}, outputs={"action": model.action_ph})
Then I try to transform the model using tensorflowjs_converter
tensorflowjs_converter --input_format=tf_saved_model test/ web_test
However, it gives me the following error:
Unable to lift tensor <tf.Tensor 'loss/action_ph:0' shape=(?,) dtype=int32> because it depends transitively on placeholder <tf.Operation 'loss/action_ph' type=Placeholder> via at least one path, e.g.: loss/action_ph (Placeholder)
I created the following colab notebook with the error so you can try it.
Does anyone knows how to make this conversion work?
Thank you for the help
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:16
Top Results From Across the Web
How to export a model for TensorFlow.js - Jim Fisher
This post shows how to save a “hello world” model in TensorFlow (Python), export it for TensorFlow.js, then run it in the browser....
Read more >Importing a Keras model into TensorFlow.js
Importing a Keras model into TensorFlow.js is a two-step process. First, convert an existing Keras model to TF.js Layers format, and then ...
Read more >How can I convert Tensorflow model to tensorflow.js model?
I can export it as a frozen graph, but Tensorflow.js does not support conversion of a frozen graph anymore. I tried using the...
Read more >Converting a TensorFlow Model to TensorFlow.js in Python
But it's not quite what we wanted, as it requires us to export our model to the SavedModel format first, and of course...
Read more >How To Deploy a Pre-Trained Question and Answer ...
TensorFlow.js is TensorFlow's JavaScript Library for training, executing, and deploying machine learning models in a web browser.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are trying to save the action placeholder used in PPO training (part of PPO agent), but for inference you only need the trained policy and its placeholders (
model.act_model
). The code on colab runs without errors by changing call tosimple_save
to this:The value of
_policy_proba
depends on the environment/algorithm.Thanks for offering the colab code, btw! It really made debugging this very easy 😃
@Miffyli I deployed this snake AI running on tensorflowjs after exporting it following the guidelines here. In the browser it is used only for inference and not for training as discussed previously. If someone wants a reference of it, here it is: https://www.pedro-torres.com/snake-rl/