【发布时间】:2021-08-30 12:29:39
【问题描述】:
我有以下代码:
import tensorflow as tf
a = tf.constant(5)
b = tf.constant(2)
c = tf.constant(3)
d = tf.multiply(a,b)
e = tf.add(b,c)
f = tf.subtract(d,e)
with tf.Session() as sess: #changes should be made here since session is not supported in 2.0
fetches = [a,b,c,d,e,f]
outs = sess.run(fetches)
print("outs={}".format(outs))
由于 tensorflow 2.0 不再支持“会话”,我该如何修改它以使其符合 tensorflow 2.0 语法?
我不想使用 compat 函数,因为我想学习新的 tensorflow 2.0 会话替代语法。我阅读了文档,https://www.tensorflow.org/guide/effective_tf2,但在文档中提到使用函数时我很难理解它。
如何修改上面的会话代码,以便在 tensorflow 2.0 中获得相同的输出?
【问题讨论】:
标签: python tensorflow tensorflow2.0