机器学习中的一个任务是学习具有判别性的特征,使得类内距离较小,类间距离较大,或者说使得学习到的特征具有类内的紧致性和类间的分离性。传统的做法是利用contrastive loss,triplet loss,还有最近提出来的center loss+softmax。参考论文提出了large-margin softmax (L-Softmax) loss也是以此为目的,它扩展了传统的Softmax,取得了更好的效果。
更新记录
康凯@Dilusense
本文持续更新!如文中有错误,或你对本文有疑问或建议,欢迎留言!
2017年01月20日,发表博文。
参考文献
[2016 ICML] Large-Margin Softmax Loss for Convolutional Neural Networks
相关代码
import numpy as np
import matplotlib.pyplot as plt
def angleMargin(m):
assert m > 0 and isinstance(m, int)
pts = 100
psi = np.empty(m*pts)
theta = np.empty(m*pts)
for k in range(m):
t = np.linspace(k*np.pi/m, (k+1)*np.pi/m, pts)
theta[k*pts:(k+1)*pts] = t
psi[k*pts:(k+1)*pts] = (-1)**k*np.cos(m*t) - 2*k
return theta, psi
if __name__ == '__main__':
for m in range(1, 5):
theta, psi = angleMargin(m)
plt.plot(theta, psi, label = 'm = {}'.format(m))
plt.legend(loc = 'best')
plt.xlabel(r'$\theta$')
plt.ylabel(r'$\psi(\theta)$')