cvqluu / Angular-Penalty-Softmax-Losses-Pytorch

Angular penalty loss functions in Pytorch (ArcFace, SphereFace, Additive Margin, CosFace)
MIT License
482 stars 91 forks source link

Normalization will not work #3

Open zhangtemplar opened 4 years ago

zhangtemplar commented 4 years ago

I tested it and the normalization will not working:

       for W in self.fc.parameters():
            W = F.normalize(W, p=2, dim=1)
gregunz commented 4 years ago

This should fix it:

for _, module in self.fc.named_modules():
    if isinstance(module, nn.Linear):
        module.weight.data = F.normalize(module.weight, p=2, dim=1)
bnu-wangxun commented 3 years ago

This should fix it:

for _, module in self.fc.named_modules():
    if isinstance(module, nn.Linear):
        module.weight.data = F.normalize(module.weight, p=2, dim=1)

thanks

JisongXie commented 3 years ago

I find this problem, too. I modify it like this:

self.fc.weight.data = F.normalize(self.fc.weight.data, p=2, dim=1)
Charlyo commented 3 years ago

@cvqluu can you fix it in the code? thanks