Model accuracy with contrastive loss and triplet loss

Is there a way to calculate some sort of accuracy when I have to deal with loss functions which calculates distance beetwen pairs? Siamese networks outputs embedded representations of input data and then these are fed to the contrastive loss which calculates their dissimilarity. How can I say that these representations belongs to the same class according to the margin I choose? For triplet networks I think a possible metric to calculate accuracy would be to check if the distance between anchor and positive has to be less than the distance between anchor and negative for each input of my data. Here is an article which talks about these types of loss functions. Would you share your opinion about this? Thanks.

1 Like

I usually monitor the percentange of correct triplets in each batch. With that I mean the triplets where the distance between the anchor and the negative is bigger than the distance between the anchor and the positive by the margin.

Pytorch triplet loss does not provide tools to monitor that, but you can code it easily as I do in here.

I’m the author of the blog post you link Understanding Ranking Loss, Contrastive Loss, Margin Loss, Triplet Loss, Hinge Loss and all those confusing names