简体   繁体   English

将 Tensorflow 1.x 代码重写为 tensorflow 2.x

[英]Rewriting Tensorflow 1.x code to tensorflow 2.x

I am dealing with a task where I have to create a code using TensorFlow-version2.我正在处理一项任务,我必须使用 TensorFlow-version2 创建代码。 I have an existing code of the same thing but in TensorFlow version 1.我有一个相同的现有代码,但在 TensorFlow 版本 1 中。

with tf.variable_scope(name):
        self.obs = tf.placeholder(dtype=tf.float32, shape=[None] + list(ob_space.shape), name='obs')

        with tf.variable_scope('policy_net'):
            layer_1 = tf.layers.dense(inputs=self.obs, units=20, activation=tf.tanh)
            layer_2 = tf.layers.dense(inputs=layer_1, units=20, activation=tf.tanh)
            layer_3 = tf.layers.dense(inputs=layer_2, units=act_space.n, activation=tf.tanh)
            self.act_probs = tf.layers.dense(inputs=layer_3, units=act_space.n, activation=tf.nn.softmax)

I have worked on tf2 directly but I am facing challenges in understanding the given excerpt.我直接在 tf2 上工作,但我在理解给定的摘录方面面临挑战。 Please help me understand it.请帮助我理解它。 Also, how can rewrite this code suitable for tf2.另外,如何重写适合tf2的代码。 kindly suggest or provide me with a doc to do so.请建议或向我提供这样做的文档。

For this, I will be really thankful to you.为此,我会非常感谢你。

Two ways to migrate your TensorFlow 1 code to TensorFlow 2:将 TensorFlow 1 代码迁移到 TensorFlow 2 的两种方法:

  1. Manually migrate low level TensorFlow APIs手动迁移低级 TensorFlow API
  2. Automatically upgrade code to TensorFlow 2自动升级代码到 TensorFlow 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM