tensorflow / nmt

TensorFlow Neural Machine Translation Tutorial
Apache License 2.0
6.38k stars 1.96k forks source link

Explicit session gives fetch error #215

Closed humanely closed 6 years ago

humanely commented 6 years ago

Hi,

I have to keep persistent session for serving. 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 <tf.Operation 'init_all_tables' type=NoOp> cannot be interpreted as a Tensor. (Operation name: "init_all_tables" op: "NoOp" is not an element of this graph.)

lmthang commented 6 years ago

Hi Jolly, I guess you probably have found the answer. To make it work, you need to do:

 with infer_model.graph.as_default():
    loaded_infer_model = model_helper.load_model(
        infer_model.model, ckpt_path, sess, "infer")

-Thang