def reg_loss(regr, gt_regr, mask):
    """L1 regression loss

    Args:
        regr (torch.Tensor): tensor with HW regression predicted by model,
            should have shapes [batch, max_objects, dim]
        gt_regr (torch.Tensor): tensor with ground truth regression values,
            should have shapes [batch, max_objects, dim]
        mask (torch.Tensor): objects mask, should have shape [batch, max_objects]

    Returns:
        torch.Tensor with regression loss value
    """
    num = mask.float().sum()
    mask = mask.sum(1).unsqueeze(1).expand_as(gt_regr)

    regr = regr * mask
    gt_regr = gt_regr * mask

    regr_loss = F.smooth_l1_loss(regr, gt_regr, size_average=False)
    regr_loss = regr_loss / (num + 1e-4)
    return regr_loss
L1 regression loss

    Args:
        regr (torch.Tensor): tensor with HW regression predicted by model,
            should have shapes [batch, max_objects, dim]
        gt_regr (torch.Tensor): tensor with ground truth regression values,
            should have shapes [batch, max_objects, dim]
        mask (torch.Tensor): objects mask, should have shape [batch, max_objects]

    Returns:
        torch.Tensor with regression loss value
    
examples/detection/criterion.py