解决django+keras ValueError: Tensor Tensor(“conv2d_18/Relu:0”, shape=(?, 512, 512, 3), dtype=float32) is not an element of this graph.
报错信息
ValueError: Tensor Tensor("conv2d_18/Relu:0", shape=(?, 512, 512, 3), dtype=float32) is not an element of this graph.
排查问题
# 库版本
tensorflow==1.15
keras==2.3.1
# 尝试
在你create/load model 的地方之后加上代码:
self.graph = tf.get_default_graph()
在你使用model之前加上
with self.graph.as_default():
(... do inference here ...)
# 继续报错
tensorflow.python.framework.errors_impl.FailedPreconditionError: 。。。from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exis
# 之后换了一种思路,如下