title: Log Keras metrics for each batch as per Keras example for the loss
body: <p>In the Keras doc, there is an <a href="https://keras.io/guides/writing_your_own_callbacks/#a-basic-example" rel="nofollow noreferrer">example</a> where a custom callback is created to log the <strong>loss</strong> for each batch. This has worked fine for me, however I also want to log metrics that I add.</p>
  <p>For example for this code:</p>
  <pre><code>optimizer = Adam()
  loss = losses.categorical_crossentropy
  metric = [&quot;accuracy&quot;]
  
  model.compile(optimizer=optimizer,
                loss=loss,
                metrics=metric)
  
  
  class LossHistory(Callback):
      def on_train_begin(self, logs={}):
          self.losses = []
  
      def on_batch_end(self, batch, logs={}):
          self.losses.append(logs.get('loss'))
  
  loss_history = LossHistory()
  
  history = model.fit(training_data, training_labels,
                      batch_size=batch_size,
                      epochs=epochs,
                      verbose=2,
                      validation_data=(val_data, val_labels),
                      callbacks=[loss_history])
  </code></pre>
  <p>I can't figure out how to get access to the metrics.</p>