I have the following Keras LSTM model using functional API:
model = Sequential()
model.add(Lambda(lambda x: x,input_shape=(timestep,n_feature)))
output = model.output
output = LSTM(8)(output)
output = Dense(2)(output)
inputTensor = model.input
myModel = Model([inputTensor], output)
myModel.compile(loss='mean_squared_error', optimizer='adam')
myModel.fit([trainX], trainY, epochs=100, batch_size=1, verbose=2, validation_split = 0.1)
The model works fine but I think there are redundant syntax in my architecture. For example, the Lambda layer is only used to define the input_shape, maybe it can be removed? Can the above code be simplified/cleaned (I want to keep using functional API)? Thanks!
You can write your model using functional API as follows-
x=Input(shape=(timestep,n_feature))
model=LSTM(8)(x)
model=Dense(2)(model)
myModel=Model(x,model)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With