# Contactless Palm Vein Recognition Based on Attention-Gated Residual U-Net and ECA-ResNet
## 3 Attention-Gated Residual U-Net and ECA-ResNet
### Palm Vein Recognition
#### 3.3.3 Loss Function  
As a proposed recognition model is trained with the combined loss functions, the following layers after the feature embedding output are set in a multi-task trainable manner for each loss function. First, the feature embedding is used to calculate triplet loss [49] by computing the Euclidean distances between the pairs of genuine and imposter palm samples. To boost the triplet loss to learn better generalization features for hard negative samples, a hard-mining strategy is used before computing the triplet loss function. After that, the embedding outputs are separated into the binary head and margin head separately, where the aim is for each head to be simultaneously trained with focal loss and ArcFace loss. In the margin head, an angular margin m is added to the targets and multiplied by the feature scale s to compute ArcFace loss. By combing triplet loss, ArcFace loss, and focal loss, the network learned to separate hard samples with high discriminative features for identification and verification. The triplet loss in our experiment is defined as Equation (15):  
\[L_{\text{Triplet}}=\max(0,M+\left\|f(x_{a})-f(x_{p})\right\|-\left\|f(x_{a})-f( x_{bn})\right\|) \tag{15}\]  
where \(a\) represents the anchor sample, \(p\) represents the positive sample, \(bn\) represents the hard negative sample, and margin \(M\) stands for margin.  
The ArcFace loss [8], which is based on modifications in the SoftMax loss function, is used to obtain discriminative embedding features for palm vein samples. An additive angular margin penalty is applied to tighten the distances between intra-class samples and boost inter-class diversity. The margin penalty also provides precise correspondence to the geodesic distance. The ArcFace loss is formulated as Equation (16).  
\[L_{\text{ArcFace}}=-\frac{1}{N}\sum_{i=1}^{N}\log\frac{e^{s\left(\cos\left( \theta_{y_{i}}+m\right)\right)}}{e^{s\left(\cos\left(\theta_{y_{i}}+m\right) \right)}+\sum_{j=1,j\
eq y_{i}}^{n}e^{s\cos\theta_{j}}} \tag{16}\]  
where \(\theta_{j}\) is the angle between the feature vector and the weight vector, s is the scaling factor for the feature vectors, m represents the penalty imposed on the angular margin, and N and n stand for the size of the batch being processed and the total number of classes, respectively.  
Focal loss [50], which is a cross-entropy loss that is dynamically scaled with a scaling factor, was proposed to solve the class imbalance problem in binary classification. To punish hard-to-classify classes more severely during training, the scaling factor down-weighs the easy-to-classify samples. In this study, the focal loss is modified to apply to multi-class classification, as shown in Equation (17).  
\[L_{\text{Focal}}\,=-\sum_{c}^{i=n}(1-y_{i})^{\gamma}\log(y_{i}) \tag{17}\]  
Figure 8: Detailed network architecture of proposed ECA-ResNet-50 recognition model.  
where \(C\) denotes the number of categories, \(y_{i}\) denotes a probability distribution of the prediction, and \(\gamma\) is the focusing parameter that controls the degree to which the loss function focuses. When \(\gamma>0\), the focal loss will assign more weight to hard-to-classify classes and less weight to easy-to-classify samples.  
Thus, ArcFace loss broadens the inter-class margins with the margin penalty, while hard triplet loss enhances the intra-class compactness. Meanwhile, focal loss is incorporated with triplet loss and ArcFace loss to focus more on hard-to-classify palm vein samples. The combination of these losses allows our deep recognition model to learn more specific discriminative features for palm vein recognition.