clovaai / voxceleb_trainer

In defence of metric learning for speaker recognition
MIT License
1.05k stars 272 forks source link

Contrastive Confusion #9

Closed jlian2 closed 4 years ago

jlian2 commented 4 years ago
   ` ## loss functions
    if self.loss_func == 'contrastive':
        nloss       = torch.mean(torch.cat([torch.pow(pos_dist, 2),torch.pow(F.relu(self.margin - neg_dist), 2)],dim=0))
    elif self.loss_func == 'triplet':
        nloss   = torch.mean(F.relu(torch.pow(pos_dist, 2) - torch.pow(neg_dist, 2) + self.margin))

    scores = -1 * torch.cat([pos_dist,neg_dist],dim=0).detach().cpu().numpy()

    errors = tuneThresholdfromScore(scores, labelnp, []);

    return nloss, errors[1]

` Why there are three inputs for contrastive ?

joonson commented 4 years ago

The code deals with positive and negative pairs at once because of the batch formation, but does not compare positives to negatives unlike the triplet loss. Let me know if you see any problem with the implementation.