def mean_std(feature_space, eps=1e-5):
    """
    Calculates the mean and standard deviation for each channel

    Arguments:
        feature_space (torch.Tensor): Feature space of shape (N, C, H, W)
    """
    # eps is a small value added to the variance to avoid divide-by-zero.
    size = feature_space.size()
    assert (len(size) == 4), "Feature space shape is NOT structured as N, C, H, W!"
    N, C = size[:2]
    feat_var = feature_space.view(N, C, -1).var(dim=2) + eps
    feature_std = feat_var.sqrt().view(N, C, 1, 1)
    feature_mean = feature_space.view(N, C, -1).mean(dim=2).view(N, C, 1, 1)
    return feature_mean, feature_std