# Automatic Bird Species Recognition from Images with Feature Enhancement and Contrastive Learning
## 2 Materials and Methods
### Siamese Network  
Siamese network is proposed to learn similarity or distance between inputs that consists of three identical subnetworks (sharing weights) which process three inputs in parallel. Each subnetwork employs the same architecture and parameters, and processes the three inputs separately during forward propagation to obtain corresponding feature vectors [36; 37]. These feature vectors can then be passed into a metric learning layer to compute the similarity or distance between the three inputs.  
Training a siamese network involves using a triplet loss and softmax loss. Triplet loss is a loss function used for learning similarity or distance metrics, which uses triplets to define the relationship between samples. Each triplet consists of an anchor sample, a positive sample, and a negative sample, where the positive sample is similar to the anchor sample and the negative sample is dissimilar to the anchor sample.  
The goal of triplet loss is to minimize the distance between the anchor sample and the positive sample, while maximizing the distance between the anchor sample and the negative sample, such that the distance between the anchor sample and the positive sample is less than the distance between the anchor sample and the negative sample. This can  
Figure 3: The framework of feature enhancement module. It splits channels and processes sub-features concurrently. Two branches extract informative features: channel attention focuses on important channels using GAP, while spatial attention captures spatial dependencies with group normalization. Both branches are concatenated, followed by sub-feature aggregation and a channel shuffle operation to promote information exchange. This enhances the overall feature representation for tasks like fine-grained bird recognition.  
encourage the model to learn an embedding space where similar samples are closer together and dissimilar samples are farther apart.  
\[L_{tp}=max(0,d(f(a),f(p))-d(f(a),f(n))+margin) \tag{3}\]  
where \(f(a),f(p)\), and \(f(n)\) represent the feature vectors of the anchor sample, positive sample, and negative sample in the embedding space, respectively, \(d(u,v)\) represents the distance between two feature vectors, and margin is a hyperparameter used to control the difference between the distances of the positive and negative samples.  
Softmax loss is used to measure the difference between the predicted probability distribution and the true probability distribution of the classes. The softmax loss function penalizes the model when the predicted probability for the correct class is low and rewards the model when the predicted probability for the correct class is high. The softmax loss function can then be defined as:  
\[L_{st}=-\frac{1}{N}\sum_{j=1}^{K}y_{i,j}logP(y_{i,j}=1) \tag{4}\]  
where \(y_{i,j}\) is a binary indicator (0 or 1) whether the \(j\)-th class is the correct classification for the \(i\)-th training sample, and \(P\big{(}y_{i,j}=1\big{)}\) is the predicted probability of the \(j\)-th class for the \(i\)-th training sample.  
The total loss is a weighted sum of the triplet and softmax losses, where the weights are determined by the relative importance of each component to the overall task.  
\[L=L_{st}+\lambda L_{tp} \tag{5}\]  
During training, a batch of randomly selected triplets are used, and their triplet and softmax losses is computed. The goal is to minimize the loss function by adjusting the weights and biases of the neural network using backpropagation. This process updates the parameters of the network until the loss function is minimized, and the network can accurately classify the input data.