【发布时间】:2021-05-13 10:51:51
【问题描述】:
我是 tensorflow 的新手,我想知道为什么某些重要功能在最新版本中被弃用,特别是占位符和 get_variable。例如,我无法在 TF 2.0 中执行此操作:
# tf.placeholder()
X = tf.placeholder(tf.float32, shape=(2,2))
Y = tf.placeholder(tf.float32, shape=(2,2))
Z = X + Y
x, y = [[1,1], [1,1]], [[2,2], [2,2]]
with tf.Session() as sess:
sess.run(Z, feed_dict={X: x, Y: y})
# tf.get_variable()
W1 = tf.get_variable("W1", [4, 4, 3, 8], initializer = tf.contrib.layers.xavier_initializer(seed=0))
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
# etc ...
从我目前了解到的情况来看,这些似乎是非常重要的功能,所以我认为它们的功能已被 TF 2.0 中的其他功能取代,但我似乎无法弄清楚?我知道您可以改用 tf.compat.v1.placeholder,但我正在尝试弄清楚如何在 TF 2.0 中做到这一点。
【问题讨论】:
标签: python tensorflow