转载自:https://blog.csdn.net/qq_39564555/article/details/95475871
报错内容如下:
tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable dense_1/bias from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/dense_1/bias/class tensorflow::Var does not exist
这是flask和tensorflow结合出现的错误,找了好几种解决办法下面这个最靠谱
解决方式:
from tensorflow.python.keras.backend import set_session
# 程序开始时声明
sess = tf.Session()
graph = tf.get_default_graph()
# 在model加载前添加set_session
set_session(sess)
model = models.load_model(…………)
# 每次使用有关TensorFlow的请求时
# in each request (i.e. in each thread):
global sess
global graph
with graph.as_default():
set_session(sess)
model.predict(...)