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.

[question] exporting model to tensorflowjs

See original GitHub issue

First 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:16

github_iconTop GitHub Comments

6reactions
Miffylicommented, Sep 15, 2019

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 to simple_save to this:

tf.saved_model.simple_save(model.sess, checkpoint_name, inputs={"obs": model.act_model.obs_ph},
                                   outputs={"action": model.act_model._policy_proba})

The value of _policy_proba depends on the environment/algorithm.

Thanks for offering the colab code, btw! It really made debugging this very easy 😃

5reactions
pedrohbtpcommented, Sep 18, 2019

@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/

Read more comments on GitHub >

github_iconTop 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 >

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