# Multiple Object Tracking Using Re-Identification Model with Attention Module
## 3 Proposed Method
### Object Association
#### 3.2.2 Triplet-Based Association Network with Attention  
The Kalman filter, which solely relies on boundary box coordinates, is prone to frequent ID switches when objects overlap or are separate. To overcome this limitation, we propose a solution by constructing an embedding network to incorporate image information and compute a similarity matrix for the IDs across images. The embedding network was built using a triplet loss and an attention module. Figure 5: Intersection over union (IoU). An attention block was added to the embedding network configuration used in [9] by inserting it after the residual block [23]. The attention module utilizes the method proposed in CBAM [24], which has been demonstrated to enhance performance by adding attention blocks to bottleneck locations. Attention blocks have a negligible impact on the existing parameters since they do not have a large number of parameters. Consequently, they can enhance performance while maintaining the computational speed. The detail of the attention association network architecture is shown in Figure 6.  
Triplet Loss  
The loss function was designed to not only bring semantically similar inputs closer together in the embedding space, but also to ensure that dissimilar inputs are separated by a significant distance. This results in a discriminative embedding space where each input is mapped to a unique and distinguishable feature vector. The triplet loss is computed using three inputs: an anchor image (used as a reference), a positive image with the same ID as the anchor, and a negative image with a different ID, as shown in Figure 7. The embedding network shares the weights to compute the feature vectors of these images and learn to distinguish whether the images represent the same object, which results in Figure 8.  
Figure 8: Example of metric learning. Figure 6: Network architecture of proposed embedding network. Figure 7: Schematic of the triplet structure of the proposed network. The triplet loss was designed to minimize the distance between an anchor and the positive image and to maximize the distance between an anchor and the negative image by using the feature vector obtained from the CNN. The distance between feature vectors is calculated as the L2-norm as follows:  
\[Triplet(i,j)=\parallel f(i)-f(j)\parallel_{2}, \tag{3}\]  
where \(i\) and \(j\) are the input images, with one of them being an anchor image and the other a positive or negative image. \(f(\cdot)\) represents the proposed embedding network. The triplet loss is defined as:  
\[l_{triplet}(a,p,n)=[D_{a,p}-D_{a,n}+\alpha]_{+}, \tag{4}\]  
where \(a,p\), and \(n\) are the anchor, positive image, and negative image and \(\alpha\) denotes the margin between the distances. The network was trained to minimize the triplet loss. The metric learning process can be unstable and may oscillate without converging, as the labels are not quantified and the model expects clustered data in the embedding space. To address this issue, Reference [25] proposed a negative hard sampler method that selects negative samples greater than the distance of the positive samples relative to an anchor during triplet construction. This method can facilitate fast convergence and high performance. However, for tracking datasets, a different sampler construction method may be more appropriate. Tracking datasets consist of several videos, and objects are typically tracked within the same video. Therefore, it is more appropriate to select hard negative samples from the same video rather than from other videos, as this can facilitate discrimination learning for overlapping objects and similar backgrounds within the same video. Positive samples of the same class are also typically present in the same video, so they can be randomly selected as existing samplers. This method of selecting negative hard samples from the same video has been shown to be more appropriate for tracking datasets, as verified through experiments.