运行Tensorflow时候发生以下错误:
tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable loss from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/loss)
[[node loss/Read/ReadVariableOp (defined at E:/PycharmProject/onlyfortest/example1.py:10) ]]
在使用Tensorflow时候,用tf.Variable创建函数后,要开始用Session去调用改该函数的时候,如果没有初始化Variable函数会发生错误,即上面的
例如:
add=tf.Variable(a+b) #创建一个求俩参数之和的函数
sess=tf.Session() #创建session
init = tf.compat.v1.global_variables_initializer() #创建初始化对象
sess.run(init) #先将variable函数初始化
sess.run(add) #这时候再调用函数