Tensorflow rnn_decoder用法:[0,0]错误消息

时间:2016-11-29 03:33:05

标签: python neural-network tensorflow

我是tensorflow的新手,我在张量流中使用 embedding_rnn_decoder 时遇到了一些问题 sample code

这是我的代码:

vocal_size = 407
embedding_size = 200

def decoder(input_,initial_state):
    lstm = tf.nn.rnn_cell.LSTMCell(decoder_state_num,num_proj=vocab_size)
    output,state=seq2seq.embedding_rnn_decoder(input_,initial_state,lstm,vocab_size,embedding_size,update_embedding_for_previous=True)
    return  output

decoder_input = [tf.placeholder(tf.int32, shape=[None])]
predict_result=decoder(decoder_input,encoder_output)

当我运行代码时:

sess = tf.Session()
sess.run(tf.initialize_all_variables())
sess.run(predict_result, feed_dict = {input: [input_one_hot[0]] , decoder_input[0]: label[0]})

input_one_hot:是一个6228大小的列表,其中包含1 * 24个np.array元素。我认为问题不在这里。 它是简单DNN的输入,其输出用作解码器的状态。我检查了形状,没有任何错误。

label[0]:是batch_size * 1 np.array的列表。

它将输出错误:

tensorflow/core/client/tensor_c_api.cc:485] Expected size[1] in [0, 0], but got 407

似乎它会自动将前一个解码器输出(形状(?,407))输入到下一个时间步的解码器输入中。但我没有把boolen feed_previous设置为True ......

我还在decoder_input中尝试了不同类型的label到feed_dict,但它无法正常工作。

我应该修改什么才能使代码生效?

非常感谢!

1 个答案:

答案 0 :(得分:0)

显然有些形状不匹配,但很难从你的代码片段中分辨出哪些形状。如果您发布了整个错误消息,将会更容易提供帮助。