# Cross Domain Adaptation of Crowd Counting with Model-Agnostic Meta-Learning
## 3 Methods
### Adaptive Domain-Invariant Feature-Extracting Module  
The feature extraction module is an essential part of the vision algorithm [66]. In cross-domain scenarios, the training dataset is represented as the source domain for training, and testing or predicting is then performed in the target domain. Without domain adaptation, accuracy and performance will be significantly reduced [67]. The different feature distribution between the source and target domains causes a decrease in accuracy in cross-domain scenarios. Consequently, aligning the two domains at the feature level will create a more adaptive model [68]. In this section, we study the adversarial training approaches used to extract domain-invariant features, and we apply the separate feature-extracting model in cross-domain scenes. For the source domain, we preferred the most popular synthetic dataset in crowd-counting scenarios, the GCC datasets, created for the GTA5 computer game, while, for the target domain, we chose real-world datasets, such as NWPU-crowd, Shanghai A, and UCF, etc. The GTA5 dataset exploits UE4 to construct synthetic street-scene data (different weather conditions, timestamps, and capacities) for crowd-counting tasks. The advantage of the synthetic dataset is that there is no need to manually label the data, and, when the image is synthesized, the objects in the image already have accurate location information [5; 53]. In cross-domain scenarios, we sought to train a feature-extracting module to align the feature distribution and extract the domain-invariant features representation. Given the labeled source domain \(\mathcal{D}_{S}=\{(x_{i}^{S},y_{i}^{S})\}_{i=1}^{N_{S}}\), \(x_{i}^{S}\) and \(y_{i}^{S}\) denote the \(i\)-th crowd image and corresponding label. Furthermore, we had access to the target domain \(\mathcal{D}_{T}=\{(x_{i}^{T})\}_{i=1}^{N_{T}}\) containing a set of unlabeled crowd images. We assumed that samples from the two domains are drawn from different distributions, and our goal was to align the two domains using the adversarial training method. If the crowd-counting model is trained in different domains, the parameters of each model for extracting feature representations are different. In cross-domain scenarios, the domain-invariant feature representation needs to be extracted to achieve domain adaptation. We adhered to the idea of extracting domain-invariant feature representation and designing training algorithms in two domains by an adversarial method [69; 70]. In both domains, we used \(\mathcal{H}\)-divergence to measure the distribution distance of the two sets of samples. As shown in Figure 3, we trained the adversarial discriminator module to distinguish whether the feature is generated from a source or target domain. In this feature-extraction module, the source domain contains synthetic data and \(x^{S}\) and \(y^{S}\) are the source image and source label, respectively. The target domain contains  
Figure 3: The domain invariant feature representation module framework, which allows models to extract domain-invariant features, to reduce the impact of domain gaps between the source and target domains. real-world data and \(x^{T}\) and \(\widetilde{y}^{T}\) are the target image and pseudo-target label, respectively. These are coarse and predicted by the model trained in the source domain. We define \(h:x\rightarrow\{0,1\}\) as the adversarial discriminator, which aims to distinguish samples from the source domain or target domain. We denote the sample of source domain \(x_{i}^{S}\) as 0, and the target domain sample \(x_{i}^{T}\) as 1. We denote the method \(h(\cdot)\) as the domain classifier, and the \(\mathcal{H}\)-divergence distance between the source domain and target domain is shown below:  
\[ \begin{split} e_{S}(h)&=E_{x\sim\mathcal{D}_{S}}[|h( x)-0|]\\ e_{T}(h)&=E_{x\sim\mathcal{D}_{T}}[|h(x)-1|]\\ d_{\mathcal{H}}(S,T)&=2(1-\min_{h\in\mathcal{H}}( e_{S}(h)+\epsilon_{T}(h)))\end{split}