需要帮助解密tensorflow feed InvalidArgumentError

时间:2018-05-09 14:07:44

标签: tensorflow

我认为我不理解tensorflow的这个Feed错误

Debug:  [[ 0.  0.]]
Debug: (1, 2)
Debug: float64

2018-05-09 09:56:34.615561: W tensorflow/core/kernels/queue_base.cc:295] _0_input_producer: Skipping cancelled enqueue attempt with queue not closed
Traceback (most recent call last):
  File "/home/kiran/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1323, in _do_call
    return fn(*args)
  File "/home/kiran/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1302, in _run_fn
    status, run_metadata)
  File "/home/kiran/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'seqModel/a_prev' with dtype double and shape [1,2]
         [[Node: seqModel/a_prev = Placeholder[dtype=DT_DOUBLE, shape=[1,2], _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

我为占位符提供的方式是:

self.a_prev = tf.placeholder(tf.float64, shape=[1,2], name='a_prev')

batch = tf.train.batch([self.x_acc, self.y_acc,
                        self.prev_pos], 
                        batch_size=1, capacity=20000, num_threads=1)

x_acc, y_acc, prev_pos = sess.run(batch)
test = np.array([[ x_acc[0,0], y_acc[0,0] ]])

print("Debug: ",test)
print("Debug:",test.shape)
print("Debug:",test.dtype)

_,X_hat_val,loss_val, X_val = sess.run([train,X_hat,loss, self.X],  
                                    feed_dict={self.a_prev : np.array([[x_acc[0,0],y_acc[0,0] ]]),
self.pos1 :  np.array([[ prev_pos[0,0] ]])
})

错误没有意义,因为我正在向占位符提供值,但它表示没有值。这是什么意思?

1 个答案:

答案 0 :(得分:1)

注意:我没有运行您的代码,因为它取决于不可用的数据。

但是,您可能会因重新分配self.a_prev属性行173而导致错误。使用此行时,self.a_prev不再指向tf.placeholder(..., name='a_prev'),而是指向不同的Tensor(来自self.new_evidence) - 因此实际的占位符不会在运行

此假设的玩具示例

import tensorflow as tf
import numpy as np

x_acc = np.random.rand(2, 2)
y_acc = np.random.rand(2, 2)

a_prev = tf.placeholder(tf.float64, shape=[1,2], name='a_prev')
some_results = tf.add(a_prev, 1.)

a_prev = tf.constant([[-1, -1]])
# ... now "a_prev" the python variable isn't pointing to the placeholder anymore,
# so "a_prev" the placeholder exists in the graph with no python pointer to it.

with tf.Session() as sess:
    res = sess.run(some_results, feed_dict={a_prev : np.array([[x_acc[0,0],y_acc[0,0] ]])})
    # "a_prev" the constant is assigned the values, not "a_prev" the placeholder, 
    # hence an error.
  

InvalidArgumentError(请参阅上面的回溯):您必须为占位符张量'a_prev'提供一个值,其中dtype为double,形状为[1,2]
  [[Node:a_prev = Placeholderdtype = DT_DOUBLE,shape = [1,2],   _device =“/ job:localhost / replica:0 / task:0 / device:GPU:0”]] [[Node:Add / _1 = _Recvclient_terminated = false,   recv_device = “/作业:本地主机/复制:0 /任务:0 /装置:CPU:0”,   send_device = “/作业:本地主机/复制:0 /任务:0 /设备:GPU:0”,   send_device_incarnation = 1,tensor_name =“edge_8_Add”,   tensor_type = DT_DOUBLE,   _device = “/作业:本地主机/复制:0 /任务:0 /装置:CPU:0”]]