问题描述
事先训练好一个keras的神经网络model。在某一个网站项目flask中,启动服务的时候会把这个model加载进来,当用户访问某一个页面A的时候,会调用model的预测函数。
raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("dense_3/Sigmoid:0", shape=(?, 59), dtype=float32) is not an element of this graph.
网上有人说是线程的问题,链接:https://blog.youkuaiyun.com/leon_wzm/article/details/78434432
然而该方法并不能解决问题
解决方法
错误原因:
When you create a Model, the session hasn’t been restored yet. All placeholders, variables and ops that are defined in Model.init are placed in a new graph, which makes itself a default graph inside with block. This is the key line:
因此 解决方案:
附上解决的链接
https://github.com/tensorflow/tensorflow/issues/14356