本地调用没有出现问题,但是用flask部署远程的服务,调用的时候会出现下面的错误:
ValueError(\"Tensor %s is not an element of this graph.\" % obj)
解决方案是在初始化前向的时候都加上with self.graph.as_default()这句代码。
Class A():
def __init__():
with self.graph.as_default():
self.Model = self.get_Model()
self.Model.load_weights(modelfile)
.
.
.
def predict():
with self.graph.as_default():
pre = self.Model.predict(img)