How to keep tensorflow session open between predictions? Loading from SavedModel

后端 未结 3 736
庸人自扰
庸人自扰 2021-02-05 18:00

I trained a tensorflow model that i\'d like to run predictions on from numpy arrays. This is for image processing within videos. I will pass the images to the model as they happ

3条回答
  •  一整个雨季
    2021-02-05 18:23

    Your code creates a scope which is exited after it leaves init.

    def __init__(self): 
      with tf.Session(graph=tf.Graph()) as self.sess:
        tf.saved_model.loader.load(self.sess[tf.saved_model.tag_constants.SERVING], "model")
    

    The following should work for you if you have everything else working properly.

    def __init__(self):   
      self.sess=tf.Session(graph=tf.Graph())
      tf.saved_model.loader.load(self.sess[tf.saved_model.tag_constants.SERVING], "model")
    

    When I do something like this I also usually create the option of passing the session to the class by a parameter, then when I call the class I pass in a session create by with

提交回复
热议问题