我必须错过一些基本的东西。这是我的测试用例 -
def test_silly(self):
with self.test_session() as sess:
init_op = tf.global_variables_initializer()
out = tf.contrib.layers.fully_connected(
inputs=tf.zeros([self.batch_size, 10]),
num_outputs=20,
activation_fn=None,
scope="hmmm")
sess.run(init_op)
print(out.eval())
我不明白为什么我一直得到如下错误。
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value hmmm/weights
[[Node: hmmm/weights/read = Identity[T=DT_FLOAT, _class=["loc:@hmmm/weights"], _device="/job:localhost/replica:0/task:0/cpu:0"](hmmm/weights)]]
答案 0 :(得分:0)
hmmm/weights
未初始化。
def test_silly(self):
with self.test_session() as sess:
out = tf.contrib.layers.fully_connected(
inputs=tf.zeros([self.batch_size, 10]),
num_outputs=20,
activation_fn=None,
scope="hmmm")
init_op = tf.global_variables_initializer()
sess.run(init_op)
print(out.eval())
交换init_op
的位置会使其有效。有关更多见解,请参阅What does tf.global_variables_initializer() do under the hood?。