(end_points, stylized_end_points, content_weights)
return total_content_loss, content_loss_dict
Content loss.

  Args:
    end_points: dict mapping VGG16 layer names to their corresponding Tensor
        value for the original input.
    stylized_end_points: dict mapping VGG16 layer names to their corresponding
        Tensor value for the stylized input.
    content_weights: dict mapping layer names to their associated content loss
        weight. Keys that are missing from the dict won't have their content
        loss computed.

  Returns:
    Tensor for the total content loss, dict mapping loss names to losses.
Content loss.
Content loss .
def content_loss(end_points, stylized_end_points, content_weights):
  """Content loss.

  Args:
    end_points: dict mapping VGG16 layer names to their corresponding Tensor
        value for the original input.
    stylized_end_points: dict mapping VGG16 layer names to their corresponding
        Tensor value for the stylized input.
    content_weights: dict mapping layer names to their associated content loss
        weight. Keys that are missing from the dict won't have their content
        loss computed.

  Returns:
    Tensor for the total content loss, dict mapping loss names to losses.
  """
  total_content_loss = np.float32(0.0)
  content_loss_dict = {}

  for name in content_weights:
    # Reducing over all but the batch axis before multiplying with the content
    # weights allows to use multiple sets of content weights in a single batch.
    loss = tf.reduce_mean(
        (end_points[name] - stylized_end_points[name]) ** 2,
        [1, 2, 3])
    weighted_loss = tf.reduce_mean(content_weights[name] * loss)
    loss = tf.reduce_mean(loss)

    content_loss_dict['content_loss/' + name] = loss
    content_loss_dict['weighted_content_loss/' + name] = weighted_loss
    total_content_loss += weighted_loss

  content_loss_dict['total_content_loss'] = total_content_loss

  return total_content_loss, content_loss_dict
def content_loss ( end_points , stylized_end_points , content_weights ) : total_content_loss = np . float32 ( 0.0 ) content_loss_dict = { } for name in content_weights : # Reducing over all but the batch axis before multiplying with the content # weights allows to use multiple sets of content weights in a single batch. loss = tf . reduce_mean ( ( end_points [ name ] - stylized_end_points [ name ] ) ** 2 , [ 1 , 2 , 3 ] ) weighted_loss = tf . reduce_mean ( content_weights [ name ] * loss ) loss = tf . reduce_mean ( loss ) content_loss_dict [ 'content_loss/' + name ] = loss content_loss_dict [ 'weighted_content_loss/' + name ] = weighted_loss total_content_loss += weighted_loss content_loss_dict [ 'total_content_loss' ] = total_content_loss return total_content_loss , content_loss_dict