title: How can I write a custom metric only for the regularisation losses?
body: <p>Some layers have regularisation losses. I would like to have a "metric" that only keeps track of the regularisation losses, so that I can separately (from the total loss) see, in the progress bar, how the regularisation losses are evolving during training. Furthermore, given that metrics are saved in the history object (returned by <code>fit</code>), I could easily plot and save (to a file) the regularisation losses at the end of the training.</p>
  
  <p>How can I write a custom metric only for the regularisation losses?</p>
  
  <p>I know I can have a callback that iterates the layers of a model and sums the regularisation losses (see e.g. <a href="https://stackoverflow.com/a/48489090/3924118">https://stackoverflow.com/a/48489090/3924118</a>), but I would like to have a metric (rather than a callback) because the metric will be saved in the history object. </p>
  
  <p>Ultimately, I would like the regularisation losses to be present in the history object and displayed in the progress bar (separately from the total loss), even without implementing a custom metric, but I don't know if there's such an option in <code>tf.keras</code>. Also, it would be nice if I could have two options: 1. see the sum of all regularisation losses across all layers and 2. see the regularisation losses for each layer separately.</p>