# RANDnet: Vehicle Re-Identification with Relation Attention and Nuance-Disparity Masks
## 3 Vehicle Re-Identification With RANDnet
### Framework  
In this section, we describe the architecture of our proposed relation attention with the nuance-disparity masks network (RANDnet). We adopt IBNnet [14] as our backbone model. Two pivotal components, the N&D masks and the RA (Region Attention) module, are integrated as branch networks into the backbone architecture, as shown in Figure 5. The feature vectors extracted from these two branches are concatenated to generate the final image representation.  
We implement a weight matrix by N&D masks on the feature map before the GAP operation. In order to obtain a concrete importance score for the feature weight, a parameter \(impact\) is introduced.  
Moreover, an \(h\times w\) tensor is defined as the weight matrix. The calculation procedure can be expressed as  
\[F^{\prime}_{last}=F_{last}\odot(impact\times Masks+1) \tag{13}\]  
where operation \(\odot\) denotes the Hadamard product. \(F^{\prime}_{last}\) represents the refined 3D feature tensor, which is then fed into the GAP layer. Let \(F_{last}\) denote the final feature map produced by the backbone network. The hyper-parameter \(impact\) is employed to modulate the extent to which the N&D masks influence this feature map.  
In the RANDnet framework, the backbone network processes the input vehicle image to produce a 3D feature map, which is subsequently relayed to each branch. Within each branch, an FC layer is employed to compute the cross-entropy loss, treating the re-identification task as a classification challenge. The cross-entropy loss is formulated as follows:  
\[loss_{CE}=-\sum_{i=1}^{BS}y_{i}^{T}\log(\hat{y}i), \tag{14}\]  
where \(BS\) denotes the batch size utilized during training. Here, \(yi\) represents the one-hot encoded vector corresponding to the ground truth label of the image \(I_{i}\), and \(\hat{y}_{i}\) signifies the predicted probability distribution across all categories for the given branch.  
In addition to the cross-entropy loss, triplet loss is employed to enhance the distribution of features. The function \(\Theta(\cdot)\) symbolizes the deep learning model, serving as a transformation from raw images to feature vectors. The triplet loss is defined as  
\[loss_{Tri}=\max(d(\Theta(I_{a}),\Theta(I_{p}))-d(\Theta(I_{a}),\Theta(I_{n}) )+margin,0), \tag{15}\]  
Figure 5: The network architecture of RANDnet incorporates disparity mask and nuance mask. (**a**) Details of N&D masks. During the testing phase, the representation vector of a vehicle is composed of the three vectors. (**b**) Details of RA Module.  
where \(I_{a}\) is the anchor image, \(I_{p}\) is a positive instance sharing the same label as \(I_{a}\), and \(I_{n}\) is a negative instance with a differing label. These instances are selected from a training batch following a strategy aimed at mining hard examples. The function \(d(\cdot)\) calculates the \(L2\) distance, and the inclusion of a \(margin\) promotes discriminative learning between positive and negative pairs.  
The cumulative loss is expressed as  
\[loss=loss_{CE}+\alpha\cdot loss_{Tri}, \tag{16}\]  
where \(\alpha\) is a hyper-parameter that adjusts the relative influence of the two losses. The losses from branch-1 and branch-2 are denoted as \(loss_{1}\) and \(loss_{2}\), respectively. Thus, the overall loss for RANDnet is calculated by  
\[loss_{RANDnet}=loss_{1}+\beta\cdot loss_{2}, \tag{17}\]  
introducing \(\beta\) as a mechanism to modulate the gradient flow proportionally between the branches during backpropagation, thereby optimizing the learning dynamics of the network.