How to serve tensorflow model using flask+uwsgi?
The reason is that uwsgi forks processes to run multiple "copies" of your app.
However, you instantiate your graph outside of that context. Your callable is app
so the model should be instantiated in it.You can use the before_first_request
callback to load your model.
This blog post could be handy to understand how to set it up:https://networklore.com/start-task-with-flask/
Relevant flask documentation: http://flask.pocoo.org/docs/0.12/api/#flask.Flask.before_first_request
Hi have you solved your problem yet? I have had similar issues and with Keras I can fix the issue by using Theano instead of Tensorflow.
I had to add the code below to my script and use KERAS_BACKEND=theano python myprogram.py
to run the program on a Linux OS.
import theanotheano.config.optimizer="None"
See this stackoverflow post: