rabbityl/lepard

Why does the focal loss only consider positive entries in confidence matrix?

mlzxy opened this issue · 1 comments

mlzxy commented

The relevant code snippet is listed below. When the match type is dual softmax, only the positive labels are used. I wonder is there any specific reasons for this? I really appreciate your guidance.

if self.match_type == "dual_softmax":
    pos_conf = conf[pos_mask]
    loss_pos = - alpha * torch.pow(1 - pos_conf, gamma) * pos_conf.log()
    if weight is not None:
        loss_pos = loss_pos * weight[pos_mask]
    loss =  pos_w * loss_pos.mean()
    return loss

elif self.match_type == "sinkhorn":
    # no supervision on dustbin row & column.
    loss_pos = - alpha * torch.pow(1 - conf[pos_mask], gamma) * (conf[pos_mask]).log()
    loss_neg = - alpha * torch.pow(conf[neg_mask], gamma) * (1 - conf[neg_mask]).log()
    loss = pos_w * loss_pos.mean() + neg_w * loss_neg.mean()
    return loss

Thx!

mlzxy commented

Oh I realize the loss is applied on softmax, so this explains. Thx!