首页 文章

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

提问于
浏览
0

我的问题很简单,但似乎没有解决 .

Input :(bs,timesteps,input_dim) - > Tensor("stack:0",shape =(?, 4 ,400),dtype = float32)

Layer :output = LSTM(100,input_shape =(timesteps,input_feature),return_sequence = True)(输入)

Expect :(bs,timesteps,output_dim) - > Tensor("gru_20/transpose_1:0",shape =(?, 4 ,100),dtype = float32)

Output :Tensor("gru_20/transpose_1:0",shape =(?, ? ,100),dtype = float32)

为什么Keras不会推断出时间步数,即使它收到一个input_shape?当我使用模型摘要时,它显示的结果具有正确的输出形状:


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

但不是在施工期间 . 因此,当我想通过使用unstack(输出,轴= 1)将Tensor拆分为每个时间步长*(bs,10)的Tensors列表时,我收到了这个错误:ValueError:无法从形状推断num(?, ?,100)

我的错误在哪里?

BTW . 添加TimeDistributed(Dense(100))(问题)会导致正确的输出变暗:Tensor("time_distributed_17/Reshape_1:0",shape =(?, 4 ,100),dtype = float32)但由于共享权重而不是选项 . 如果没有,解决方法是什么?

1 回答

  • 1

    解决方法可能是乘以1(无变化) .

    workaround = TimeDistributed(Lambda(lambda x:x * 1.0))(输出)

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

    使用return_sequences = True时,是否始终需要TimeDistributed Layer?

相关问题