0

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>)

dhalfageme
  • 1,444
  • 4
  • 21
  • 42
  • I tried the solution of the duplicated cuestion, 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>) – dhalfageme Apr 18 '18 at 13:07
  • 1
    I'd open a new question otherwise this will become a chameleon (changing the question over time). Structure your question as "I'm trying to do ``. I've tried ``, but I'm getting error ``. My code is ``". Referencing the duplicated question reduces the risk of it being marked duplicate. – Philip Couling Apr 18 '18 at 15:52
  • 2
    I finally end up with a separate socket server on a different port that parses HTPP request and reuses the same tensorflow session every time. SInce AJAX calls can't be done to a different port than the original webserver port, I needed also to configure a reverse proxy in apache to make the pieces work together. Hope this solution helps someone (I won't create a new question this time, thanks) – dhalfageme Apr 18 '18 at 17:14

0 Answers0