Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用flask+;uwsgi?_Python_Tensorflow_Flask_Uwsgi - Fatal编程技术网

Python 如何使用flask+;uwsgi?

Python 如何使用flask+;uwsgi?,python,tensorflow,flask,uwsgi,Python,Tensorflow,Flask,Uwsgi,我有一个经过训练的模型,我想用它来预测一些数据,并使用flask+uwsgi为其提供服务。一切正常,但当我点击服务器时,有时会抛出错误: File "api.py", line 150, in get_data im = sess.run(image_tf) `ValueError: Fetch argument <tf.Tensor 'DecodeJpeg_2:0' shape=(?, ?, 3) dtype=uint8> cannot be interpreted as a

我有一个经过训练的模型,我想用它来预测一些数据,并使用flask+uwsgi为其提供服务。一切正常,但当我点击服务器时,有时会抛出错误:

File "api.py", line 150, in get_data
   im = sess.run(image_tf)
`ValueError: Fetch argument <tf.Tensor 'DecodeJpeg_2:0' shape=(?, ?, 3) dtype=uint8> cannot be interpreted as a Tensor. 
      (Tensor Tensor("DecodeJpeg_2:0", shape=(?, ?, 3), dtype=uint8) 
       is not an element of this graph.)`
最后,我使用以下方法运行应用程序:

`uwsgi --http 0.0.0.0:8011 --wsgi-file api.py --master --processes 4 --threads 2 --callable app --lazy --lazy-apps`

有人能告诉我我做错了什么吗?

原因是uwsgi分叉进程来运行应用程序的多个“副本”

但是,您可以在该上下文之外实例化图形。您可以调用的是
app
,因此应该在其中实例化模型。 您可以使用
before\u first\u request
回调来加载模型

这篇博客文章可以方便地理解如何设置它:


相关烧瓶文档:

您好,您的问题解决了吗?我也有过类似的问题,对于Keras,我可以用Theano而不是Tensorflow来解决这个问题

我不得不将下面的代码添加到我的脚本中,并使用
KERAS\u BACKEND=theano python myprogram.py
在Linux操作系统上运行该程序

import theano
theano.config.optimizer=“无”

请参阅此帖子:

`uwsgi --http 0.0.0.0:8011 --wsgi-file api.py --master --processes 4 --threads 2 --callable app --lazy --lazy-apps`