这种 tf.session 工作正常:
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")
但我必须保持持久会话以供重用。因此,我没有通过“with”语句创建 tf.session,而是创建了一个 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")
但这会产生以下错误(在 model_helper.load_model 中):有人可以建议如何加载可以重用的显式会话吗?
文件“/home/pksingh/sans/app/nmt/model_helper.py”,第 444 行,在 load_model session.run(tf.tables_initializer()) 文件“/usr/local/lib/python2.7/dist-packages/ tensorflow/python/client/session.py”,第 889 行,运行中 run_metadata_ptr) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”,第 1103 行,在_run self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”,第 414 行,在 init self._fetch_mapper = _FetchMapper.for_fetch(fetches) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”,第 242 行,for_fetch 返回 _ElementFetchMapper(fetches,contraction_fn) 文件“/usr /local/lib/python2.7/dist-packages/tensorflow/python/client/session.py",第 278 行,在 init 'Tensor. (%s)' % (fetch, str(e))) 中 ValueError:Fetch 参数不能被解释为张量. (操作名称:“init_all_tables” op:“NoOp”不是该图的元素。)