title: Get output from last layer in each epoch in LSTM, Keras
body: <p>We are already aware that output of each layer can be obtained from following code: </p>
  
  <pre><code>def get_layer(model,x):
      from keras import backend as K
  
      get_3rd_layer_output = K.function([model.layers[0].input],
                                        [model.layers[2].output])
      layer_output = get_3rd_layer_output([x])[0]
      print(layer_output.shape)
      return layer_output
  </code></pre>
  
  <p>LSTM model is fit as:</p>
  
  <pre><code>history = model.fit(X_train, y_train, batch_size=batch_size,verbose=1, nb_epoch=10,validation_data=(X_test,y_test))
  </code></pre>
  
  <p>But how to obtain output of the last layer in the model for each epoch out of 10 epochs?</p>