TensorLow: FailedPreconditionError:Attempting to use uninitialized value Variable

来源:互联网 发布:linux 安装 jdk 编辑:程序博客网 时间:2024/06/05 03:37

问题:

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value Variable[[Node: Variable/read = Identity[T=DT_FLOAT, _class=["loc:@Variable"], _device="/job:localhost/replica:0/task:0/cpu:0"](Variable)]]

出处:

constant_e = tf.Variable(tf.random_normal(shape=[2, 3],stddev=2, dtype=tf.float32))sess.run(constant_e)

原因:
Tensorflow中,所有变量都必须初始化才能使用。

方法:

init = tf.global_variables_initializer()sess.run(init)

结果:

constant_e = tf.Variable(tf.random_normal(shape=[2, 3], stddev=2, dtype=tf.float32))init = tf.global_variables_initializer()sess.run(init)print(sess.run(constant_e ))
阅读全文
0 0
原创粉丝点击