title: Is there a way to output a metric with several values in keras?
body: <p>I'm working on a U-net architecture to perform segmentation in 10 classes.  I want to calculate the Dice Coefficient for each class after each epoch. </p>
  
  <p>The output of my network is a stack of the segmentation masks for each class with shape <code>(b_size, rows, cols, num_classes)</code>. Over this output, I am computing the Dice Coefficient of each class in the following way:</p>
  
  <pre><code>def dice_metric(ground_truth, prediction):
      # initialize list with dice scores for each category
      dice_score_list = list()
      # get list of tensors with shape (rows, cols)
      ground_truth_unstacked = reshape_ground_truth(ground_truth)
      prediction_unstacked = tf.unstack(prediction, axis=-1)
      for (ground_truth_map, prediction_map) in zip(ground_truth_unstacked, prediction_unstacked):
          # calculate dice score for every class
          dice_i = dice_score(ground_truth_map, prediction_map)
          dice_score_list.append(dice_i)
      return tf.reduce_mean(dice_score_list, axis=[0])
  </code></pre>
  
  <p>Is there any way that I can print the list of dice scores instead of the mean. So in each epoch the output is:</p>
  
  <pre><code>Epoch 107/200
  - 13s - loss: 0.8896 - dice_metric: [dice_class_1, ... dice_class_10] - val_loss: 3.3417 - val_dice_metric: [val_dice_class_1, ... val_dice_class_10]
  </code></pre>
  
  <p>Keras documentation on <a href="https://keras.io/metrics/" rel="noreferrer">Custom Metrics</a> only considers single tensor values (i.e., <em>"Custom metrics can be passed at the compilation step. The function would need to take <code>(y_true, y_pred)</code>
  as arguments and return a <strong>single tensor value.</strong>"</em></p>
  
  <p>Is there any way/workaround to output a <strong>metric</strong> with more than one value?</p>