我正在尝试使用 MTCNN in tensorflow 部署人脸检测服务+ flask + uWSGI。我的部署基于 this docker并添加了这个自定义 uwsgi.ini
:
[uwsgi]
module = main
callable = app
enable-threads = true
cheaper = 2
processes = 16
threads = 16
http-timeout = 60
但是当我尝试使用我刚刚构建的这个 docker 镜像进行人脸检测时,我总是遇到 504 Gateway Time-out
。实际上,当我深入挖掘时,我注意到代码运行良好 this session.run line :
for op_name in data_dict:
with tf.variable_scope(op_name, reuse=True):
for param_name, data in iteritems(data_dict[op_name]):
try:
var = tf.get_variable(param_name)
session.run(var.assign(data))
except ValueError:
if not ignore_missing:
raise
一开始我以为是uwsgi worker下的threading相关的问题,所以我增加了进程数和线程数,但是没有成功。
当我使用 flask 调试器运行相同的代码时,它运行得很好,并在不到一秒的时间内处理了图像。所以这不是代码的问题,而是配置或这些工具组合的问题。
最佳答案
您还需要设置cheaper = 0
。
这是我的 uwsgi,它正在工作。
[uwsgi]
module = main
callable = app
master = false
processes = 1
cheaper = 0
关于python - 无法在 uwsgi + nginx 部署下使用 tensorflow 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52522755/