标题: "Tensor %s is not an element of this graph." % obj) Tensor shape= [打印本页] 作者: 东方耀 时间: 2020-3-13 12:22 标题: "Tensor %s is not an element of this graph." % obj) Tensor shape= ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("activation_25/truediv:0", shape=(?, ?, 1, 84), dtype=float32) is not an element of this graph.
以上报错,是在keras模型部署到python的flask服务器 遇到 估计django也会出现
从提示看:不是图的一个元素 说明图已经变了
为了保持图的唯一的默认图:
# 定义一个全局的图变量
import tensorflow as tf
global graph
# 赋值
graph = tf.get_default_graph()
# 使用模型预测时 加上
with graph.as_default():
y_pred = 你的model.predict(X)