I have a tensor flow model loaded in a tensor flow session. I need to execute this model on a webserver to attend web request. I'm using Flask framework.
Since model load and session creation takes some time, I want to reuse the created tensorflow session.
I tried to save it inside a session variable for each user, but tensorflow session is not serializable and it does not work.
Other thing I thought about is to create a separate socket to attend the request and keep the session opened in an infinite loop, but I would need to do some extra management to make mi ajax calls work on a different port than the port 80, I guess...
This is the code I use to create the session:
import tensorflow as tf
def createGraph():
with tf.gfile.FastGFile('graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
def createTfSession():
createGraph(appRootPath)
return tf.Session()
I would like to get a solution to make it work inside the web app, but if it's not possible any help to make an ajax call to a different port than 80 is also welcome
Thank you
Update: I tried the solution of the duplicated question, but it fails with a similar error saying that the tensor flow session is not serializable:
Unserializable message: ('#RETURN', tensorflow.python.client.session.Session object at 0x7fc9742f1050>)
`". Referencing the duplicated question reduces the risk of it being marked duplicate.