一、问题描述
在用tensorflow2.0版本时,用
with tf.compat.v1.Session() as sess:
pre=sess.run(prediction,feed_dict={x:x_test[0:2],keep_prob:1})
print(pre)
出现错误如下
FailedPreconditionError: Error while reading resource variable Variable_16 from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/Variable_16)
[[{{node Conv2D_4/ReadVariableOp}}]]
解决方案是没有对变量初始化,改正如下
with tf.compat.v1.Session() as sess:
sess.run(tf.compat.v1.global_variables_initializer())
pre=sess.run(prediction,feed_dict={x:x_test[0:2],keep_prob:1})
print(pre)