code: def total_variation_loss(stylized_inputs, total_variation_weight):
      """Total variation regularization loss.
  
      This loss improves the smoothness of the image by expressing high frequency
      variations as a loss.
      http://link.springer.com/article/10.1023/B:JMIV.0000011325.36760.1e
  
      Args:
        stylized_inputs: The batched set of images.
        total_variation_weight: Weight of total variation loss.
  
      Returns:
        Tensor for the total variation loss, dict mapping loss names to losses.
      """
      shape = tf.shape(stylized_inputs)
      batch_size = shape[0]
      height = shape[1]
      width = shape[2]
      channels = shape[3]
      y_size = tf.to_float((height - 1) * width * channels)
      x_size = tf.to_float(height * (width - 1) * channels)
      y_loss = (
          tf.nn.l2_loss(
              stylized_inputs[:, 1:, :, :]
              - stylized_inputs[:, :-1, :, :]
          )
          / y_size
      )
      x_loss = (
          tf.nn.l2_loss(
              stylized_inputs[:, :, 1:, :]
              - stylized_inputs[:, :, :-1, :]
          )
          / x_size
      )
      loss = (y_loss + x_loss) / tf.to_float(batch_size)
      weighted_loss = loss * total_variation_weight
      return weighted_loss, {
          "total_variation_loss": loss,
          "weighted_total_variation_loss": weighted_loss,
      }
  
file_path: magenta/magenta/models/image_stylization/learning.py
imports: from magenta.models.image_stylization import vgg
  import numpy
  import tensorflow.compat.v1
  import tf_slim
label_desc: Use image node_id 5 for calling a global function with example usage: total_variation_loss(stylized_inputs, total_variation_weight) and returns: weighted_loss,  dict