您必须使用dtype float和shape为占位符张量“占位符”提供值

时间:2018-01-23 14:30:17

标签: python tensorflow

这是我的代码。

def zero_state(hidden_num, height, width):
    state0 = tf.placeholder(tf.float32,[None,height,width,hidden_num],name='state0_zeros')
    state = state0
    with tf.Session() as sess:     
         state_zeros = np.zeros([height, width, hidden_num],dtype=np.float32)
         sess.run(state,feed_dict={state:[state_zeros]}) #updated
         return [state0,state0]

并在tensorflow中引发此错误。

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'generator_newFrame/state0_zeros' with dtype float and shape [?,64,64,16]
     [[Node: generator_newFrame/state0_zeros = Placeholder[dtype=DT_FLOAT, shape=[?,64,64,16], _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]
     [[Node: generator_newFrame/Tanh/_3 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_620_generator_newFrame/Tanh", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您正在提供state而不是state0

def zero_state(hidden_num, height, width):
    state0 = tf.placeholder(tf.float32,[None,height,width,hidden_num],name='state0_zeros')
    state = state0
    with tf.Session() as sess:     
         state_zeros = np.zeros([height, width, hidden_num],dtype=np.float32)
         sess.run(state,feed_dict={state0:[state_zeros]}) #updated
         return [state0,state0]