为什么即使对于相同的变量,tensorflow 占位符也会有一个计数器?
Why is there a counter on tensorflow placeholders even for same variables?
使用 iPython 控制台在 Tensorflow 1.8 中进行以下实验:
In [2]: x = tf.placeholder(tf.float16, [None, 784])
...: y = tf.placeholder(tf.float16, [None, 10])
...:
...:
In [3]: x
Out[3]: <tf.Tensor 'Placeholder:0' shape=(?, 784) dtype=float16>
In [4]: y
Out[4]: <tf.Tensor 'Placeholder_1:0' shape=(?, 10) dtype=float16>
In [5]: x = tf.placeholder(tf.float16, [None, 784])
...: y = tf.placeholder(tf.float16, [None, 10])
In [6]: x
Out[6]: <tf.Tensor 'Placeholder_2:0' shape=(?, 784) dtype=float16>
In [7]: y
Out[7]: <tf.Tensor 'Placeholder_3:0' shape=(?, 10) dtype=float16>
为什么这个 "placeholder counter" 存在,它的原因是什么?我用相同的占位符重新分配变量,所以我想知道为什么它们没有再次编号为 "Placeholder:0" 和 "Placeholder_1:0" ?
谢谢
每次 运行 x = tf.placeholder(tf.float16, [None, 784])
,操作都会添加到默认图表中。您可以通过以下方式查看:
for op in tf.get_default_graph().get_operations():
print (op.name)
#Placeholder
#Placeholder_1
#Placeholder_2
因此,在 ipython notebook
中,您可以在单元格前执行 tf.reset_default_graph()
以避免此行为。
使用 iPython 控制台在 Tensorflow 1.8 中进行以下实验:
In [2]: x = tf.placeholder(tf.float16, [None, 784])
...: y = tf.placeholder(tf.float16, [None, 10])
...:
...:
In [3]: x
Out[3]: <tf.Tensor 'Placeholder:0' shape=(?, 784) dtype=float16>
In [4]: y
Out[4]: <tf.Tensor 'Placeholder_1:0' shape=(?, 10) dtype=float16>
In [5]: x = tf.placeholder(tf.float16, [None, 784])
...: y = tf.placeholder(tf.float16, [None, 10])
In [6]: x
Out[6]: <tf.Tensor 'Placeholder_2:0' shape=(?, 784) dtype=float16>
In [7]: y
Out[7]: <tf.Tensor 'Placeholder_3:0' shape=(?, 10) dtype=float16>
为什么这个 "placeholder counter" 存在,它的原因是什么?我用相同的占位符重新分配变量,所以我想知道为什么它们没有再次编号为 "Placeholder:0" 和 "Placeholder_1:0" ?
谢谢
每次 运行 x = tf.placeholder(tf.float16, [None, 784])
,操作都会添加到默认图表中。您可以通过以下方式查看:
for op in tf.get_default_graph().get_operations():
print (op.name)
#Placeholder
#Placeholder_1
#Placeholder_2
因此,在 ipython notebook
中,您可以在单元格前执行 tf.reset_default_graph()
以避免此行为。