无需会话即可评估Tensor

时间:2019-07-11 15:28:08

标签: python tensorflow session tensor

我遇到以下问题:我需要组合的CNN-LSTM体系结构的中间输出,即CNN输出的编码图像。显然,不启动会话并初始化变量就无法获得张量值。但是,由于未初始化的值,在我的代码中启动tensorflow会话始终会产生错误。我做了很多实验,仅使用常规/交互式会话等初始化局部/全局变量。但是,似乎没有任何效果,代码会挂起或立即产生错误。有谁知道如何解决这个问题?

非常感谢!

更新:因此,当前使我无法运行成功会话的问题是

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'image_feed' with dtype string
     [[node image_feed (defined at /Documents/im2txt/bazel-bin/im2txt/run_inference.runfiles/im2txt/im2txt/show_and_tell_model.py:133) ]]

...

 File "/Documents/im2txt/bazel-bin/im2txt/run_inference.runfiles/im2txt/im2txt/show_and_tell_model.py", line 133, in build_inputs
    image_feed = tf.compat.v1.placeholder(dtype=tf.string, shape=[], name="image_feed")
  File "/anaconda3/envs/workenv_p2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2143, in placeholder
    return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
  File "/anaconda3/envs/workenv_p2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6262, in placeholder
    "Placeholder", dtype=dtype, shape=shape, name=name)
  File "/anaconda3/envs/workenv_p2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "/anaconda3/envs/workenv_p2/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/anaconda3/envs/workenv_p2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
    op_def=op_def)
  File "/anaconda3/envs/workenv_p2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2005, in __init__
    self._traceback = tf_stack.extract_stack()

但是,第133行明确指出了

 image_feed = tf.compat.v1.placeholder(dtype=tf.string, shape=[], name="image_feed")

0 个答案:

没有答案