title: Keras - Save output of intermediate layer
body: <p><strong>What I have done?</strong></p>
  
  <p>I'm using from this code to implement my keras'model:</p>
  
  <pre><code>X, tx, Y, ty = train_test_split(X, Y, test_size=0.2, random_state=np.random.seed(7), shuffle=True)
  
  X = np.reshape(X, (X.shape[0], 1, X.shape[1]))
  tx = np.reshape(tx, (tx.shape[0], 1, tx.shape[1]))
  
  model = Sequential()
  model.add(LSTM(100, return_sequences=False, input_shape=(X.shape[1], X.shape[2])))
  model.add(Dense(Y.shape[1], activation='softmax'))
  model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
  filepath="weights-{epoch:02d}-{val_acc:.2f}.hdf5"
  checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
  callbacks_list = [checkpoint]
  
  model.fit(X, Y, validation_split=.20,
                      epochs=1000, batch_size=50, callbacks=callbacks_list, verbose=0) 
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <p>Below is a part of the program's output:</p>
  
  <pre><code>Epoch 00993: val_acc did not improve
  Epoch 00994: val_acc did not improve
  Epoch 00995: val_acc did not improve
  Epoch 00996: val_acc did not improve
  Epoch 00997: val_acc did not improve
  Epoch 00998: val_acc improved from 0.93900 to 0.94543, saving model to weights-998-0.94.hdf5
  Epoch 00999: val_acc did not improve
  </code></pre>
  
  <p><strong>PROBLEM:</strong> </p>
  
  <p>I need to save the output of LSTM layer in any epoch but i do not know how?</p>
  
  <p>Any idea?</p>