# A Domain Adaptive Person Re-Identification Based on Dual Attention Mechanism and Camstyle Transfer
## 3 The Proposed Method
### Camera-Aware Neighborhood Invariance  
When the label space (given by the identity annotation and the number of identities) is unknown, it is not feasible to directly analyze the categories of target samples. In this case, the pairwise relationship is a potential clue to guide the feature learning in target domain. In characteristics learning, it is usually assumed that each sample is likely to share the same basic label with its nearest neighbors. The probability that \(x_{i}^{t}\) and \(x_{j}^{t}\) share the same identity can be instantly obtained by using the memory bank mentioned above as follows. \[p_{ij}=\frac{\exp\Bigl{(}s\times\mathcal{K}_{j}^{T}f(x_{i}^{t})\Bigr{)}}{\sum _{n=1}^{N_{t}}\exp(s\times\mathcal{K}_{n}^{T}f(x_{i}^{t}))} \tag{3}\]  
where \(s\) is the scale factor, which can adjust the sharpness of the probability distribution. Based on the above assumptions, ECN [23] was proposed to maximize the probability of each detection image and its nearest neighbor in the entire dataset as follows. \[\mathcal{L}_{ag}=-\sum_{j}w_{i,j}\log p_{ij},w_{ij}=\left\{ \begin{array}{l} \frac{1}{|\Omega_{i}|},j\
eq i\\ 1,j=i\end{array} ,\forall j\in\Omega_{i}\right. \tag{4}\]  
where \(\Omega_{i}\) represents the nearest neighbor of \(x_{i}^{t}\) in the entire target domain. \(\left|\Omega(x_{i}^{t})\right|\) indicates the size of the neighbor set. For convenience, this loss function is called the camera-independent neighborhood loss because it treats all candidates equally, regardless of their camera indexes, when searching for neighbors. Due to the scene changes between cameras, there is a significant difference in the distribution of similarity between inter-camera matching and intra-camera matching [52]. The average pairwise similarity of inter-camera matches is smaller than that of intra-camera matches. In this case, Equation (3) pushes the positive match between cameras away from the probe, which causes issues. As an intuitive solution, a larger neighborhood is selected. However, such an approach inevitably involves more negative matches, which is not conducive to feature learning. To solve this problem, this paper proposes to enforce neighborhood invariance for intra-camera matching and inter-camera matching, respectively. It has the following two assumptions. \(O_{i}^{\text{intra}}\) represents an instance set that shares the same camera with \(x_{i}^{t}\). \(O_{i}^{\text{inter}}\) represents an instance set that has a different camera index from \(x_{i}^{t}\). For both intra-camera matching and inter-camera matching of samples, only the instances in \(O_{i}^{\text{intra}}\) and \(O_{i}^{\text{inter}}\) can be accessed respectively. Therefore, the probability that \(x_{i}^{t}\) shares the same identity with candidate \(x_{j}^{t}\) in the camera is formalized as follows. \[p_{i,j}^{\text{intra}}=\frac{\exp\Bigl{(}s\times\mathcal{K}_{j}^{T}f(x_{i}^{t} )\Bigr{)}}{\sum_{n\in O_{i}^{\text{intra}}}\exp(s\times\mathcal{K}_{n}^{T}f(x_ {i}^{t}))} \tag{5}\]As shown in Equation (6), the definition of the probability that the candidate has the same identity between \(x_{i}^{t}\) and the camera is similar to Equation (5). \[p_{i,j}^{\text{inter}}=\frac{\text{exp}\Big{(}s\times\mathcal{K}_{j}^{T}f(x_{i}^{ t})\Big{)}}{\sum_{n\in\mathcal{O}_{i}^{\text{inter}}}\text{exp}(s\times\mathcal{K}_{ n}^{T}f(x_{i}^{t}))} \tag{6}\]  
Therefore, the original camera-agnostic loss function shown in Equation (3) is replaced by the following two camera-perceived loss functions. \[ \begin{split}\mathcal{L}_{\text{intra}}&=-\sum \limits_{j}w_{i,j}\,\text{log}p_{i,j}^{\text{intra}},\forall j\in\Omega_{i}^{ \text{intra}}\\ \mathcal{L}_{\text{inter}}&=-\sum\limits_{j}w_{i,j} \,\text{log}p_{i,j}^{\text{inter}},\forall j\in\Omega_{i}^{\text{inter}}\end{split}  \tag{7}\]  
where \(\Omega_{i}^{\text{intra}}\) and \(\Omega_{i}^{\text{inter}}\) represent the neighborhood set of \(x_{i}^{t}\) between \(O_{i}^{\text{intra}}\) and \(O_{i}^{\text{inter}}\), respectively.