首页 文章

使用Keras中的Lambda函数拆分LSTM输出

提问于
浏览
1

我正在使用带有张量流后端的Keras . 我在Keras使用功能层 . 我想要实现的是我在某个层面上有以下架构 .

张量为(20,200)----> LSTM ---->分为两个尺寸(20,100)的张量

然后使用这两个张量作为另一个网络的两个分支 . (我们可以认为这是合并操作的反面)

我了解到,实现这一目标的唯一方法是使用Lambda层,因为Keras中没有“Split”功能 .

然而,在查看Lambda函数的文档时,似乎output_shape功能仅在我们使用Keras时才相关 .

任何人都可以就如何实现这一点提出任何建议吗?这是我想要实现的粗略伪代码 .

#Other code before this 
lstm_1st_layer = LSTM(nos_hidden_neurons, return_sequences=True)(lstm_0th_layer)
#this layer outputs a tensor of size(20,200)
#Split it into two tensors of size (20,100) each (call them left and right)
left_lstm = LSTM(200, return_sequences=True)(left)
right_lstm = LSTM(200, return_sequences=True)(right)
#Other code after this

1 回答

  • 1

    在你的位置,我只需使用两个单位数量的LSTM层 .

    然后你准备好了两个输出:

    left = LSTM(half_nos_hidden_neurons,.....)(lstm_0th_layer)   
    right = LSTM(half_nos_hidden_neurons,.....)(lstm_0th_layer)
    

    效果是一样的 .

相关问题