1
votes

This kind of tf.session works fine:

with tf.Session(graph=self.infer_model.graph, config=utils.get_config_proto()) as sess:
          loaded_infer_model = model_helper.load_model(self.infer_model.model, self.ckpt, sess, "infer")

But I have to keep persistent session for reuse. So instead of creating tf.session by "with" statement, I created a under:

sess = tf.Session(
            graph=infer_model.graph, config=utils.get_config_proto())
loaded_infer_model = model_helper.load_model(
              infer_model.model, ckpt, sess, "infer")

But this gives following error (in model_helper.load_model ): Can someone please suggest for how to load explicit session which can be reused?

File "/home/pksingh/sans/app/nmt/model_helper.py", line 444, in load_model session.run(tf.tables_initializer()) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 889, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1103, in _run self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 414, in init self._fetch_mapper = _FetchMapper.for_fetch(fetches) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 242, in for_fetch return _ElementFetchMapper(fetches, contraction_fn) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 278, in init 'Tensor. (%s)' % (fetch, str(e))) ValueError: Fetch argument cannot be interpreted as a Tensor. (Operation name: "init_all_tables" op: "NoOp" is not an element of this graph.)

1

1 Answers

1
votes

The best option to achieve the same is to use an interactive session. You can initialize an interactive session like this:

sess = tf.InteractiveSession()

Visit this link for more details.