问题描述
我有一些非常基本的带有tensorflow和python的lstm代码,其中我的代码是
I have some very basic lstm code with tensorflow and python, where my code is
output = tf.nn.rnn(tf.nn.rnn_cell.BasicLSTMCell(10), input_flattened, initial_state=tf.placeholder("float", [None, 20]))
我的输入变平的形状是[?, 5, 22501]
where my input flattened is shape [?, 5, 22501]
我在lstm的state
参数上收到错误TypeError: inputs must be a sequence
,并且我正在试图找出原因为什么会出现此错误.任何帮助将不胜感激.
I'm getting the error TypeError: inputs must be a sequence
on the state
parameter of the lstm, and I'm ripping my hair out trying to find out why it is giving me this error. Any help would be greatly appreciated.
推荐答案
我认为,当您使用tf.nn.rnn函数时,它期望的是张量列表,而不仅仅是一个张量.您应该在时间方向上解压缩输入,以便它是形状为[?,22501]的张量的列表.您也可以使用tf.nn.dynamic_rnn,我认为它可以为您解决此问题.
I think when you use the tf.nn.rnn function it is expecting a list of tensors and not just a single tensor. You should unpack input in the time direction so that it is a list of tensors of shape [?, 22501]. You could also use tf.nn.dynamic_rnn which I think can handle this unpack for you.
这篇关于输入不是带有RNN和TensorFlow的序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!