首页 > 解决方案 > Tensorflow sess.run InvalidArgumentError:您必须为占位符张量提供一个值

问题描述

我是 TensorFlow 的新手。我x = tf.placeholder(tf.float64, [in_len], name = "x")在张量模型中有这个占位符。我尝试使用以下注释来执行这个带有输入图像的张量模型img_20_tf

sess = tf.Session()
result_index = sess.run(model.eval(session=sess), feed_dict={x: img_20_tf})

我试图检查 shape 和 dtypeimg_20_tf并返回我(3072,)<dtype: 'float64'>. 但是,我仍然看到了这个错误:

Traceback (most recent call last):
  File "/Users/zhongyuyi/.conda/envs/Packaged program/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1356, in _do_call
    return fn(*args)
  File "/Users/zhongyuyi/.conda/envs/Packaged program/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1341, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/Users/zhongyuyi/.conda/envs/Packaged program/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1429, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'x' with dtype double and shape [3072]
     [[{{node x}}]]

我真的不明白数据类型和形状之间是如何不匹配的。有人可以帮忙吗?非常感谢!

标签: pythontensorflow

解决方案


推荐阅读