Modified arcface loss to keep cost function monotonically decreasing #539
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As mentioned in section 2.8 of the old arcface paper under target logit analysis, we can see that whenever the angle between feature vector and target center is too large, the cost function behaviour can change and it wouldn't be monotonically decreasing.
Specifically, when the angle between the feature vector and target center is more obtuse than (180 - margin), the cos function can start to increase.
For instance, consider that my margin is 30 degrees.
If the normed feature vector makes an angle of 130 degrees with the target center, then the
logit = cos(130 + 30) = cos(160) = -0.93
.Now consider the normed feature vector makes an angle of 170 degrees with the target center, then the
logit = cos(170 + 30) = cos(200) = -0.93
.This doesn't help in our training as we want to penalize highly obtuse angle even more. Hence we make the following change in our loss function as mentioned here to keep this function monotonically decreasing.
Thanks,
Vinayak.