title: How to set keras custom metrics to only be called at the end of epoch?
body: <p>I am trying to use a custom metrics for my neural network and this metric should only be evaluated at the end of the epoch. The problem that I encounter is that the metrics is evaluated at each batch which is not the behaviour wanted. Note that I am working with generators and <code>fit_generator</code> with keras.</p>
  
  <p>validation_data are loaded with a generator that implements  <code>keras.utils.Sequence</code></p>
  
  <pre><code>class DataGenerator(keras.utils.Sequence): 
     def __init__(self, inputs, labels, batch_size):
      self.inputs = inputs
      self.labels = labels
      self.batch_size = batch_size
  
     def __getitem__(self, index):
      #some processing done here
      return batch_inputs, batch_labels
  
     def __len__(self):
      return int(np.floor(len(self.inputs) / self.batch_size))
  </code></pre>
  
  <p>I tried to implement what the keras documentation suggests but I did not find any info to specify the metric should only used at the end of epoch.</p>
  
  <pre><code>def auc_roc(y_true, y_pred):
     auc, up_opt = tf.metrics.auc(y_true, y_pred)
     K.get_session().run(tf.local_variables_initializer())
     with tf.control_dependencies([up_opt]):
         auc = tf.identity(auc)
     return auc
  </code></pre>
  
  <p>So right now the <code>auc_roc</code> is called after each batch instead of a single call at the end of the <code>epoch</code>.</p>