# Diverse Feature-Level Guidance Adjustments for Unsupervised Domain Adapative Object Detection
## 3 Methods
### Pixel-Wise Multi-Scale Alignment  
In order to enhance feature adaptation, Pixel-wise Multi-scale Alignment (PMA) is proposed to capture sufficient contextual information. Following the regular training methods of domain adaptation, we resort to adversarial training [2] techniques. To narrow the data distribution gap across different domains, the PMA module is applied to features from different backbone stages. The implementation process of PMA is as shown in Figure 3.  
During the training phase, multi-scale features from the source domain and the target domain are calculated, using the PMA module pixel-wisely. To measure the similarity between the two domains within the same batch, \(\text{Sim}_{pixel}\) is introduced, which quantifies the degree of similarity between them, as can be seen in Figure 3. The similarity computation of cross-domain features is as follows:  
\[\text{Sim}_{pixel}\Big{(}f_{I}^{S},f_{I}^{T}\Big{)}=\left\|f_{I}^{S}-f_{I}^{T} \right\|_{2}, \tag{1}\]  
where \(f_{I}^{S}\) and \(f_{I}^{T}\) denote the features from the source domain and the target domain, respectively.  
Inspired by TIA [16], the VGG16 [37] network is divided into three stages. Subsequently, PMA loss, represented by \(\mathcal{L}_{PMA}\), is constructed to bring the feature distributions of various domains closer together, as shown in Equation (2). \(i\) denotes the \(i\)th stage of the network, and is set to 1, 2, and 3. X and Y are the sample feature sets from the three stages of the backbone network. a and b are current features from X and Y, respectively, used for calculating the PMA loss. The contextual similarity is taken as an exponential factor [38] in calculating the similarity learning loss. The loss function formulated by the PMA module is as follows:  
\[\mathcal{L}_{PMA}\Big{(}f_{I}^{S},f_{I}^{T}\Big{)}=-\log\frac{\sum_{a\in X_{i }}e^{\text{Sim}_{pixel}\Big{(}f_{I_{i}}^{S},f_{I_{i}}^{T}\Big{)}}}{\sum_{a\in X _{i}}e^{\text{Sim}_{pixel}\Big{(}f_{I_{i}}^{S},f_{I_{i}}^{T}\Big{)}}+\sum_{b\in Y _{i}}e^{\text{Sim}_{pixel}\Big{(}f_{I_{i}}^{S},f_{I_{i}}^{T}\Big{)}}}~{},\quad i =1,2,3 \tag{2}\]  
Since there are inconsistencies in the feature representations at different stages, we choose to employ different weights to assess the importance of features. Three parameters are commonly set, with \(\alpha=0.2\), \(\beta=0.3\), and \(\gamma=0.5\). The total PMA loss is formulated as follows:  
\[\mathcal{L}_{PMA}=\alpha\mathcal{L}_{PMA}^{1}+\beta\mathcal{L}_{PMA}^{2}+ \gamma\mathcal{L}_{PMA}^{3} \tag{3}\]  
Figure 3: Proposed pixel-level multi-scale alignment. Given the output features of each stage of the network across two domains, PMA calculates the similarity between source features and target features for each batch. PMA loss is then performed on the batched features to align the two domain data distributions.  
The features generated by the feature generator \(B_{F}\) are \(B\times C\times W\times H\) tensors. B denotes the batch size of the input in the training phase. C, W, and H are the channel, width, and height of the input images, respectively. When calculating the similarity of features based on the PMA loss, the computation is performed along the channel dimension. However, due to the excessive computational burden imposed by channel-wise calculations, cross-channel calculations become necessary. At this point, it is validated that a stride of 16 achieves optimal performance, and this will be detailed in Section 4.4.  
Our PMA loss enhances the feature contextual alignment across domains and provides guidance for the domain discriminator. The overall loss of the method is formulated as follows:  
\[\mathcal{L}=\mathcal{L}_{\text{det}}+\mathcal{L}_{da}+\mathcal{L}_{PMA}\;, \tag{4}\]  
where \(\mathcal{L}_{\text{det}}\) represents the training loss of the baseline Faster R-CNN, and \(\mathcal{L}_{da}\) denotes the adversarial training loss provided by the domain discriminator.