Я использую LSTM с Keras для прогнозирования набора последовательностей. Вот моя базовая модель:
inputs = Input(shape=(1,seq_dim)) #seq_dim = 2
# shape = (timesteps, featdim) = (1,2) since my input sequences are pair of values
# I want to predict the sequence of the fist values in the pairs
se = LSTM(lstm_size)(inputs)
out = Dense(1)(se) # I want to forecast one value
model = Model(inputs=inputs, outputs=out)
Я точно знаю, что последовательности начинаются с 0 и являются монотонными (не убывающими).
Я пробовал со слоем Maximum ()
max_out = Maximum()([output_seq,input_seq])
Здесь модель
inputs = Input(shape=(1,seq_dim))
# shape = (timesteps, featdim) = (1,2) since my input sequences are pair of values
# I want to predict the sequence of the fist values in the pairs
se = LSTM(lstm_size)(inputs)
out = Dense(1)(se) # I want to forecast one value
# max between the output and the previous value of the sequence (current input)
max_out = Maximum()([out,inputs[:,:,0]])
model = Model(inputs=inputs, outputs=max_out)
однако при компиляции модели возникает ошибка:
"AttributeError: 'Tensor' object has no attribute '_keras_history'"
Я также пытался использовать слой Lambda, но он вызывает ту же ошибку.
max_out = Lambda(lambda x: K_BACKEND.max(x))([out,inputs[:,:,0]])
Как я могу добавить это ограничение к моей модели? Можно ли это сделать в архитектуре Definitio (как я пытаюсь сделать), или отредактировав функцию потерь?
заранее спасибо