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

Added CosFace Loss #198

Closed
wants to merge 0 commits into from
Closed

Added CosFace Loss #198

wants to merge 0 commits into from

Conversation

crsdvaibhav
Copy link
Contributor

@monatis This is still work in progress. Just wanted to ask few questions, by sharing the code.

  • Is the implementation of the Multi Objective Loss according to your demands? If it is not, can you give a few pointers in the correct direction, and also about the tests?
  • CosFace Loss is correct according to me, as its only difference from Arcface Loss is the subtracting of margin from the cosines instead of angles. Could you give a pointer regarding writing the tests for the Cosface and Arcface losses?

Thankyou for the help!

@netlify
Copy link

netlify bot commented Mar 25, 2023

Deploy Preview for capable-unicorn-d5e336 ready!

Name Link
🔨 Latest commit 1745697
🔍 Latest deploy log https://app.netlify.com/sites/capable-unicorn-d5e336/deploys/6424007dd3369c0008fc7c7a
😎 Deploy Preview https://deploy-preview-198--capable-unicorn-d5e336.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Comment on lines 11 to 21
def l2_norm(inputs: torch.Tensor, dim: int = 0) -> torch.Tensor:
"""Apply L2 normalization to tensor
Args:
inputs: Input tensor.
dim: Dimension to operate on.
Returns:
torch.Tensor: L2-normalized tensor
"""
outputs = inputs / torch.norm(inputs, 2, dim, True)

return outputs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @crsdvaibhav, there is already a l2_norm function implemented for arcface_loss. If you are going to use l2_norm for cos_face_loss as well, then maybe it would be better to take l2_norm function to loss/utils/utils.py and call it from there in order to avoid code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same, just needed a heads-up!



class MultiObjectiveLoss(torch.nn.Module):
def __init__(self, losses: list, weights: Optional[list] = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, in order to improve expressivity, that would be better to include data type stored in the list such as weights: Optional[List[Tensor]].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do so. Thanks!

@crsdvaibhav
Copy link
Contributor Author

@KarahanS I have made the changes. Does this need some more changes before merge?

@KarahanS
Copy link
Contributor

@KarahanS I have made the changes. Does this need some more changes before merge?

Thanks for the updates! I'm not one of the official contributors of this project, so let's wait for the reviews by the maintainers for merging :)

@crsdvaibhav crsdvaibhav changed the title [Work in Progress] CosFace Loss and Multi Objective Loss Added CosFace Loss and Multi Objective Loss Mar 27, 2023
@crsdvaibhav
Copy link
Contributor Author

@monatis I have added the CosFace Loss and its test. Could you please review it? I have also added an implementation of Multi Objective Loss, could you please review it?

Copy link
Contributor

@monatis monatis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • CosFace LGTM, but let's remove MultiObjectiveLoss.
  • Fix conflicts.

@@ -0,0 +1,22 @@
from typing import Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but it has some issues:

  • Not well documented with docstrings.
  • Argument groups is missing in the forward() method.
  • Tests are missing.

After fixing these issue it might be a good start, but I'm thinking of something slightly different that will make GroupLoss and PairLoss compatible with one another through some utility functions. For example, I got slightly better results when I combined Triplet Loss and Multiple Negatives Ranking Loss, but it will require more experiments.

tl; dr: Let's remove MultiObjectiveLoss from this PR for now --it will be something more ambitious and definitely is worth its own PR 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I will update the PR with the CosFace Loss only.

As for the issues with the Multi Objective Loss, I will surely solve them and put a new PR, and we can experiment with it there.

Thankyou!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the required changes:

  • Removed the Multi Objective Loss
  • Resolved the conflicts

@crsdvaibhav crsdvaibhav changed the title Added CosFace Loss and Multi Objective Loss Added CosFace Loss Mar 28, 2023
@monatis monatis closed this Mar 29, 2023
@monatis
Copy link
Contributor

monatis commented Mar 29, 2023

I needed to close this. Could you please make another PR by rebasing from master and insuring that all the tests pass --because it didn't.

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

Successfully merging this pull request may close these issues.

None yet

3 participants