1

I have a multi-layer LSTM autoencoder with the following characteristics.

model = Sequential()
model.add(LSTM(250, dropout_U = 0.2, dropout_W = 0.2)) #L1
model.add(LSTM(150, dropout_U = 0.2, dropout_W = 0.2)) #L2
model.add(LSTM(100, dropout_U = 0.2, dropout_W = 0.2)) #L3
model.add(LSTM(150, dropout_U = 0.2, dropout_W = 0.2)) #L4
model.add(LSTM(250, dropout_U = 0.2, dropout_W = 0.2)) #L5
model.compile(optimizer='adam', loss='mse')

Simply in the test phase, I want to feed data in #L2 and get the output of #L4 then calculate the difference between the input and output of this representation layer.

How can I feed data in this middle layer? when I define input for #L2 layer Keras back error to me that the graph disconnected that it is reasonable.

1 Answers1

0

Thanks to @mahsa-monavari and @frogatto for your answers

from keras import backend as K

# with a Sequential model
get_3rd_layer_output = K.function([model.layers[0].input],
                                  [model.layers[3].output])
layer_output = get_3rd_layer_output([x])[0]