Following Algorithm 1 of the paper, one training update proceeds as follows.
- Pass each sample of the mini-batch through the network to get the deep features xiโ.
- Compute the softmax loss LSโ and Center Loss LCโ, and set L=LSโ+ฮปLCโ.
- Compute the gradient with respect to the features, โxiโโLโ=โxiโโLSโโ+ฮป(xiโโcyiโโ). The Center Loss term points in the direction that pulls the feature toward its own class center.
- Update the weights W of the last fully connected layer with the gradient of the softmax loss.
- Update each class center cjโ with the features of that class in the mini-batch, using the formula below.
- Update the network weights, such as the convolutional layers, with the gradient from step 3.
The center update is
ฮcjโ=1+โi=1mโฮด(yiโ=j)โi=1mโฮด(yiโ=j)(cjโโxiโ)โ,cjโโcjโโฮฑฮcjโ
ฮด(yiโ=j) is 1 if sample i belongs to class j and 0 otherwise. ฮฑโ[0,1] is the learning rate of the centers. The 1+ in the denominator avoids division by zero when the class does not appear in the mini-batch (the sum is 0); in that case the center is not updated.
For example, suppose the center is c=(0.6,ย 0.2) and the mini-batch contains two features of this class, (1.0,ย 0.5) and (0.8,ย 0.0). The Center Loss of the first feature is 21โ{(0.4)2+(0.3)2}=0.125. The center update is ฮc={(โ0.4โ0.2)/3,ย (โ0.3+0.2)/3}โ(โ0.2,ย โ0.033), and with ฮฑ=0.5 the new center is about (0.7,ย 0.217), moving slightly toward the two features.
Ideally, the "center" would be the mean of the class's features over the whole training set. But the features change at every step, so recomputing the mean over all data each time is impractical. The paper moves the centers a little at a time using only the mini-batch and further damps the movement with the learning rate ฮฑ, so that a few mislabeled samples cannot swing the centers far.