xialuxi / arcface-caffe

insightface-caffe
MIT License
279 stars 124 forks source link

关于loss的梯度计算 #15

Open wu-ruijie opened 5 years ago

wu-ruijie commented 5 years ago

作者你好,有一个关于loss的梯度计算的问题想请假一下: 1、arcface的梯度我看到代码是:cos_m + sin_m cos_t[i dim + gt] / sin_theta,其实就是sin(theta+m)/sin(theta),我自己的计算是:-sin(theta+m),是不是少了什么呢? 2、combined margin的梯度我看你的代码是:m1 pow(1 - pow(bottom_data[i dim + gt], 2), -0.5) sin(m1_x_m2[i dim + gt]),其实就是m1 sin(m1 theta+m2) sin(theta),我自己的计算是:-m1 sin(m1 * theta+m2),请问你的计算是怎么得到的呢?万分感谢!

xialuxi commented 5 years ago

其实就是cos(m)cos(theta) - sin(m)sin(theta) 对 cos(theta)求导,你可以自己推导一下。

wu-ruijie commented 5 years ago

谢谢作者的回复,如果对cos(theta)求导就对着,之前我一直对theta求导,后来仔细想想,和W直接相关的是cos(theta),而不是theta,只不过在做softmax的时候,对theta进行了变换,使得训练更加困难了,从而也促进网络训练出更小的theta,感谢!