我正在尝试使用具有不同时间步长(不同帧数)的输入的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:无法从形状推断num(?,1,65536)
答案 0 :(得分:0)
As explained in here, tf.unstack
does not work if the argument is unspecified and non-inferrable.
In your code, after transpositions, x1
has the shape of [ n_steps, batch_size, n_input]
and its value at axis=0
is set to None
.