Tensorflowfully_connected 在单元测试用例中不起作用? [英] Tensorflow fully_connected not working in unit test cases?
本文介绍了Tensorflowfully_connected 在单元测试用例中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一定错过了一些基本的东西.这是我的测试用例 -
I must missed something basic. Here is my test case -
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())
我不明白为什么我总是收到如下错误.
I do not understand why I kept getting error like below.
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)]]
推荐答案
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 did tf.global_variables_initializer() 在引擎盖?了解更多见解.
Swapping the position of init_op
will make it work. Refer to What does tf.global_variables_initializer() do under the hood? for more insights.
这篇关于Tensorflowfully_connected 在单元测试用例中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文