Python 多线程Flask应用程序使用MRCNN引发错误
我有一个flask应用程序正在线程真实模式下运行Python 多线程Flask应用程序使用MRCNN引发错误,python,multithreading,tensorflow,flask,Python,Multithreading,Tensorflow,Flask,我有一个flask应用程序正在线程真实模式下运行 if __name__ == '__main__': setup.check_director() web_app.secret = "image-service" web_app.run(host='0.0.0.0', port=8084, debug=True, threaded=True) 我正在使用api调用触发mrcnn()任务,Predictor类如下所示 class Predictor(object):
if __name__ == '__main__':
setup.check_director()
web_app.secret = "image-service"
web_app.run(host='0.0.0.0', port=8084, debug=True, threaded=True)
我正在使用api调用触发mrcnn()任务,Predictor类如下所示
class Predictor(object):
def __init__(self, config=None, weights=WEIGHTS_PATH, device=DEVICE):
self.weights=weights
self.config = ElementConfig() if config is None else config
# self.el = Element_linker()
self.logger.info("Loading Mask R-CNN model")
print("Loading Mask R-CNN model and weights")
start = time.time()
self._graph = tf.Graph()
with self._graph.as_default():
self.model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=self.config)
self.logger.info("Loading saved weights from {}".format(weights))
self.model.load_weights(weights, by_name=True)
self.init_g = tf.global_variables_initializer()
self.init_l = tf.local_variables_initializer()
print("Loading completed in %s seconds" % ((time.time() - start)))
....
....
....
def predict(self):
with tf.Session(graph=self._graph) as _session:
_session.run(self.init_g)
_session.run(self.init_l)
results = _session.run(self.model.detect([image], verbose=0))
....
....
....
....
当一次只有一个api调用时,代码工作正常。当我同时命中多个api时,代码抛出错误,如下所示:
ValueError: Tensor Tensor("Placeholder:0", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph.
详细日志:
我还尝试使用不同的方式组织会话和图表。我们也尝试了mrcnn github问题页面上的所有解决方案,但没有任何帮助
线程或上述方法是否存在问题?