keras在flask跑出现的问题
alueError: Tensor Tensor("dense_3/Sigmoid:0", shape=(?, 59), dtype=float32) is not an element of this graph.
原始代码
X = img.reshape([1, 32, width, 1])
y_pred = basemodel.predict(X)
y_pred = y_pred[:, :, :]
解决方法:
在上面代码所在的py文件前面插入
import tensorflow as tf
global graph,model
graph = tf.get_default_graph()
然在把刚刚的代码改为
X = img.reshape([1, 32, width, 1])
with graph.as_default():
y_pred = basemodel.predict(X)
y_pred = y_pred[:, :, :]