我在这个问题上找不到任何东西 .
我试图在改变超级参数的同时反复训练网络,以便执行此视频中显示的内容:https://youtu.be/eBbEDRsCmv4?t=870(他通过重复运行具有不同超参数的网络来显示超参数搜索)
但是,我遇到一个错误,因为每次实例化占位符变量时,它们都会更改名称,从而导致错误
“InvalidArgumentError(参见上面的回溯):您必须为占位符张量'input / x-input'提供一个值,其中dtype为float和shape [?,784] [[Node:input / x-input = Placeholderdtype = DT_FLOAT,shape = [?,784],_ device =“/ job:localhost / replica:0 / task:0 / cpu:0”]]“
我将其追溯到“输入”占位符的重命名 . 当循环(如下面的代码所示)运行时,占位符首先命名为“input / x-input:0”,第二个命名为“input_1 / x-input:0” . 我相信我的错误是由此重命名引起的,但我不确定如何纠正它 .
以下代码是我可以编写的最小部分,它可以重现我的问题:
import tensorflow as tf
def train():
# Input placeholders
with tf.name_scope('input'):
x = tf.placeholder(tf.float32, [None, 784], name='x-input')
y_ = tf.placeholder(tf.float32, [None, 10], name='y-input')
return x
def main(_):
for i in range(2):
x = train()
print(x)
if __name__ == '__main__':
tf.app.run(main=main)
1 回答
通过添加以下行来解决此问题: