Closed Youskrpig closed 3 years ago
I think there were two losses in the paper right? The authors did use the angular loss in the next line in the code. I might be missing something though.
I misunderstood. Actually it is the angular loss.
Hi, I see the angular center loss is expressed as follow: I'm confused why it is expressed as such math formual? and i see the corresponding code is: out_1 = model(img1) out_2 = model(img2) out_1 = out_1 - center out_2 = out_2 - center center_loss = ((out_1 2).sum(dim=1).mean() + (out_2 2).sum(dim=1).mean()) which seems like the traidional center loss. Could you please explain?
I also think about this, and steal can not understand. I think the right code about the angular center loss should be write like this:
def angular_loss(out_1, out_2, center):
out_1 = F.normalize(out_1, dim=-1)
out_2 = F.normalize(out_2, dim=-1)
center_loss = -((out_1 * center).sum(dim=1).mean() + (out_2 * center).sum(dim=1).mean())
return center_loss
out_1 = model(img1)
out_2 = model(img2)
center_loss = angular_loss(out_1, out_2, center)
out_1 = out_1 - center
out_2 = out_2 - center
loss = contrastive_loss(out_1, out_2) + center_loss
Hi Please note that optimizing the Euclidean metric when dealing with unit vectors is proportional to optimizing the angular distance multiplied by a constant factor. Therefore, this optimization process is equivalent. Hope this clarifies your questions.
Hi, I see the angular center loss is expressed as follow: I'm confused why it is expressed as such math formual? and i see the corresponding code is: out_1 = model(img1) out_2 = model(img2) out_1 = out_1 - center out_2 = out_2 - center center_loss = ((out_1 2).sum(dim=1).mean() + (out_2 2).sum(dim=1).mean()) which seems like the traidional center loss. Could you please explain?