人脸识别论文SphereFace提出一种angular softmax loss, 通过约束权重向量W和特征向量的夹角大小关系,来满足同一类的最大类内距离小于不同类的最小类间距离,提高特征的判别能力。
论文:SphereFace: Deep Hypersphere Embedding for Face Recognition
github:https://github.com/wy1iu/sphereface
作者通过加了一个层:MarginInnerProduct层来实现这个loss,具体可以看github代码。下面讲一下在我们已经配置好的caffe环境中怎么添加这个新层:
1、源码添加或修改:添加margin_inner_product_layer.cpp、margin_inner_product_layer.cu(可以去作者gitgub找到)到CAFFE_ROOT/src/caffe/layers中,修改CAFFE_ROOT/src/caffe/util下 math_functions.cpp、math_functions.cu(直接复制作者的替换即可)
2、头文件添加或修改:添加margin_inner_product_layer.hpp 到CAFFE_ROOT/include/caffe/layers
替换CAFFE_ROOT/include/caffe/util 下的math_functions.hpp,mkl_alternate.hpp
3、修改caffe.proto文档:
在message LayerParameter {
…
}中添加 optional MarginInnerProductParameter margin_inner_product_param = 147;(147这个ID要根据你的配置修改,上面会有提示下一个可用ID是多少的)
在最后面添加
MarginInnerProductParameter层的定义,找原作者的caffe.proto查看就可以了。
4、重新编译caffe,完成。