title: Create keras callback to save model predictions and targets for each batch during training
body: <p>
  I am building a simple Sequential model in Keras (tensorflow backend). During training I want to inspect the individual training batches and model predictions. Therefore, I am trying to create a custom <code>Callback</code> that saves the model predictions and targets for each training batch. However, the model is not using the current batch for prediction, but the entire training data.</p>
  
  <p>How can I hand over only the current training batch to the <code>Callback</code>?</p>
  
  <p>And how can I access the batches and targets that the <code>Callback</code> saves in self.predhis and self.targets?</p>
  
  <p>My current version looks as follows:</p>
  
  <pre class="lang-py prettyprint-override"><code>callback_list = [prediction_history((self.x_train, self.y_train))]
  
  self.model.fit(self.x_train, self.y_train, batch_size=self.batch_size, epochs=self.n_epochs, validation_data=(self.x_val, self.y_val), callbacks=callback_list)
  
  class prediction_history(keras.callbacks.Callback):
      def __init__(self, train_data):
          self.train_data = train_data
          self.predhis = []
          self.targets = []
  
      def on_batch_end(self, epoch, logs={}):
          x_train, y_train = self.train_data
          self.targets.append(y_train)
          prediction = self.model.predict(x_train)
          self.predhis.append(prediction)
          tf.logging.info("Prediction shape: {}".format(prediction.shape))
          tf.logging.info("Targets shape: {}".format(y_train.shape))
  </code></pre>