(stylized_inputs, total_variation_weight)
return weighted_loss, {
      'total_variation_loss': loss,
      'weighted_total_variation_loss': weighted_loss
  }
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.
Total variation regularization loss.
Total variation regularization loss .
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
  }
def total_variation_loss ( stylized_inputs , total_variation_weight ) : 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 }