# Margin CosReid Network for Pedestrian Re-Identification
## 3 Margin CosReid Network
### Loss Comparison  
In this section, the decision boundaries among classes \(C_{1}\) and \(C_{2}\) of the three loss functions softmax, CSL, and MCSL are shown in Figure 2.  
First, in the traditional softmax loss function, overlapping decision area (denoted by the yellow region in Figure 2a) exists between the decision boundaries of classes \(C_{1}\) and \(C_{2}\) (denoted by purple and blue dotted lines, respectively) defined as \(\|W_{1}\|\cos(\varphi_{1})=\|W_{2}\|\cos(\varphi_{2})\), so that decisions in this overlapping area cannot be made on which class it belongs to.  
Based on softmax, CSL performs L2 normalization on the weight vectors \(W_{1}\) and \(W_{2}\), thus making the decision boundary a constant (\(\cos(\varphi_{1})=\cos(\varphi_{2})\)). As shown in Figure 2b, boundaries of classes \(C_{1}\) and \(C_{2}\) are connected together, so that the decisions on or closed to the connected line are also unable to be made on their associated classes. CSL performs well in simple pedestrian classification problems because there is no large overlapping area compared to traditional softmax, but is still vulnerable to outside interference with similar pairs of negative samples and confuses two pedestrians with different identities.  
To solve the above problems, the boundary threshold \(m\) is introduced in cosine space in the proposed MCSL algorithm. The boundary conditions of the MCSL are defined as  
\[C_{1}:\cos(\varphi_{1})\geq\cos(\varphi_{2})+m, \tag{6}\]  
\[C_{2}:\cos(\varphi_{2})\geq\cos(\varphi_{1})+m, \tag{7}\]  
In Equations (6) and (7), the feature vector belongs to class \(C_{1}\) only if the minimum value of \(\cos(\varphi_{1})\) is greater than or equal to the maximum value of \(\cos(\varphi_{2})\), and vice versa. Because the decision boundaries of classes \(C_{1}\) and \(C_{2}\) are separated far away from each other as shown in Figure 2c, decisions are easier to be made in the MCSL function. Therefore, the interclass difference becomes larger, and the intraclass difference becomes more compact, which is strong enough to deal with outside interferences to learn more powerful distinguishing features.  
To compare more depth about the three loss functions, we conduct an experiment on their class activation maps in Figure 3. Color temperature means importance in producing gradients associated with the target identities, indicating that warmer colors and sharper outlines demonstrate better performances. The rough outlines of results are drawn with pink dotted curves. In Figure 3a, the outline of MCSL has sharper and more similar shape with that of the person in the input image than those of softmax and CSL. In Figure 3b,c, the color in the outline of MCSL is warmer than those of softmax and CSL. Moreover, red boxes in Figure 3 denote the backgrounds that are mistakenly identified with target in  
Figure 2: Comparison of decision boundaries of (**a**) softmax, (**b**) cosine softmax loss (CSL), and (**c**) margin cosine softmax loss (MCSL) functions under binary classification. Green and orange regions represent the decision areas of classes \(C_{1}\) and \(C_{2}\), respectively. The yellow region represents the overlapping decision area. Purple and blue dotted lines represent the decision boundaries of classes \(C_{1}\) and \(C_{2}\), respectively.  
outlines of both softmax and CSL, whereas not in that of MCSL, which indicates that MCSL outperform others in class activation mapping.