为Keras中的RNN创建可变长度输出
我试图使用伪seq2seq类型模型将长度为N的序列转换为长度约为N^2的序列,但我不确定如何在我的keras模型中实现可变输入长度为Keras中的RNN创建可变长度输出,keras,keras-layer,Keras,Keras Layer,我试图使用伪seq2seq类型模型将长度为N的序列转换为长度约为N^2的序列,但我不确定如何在我的keras模型中实现可变输入长度 def LSTMModel(): input = Input(shape = (None,num_channels)) lstm_one = LSTM(75, return_sequences = True) lstm_one_output = lstm_one(input) BiLSTM = Bidirectional(LSTM(u
def LSTMModel():
input = Input(shape = (None,num_channels))
lstm_one = LSTM(75, return_sequences = True)
lstm_one_output = lstm_one(input)
BiLSTM = Bidirectional(LSTM(units = 100, return_sequences=True, recurrent_dropout = 0.1))
LSTM_outputs = BiLSTM(lstm_one_output)
output = LSTM(2, return_sequences = False)(LSTM_outputs)
return Model(input, output)
这段代码将产生一个(None,2)输出,但我真的希望它是一个(None,None^2)输出。是否有任何方法可以在模型中以某种方式存储形状,并使用keras层(可能使用lambda函数)对其执行某些操作?唯一的方法是修复时间步维度:
input=input(形状=(num_时间步,num_通道))
然后在最后一层的定义中使用num\u timesteps
:LSTM(num\u timesteps**2,…。