ValueError:Tensor("dense_1/Softmax:0", shape=(?, 3), dtype=float32) is not an element of this graph

      今天在写接口的时候再次出现了一个经典的老问题,如下所示:

ValueError: Tensor Tensor("dense_1/Softmax:0", shape=(?, 3), dtype=float32) is not an element of this graph.

      这里主要是想记录一下具体的解决方案,防止之后再次遇到的时候还需要去查资料,这里提供两种措施,如下:

1、每次预测完成之后,清空session之后,之后重新加载模型
keras.backend.clear_session()
model=loadModel(modelDir=modelDir)


2、构建全局graph
global graph
import tensorflow as tf
graph = tf.get_default_graph()
with graph.as_default():
        prediction=model.predict(image)


        记录一下,希望也能帮助需要的人。

发布了521 篇原创文章 · 获赞 490 · 访问量 323万+

猜你喜欢

转载自blog.csdn.net/Together_CZ/article/details/103993121
今日推荐