将稳定基线 tensorflow 模型转换为 tensorflowjs

convert stable-baselines tensorflow model to tensorflowjs

我正在尝试将底层 tensorflow 模型从 stable-baselines to tensorflowjs 转换为能够在浏览器上使用该模型。但是我无法进行转换

我按照 this github issue 使用以下代码创建了必要的 tensorflow 文件:

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})

然后我尝试使用 tensorflowjs_converter

转换模型
tensorflowjs_converter --input_format=tf_saved_model test/ web_test

但是,它给我以下错误:

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)

我创建了以下 colab notebook 错误,所以你可以试试。

有谁知道如何进行此转换?

感谢您的帮助

我将问题发布为 issue in stable-baselines,他们回答了。我将复制在这里作为其他人的参考:

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.