def content_loss(P, X, layer):
    """
    Defines the content loss contribution from two images at a specific layer. Reasoning: If the content of
    two images is the same the response of a given layer for each image should be the same.
    Note that additionally there is a 1 / image size factor which was not in the original paper
    """
    p = P[layer]
    x = X[layer]

    # slight change to cost function with respect to paper, which makes it independent of image size
    M = p.shape[2] * p.shape[3]
    loss = (1./(2*M)) * ((x - p)**2).sum()

    return loss