KERAS:使用return_sequence = True获取RNN时间步长的SLICE

时间:2018-10-05 16:44:34

标签: python tensorflow keras tensor

我的问题很简单,但似乎尚未解决。

输入 :( bs,时间步长,input_dim)->张量(“ stack:0”,shape =(?, 4 ,400),dtype = float32 )

: 输出= LSTM(100,input_shape =(时间步长,input_feature),return_sequence = True)(输入)

期望 :( bs,时间步长,output_dim)->张量(“ gru_20 / transpose_1:0”,shape =(?, 4 ,100),dtype = float32)

输出:张量(“ gru_20 / transpose_1:0”,shape =(?, ,100),dtype = float32)

即使Keras收到了input_shape,为什么Keras也不能推断出时间步长?当我使用模型摘要时,其显示的结果具有正确的输出形状:


lstm_2(LSTM)(无,4,100)3232

但是在施工过程中没有。因此,当我想通过使用unstack(output,axis = 1)在每个时间步长*(bs,10)上将张量堆叠成张量列表时,我会收到以下错误:ValueError:无法从形状(?,推论num? ?,100)

我的错误在哪里?

顺便说一句。添加TimeDistributed(Dense(100))(questions)会导致正确的输出暗淡:Tensor(“ time_distributed_17 / Reshape_1:0”,shape =(?, 4 ,100),dtype = float32)但由于共享权重而无法选择。如果没有,解决方法是什么?

1 个答案:

答案 0 :(得分:1)

解决方法可能是乘以1(不变)。

解决方法= TimeDistributed(Lambda(lambda x:x * 1.0))(输出)

推断在这里起作用:Tensor(“ time_distributed_17 / Reshape_1:0”,shape =(?, 4,100),dtype = float32)

使用return_sequences = True时是否始终需要时间分布层?

相关问题