def gaussian_focal_loss(pred, target, alpha=2.0, gamma=4.0):
    """
    Focal Loss introduced in [1] for targets in gaussian distribution.

    Args:
        pred (:obj:`torch.Tensor`): The predictions.
        target (:obj:`torch.Tensor`): The learning targets in gaussian
            distribution.
        alpha (float, optional): Weighting factor in range ``(0, 1)`` to
            balance positive and negative examples. ``-1`` means no weighting.
            Default: ``2.0``.
        gamma (float, optional): Exponent of the modulating factor
            ``(1 - p_t)`` to balance easy and hard examples. Default: ``4.0``.

    Returns:
        :obj:`torch.Tensor`: The loss tensor.

    References:
        1. Law et al. (https://arxiv.org/abs/1808.01244)
    """
    eps = 1e-12

    pos_weights = target.eq(1)
    neg_weights = (1 - target).pow(gamma)

    pos_loss = -(pred + eps).log() * (1 - pred).pow(alpha) * pos_weights
    neg_loss = -(1 - pred + eps).log() * pred.pow(alpha) * neg_weights

    loss = pos_loss + neg_loss
    return loss