Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your loss Implementation might be wrong #2

Closed
NaiL23 opened this issue Dec 29, 2021 · 2 comments
Closed

Your loss Implementation might be wrong #2

NaiL23 opened this issue Dec 29, 2021 · 2 comments

Comments

@NaiL23
Copy link

NaiL23 commented Dec 29, 2021

You implement loss = self.alpha * (1-y) * distance**2 + \ self.beta * y * (torch.max(torch.zeros_like(distance), self.margin - distance)**2) as your contrastive loss, however, in your dataset split and preprocessing script, you label (genuine, genuine) as 1 and (genuine,forged) as 0, which means when y=0, your loss = alpha * distance between pairs and it will be minimized, but hopefully they should be as far as possible.

loss = self.alpha * y * distance**2 + \ self.beta * (1-y) * (torch.max(torch.zeros_like(distance), self.margin - distance)**2) would be a correct implementation.

@VinhLoiIT
Copy link
Owner

It makes sense. Actually, the (assumed) author implemented it here, but I don't remember why it is different in my code.

Thanks for pointing it out.

@VinhLoiIT
Copy link
Owner

As I read the paper, the loss function in the current source code is the same as the formulas (1) in the paper. However, the author said "y is a binary indicator function denoting whether the two samples belong to the same class or not" that it is quite ambiguous

@NaiL23 NaiL23 closed this as completed Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants