我正在尝试使用具有不同时间步长(不同帧数)的输入的LSTM. rnn.static_rnn的输入应该是tf(不是tf!)的序列.所以,我应该将输入转换为序列.我试图使用tf.unstack和tf.split,但是他们都需要知道输入的确切大小,而我的输入的一个维度(时间步长)正在通过不同的输入改变.以下是我的代码的一部分:
n_input = 256*256 # data input (img shape: 256*256)
n_steps = None # timesteps
batch_size = 1
# tf Graph input
x = tf.placeholder("float", [ batch_size , n_input,n_steps])
y = tf.placeholder("float", [batch_size, n_classes])
# Permuting batch_size and n_steps
x1 = tf.transpose(x, [2, 1, 0])
x1 = tf.transpose(x1, [0, 2, 1])
x3=tf.unstack(x1,axis=0)
#or x3 = tf.split(x2, ?, 0)
# Define a lstm cell with tensorflow
lstm_cell = rnn.BasicLSTMCell(num_units=n_hidden, forget_bias=1.0)
# Get lstm cell output
outputs, states = rnn.static_rnn(lstm_cell, x3, dtype=tf.float32,sequence_length=None)
当我使用tf.unstack时出现以下错误:
ValueError: Cannot infer num from shape (?, 1, 65536)
此外,还有一些讨论here和here,但没有一个对我有用.任何帮助表示赞赏.
如
here中所述,如果参数未指定且不可推断,则tf.unstack不起作用.
在代码中,在转置之后,x1的形状为[n_steps,batch_size,n_input],其在axis = 0处的值设置为None.