相关文件可见:https://github.com/ydwen/caffe-face
主要包括4个步骤:
(1)src\caffe\caffe.proto里添加消息机制:proto格式的ID号(要求ID号唯一,不与其他ID重合即可)及相应定义
在message LayerParameter{}中添加如下ID号:
optional CenterLossParameter center_loss_param = 155;
再在文档最后加入:
message CenterLossParameter {
optional uint32 num_output = 1; // The number of outputs for the layer
optional FillerParameter center_filler = 2; // The filler for the centers
// The first axis to be lumped into a single inner product computation;
// all preceding axes are retained in the output.
// May be negative to index from the end (e.g., -1 for the last axis).
optional int32 axis = 3 [default = 1];
}
(2)include/caffe/layers/添加头文件center_loss_layers.hpp
(3)src/caffe/layers/添加CPU、GPU实现的相关文件center_loss_layers.cpp\center_loss_layers.cu
(4)重新编译Caffe。首先在windows/libcaffe/libcaffe.vcxproj和libcaffe.vcxproj.filters里
libcaffe.vcxproj相应处增加:
<ClCompile Include="..\..\src\caffe\layers\center_loss_layer.cpp" />
<ClInclude Include="..\..\include\caffe\layers\center_loss_layer.hpp" />
<CudaCompile Include="..\..\src\caffe\layers\center_loss_layer.cu" />
libcaffe.vcxproj相应处增加:
<ClCompile Include="..\..\src\caffe\layers\center_loss_layer.cpp">
<Filter>src\layers</Filter>
</ClCompile>
<ClInclude Include="..\..\include\caffe\layers\center_loss_layer.hpp">
<Filter>include\layers</Filter>
</ClInclude>
<CudaCompile Include="..\..\src\caffe\layers\center_loss_layer.cu">
<Filter>cu\layers</Filter>
</CudaCompile>
再重新编译。成功即可使用。