-
Notifications
You must be signed in to change notification settings - Fork 45
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
added circle loss #197
added circle loss #197
Conversation
for more information, see https://pre-commit.ci
✅ Deploy Preview for capable-unicorn-d5e336 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for capable-unicorn-d5e336 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, but it needs important fixes before merging. Please address them and try to optimize a small model with it to make sure that it correctly converges.
quaterion/loss/circle_loss.py
Outdated
|
||
def __init__( | ||
self, | ||
margin: Optional[float], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
margin
and scale_factor
are marked as Optional
but they don't have no default values. According the paper, section 4.1, default values are gamma = 256
and margin = 0.25
. Let's set those defaults and add a note to the docstring: "Refer to sections 4.1 and 4.5 in the paper for default values and evaluation of margin and scaling_factor hyperparameters."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quaterion/loss/circle_loss.py
Outdated
dists = self.distance_metric.distance_matrix(embeddings) | ||
# Calculate loss for all possible triplets first, then filter by group mask | ||
# Shape: (batch_size, batch_size, 1) | ||
sp = dists.unsqueeze(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't get the sp
and sn
matrices correctly. They should be similarity matrix of positives and similarity matrix of negatives. See this. Similarly, you can get the similarity matrix by calling self.distance_metric.similarity_matrix
and extract positive and negative pairs according to groups
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it in 3e99f94
added circle loss as additional loss function.