解包(取消堆叠)张量流中具有一个 None 维度的输入(占位符)



我正在尝试将 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 时,我遇到了以下错误:

值错误: 无法从形状推断数字 (?, 1, 65536)

另外,这里和这里有一些讨论,但没有一个对我有用。任何帮助,不胜感激。

如本文所述,如果参数未指定且不可推断,则tf.unstack不起作用。

在您的代码中,换位后,x1的形状为[ n_steps, batch_size, n_input],其在axis=0处的值设置为None

最新更新