# Cross Domain Adaptation of Crowd Counting with Model-Agnostic Meta-Learning
## 3 Methods
### Density-Map Estimator Module Based on Dynamic-\(\beta\) MAML
Moreover, the model aims to optimize the parameters \(\theta\) such that with just one SGD step, it can adapt to the new task for optimization. \[\theta_{t}=\theta-\beta\
abla_{\theta}\mathcal{L}_{\mathcal{T}_{test}}(f_{ \hat{\theta}_{t}}) \tag{2}\]  
where, \(\beta\) is the meta-learning rate, which produces an algorithm that learns an initialization of \(\theta\) that is useful in efficiently adapting new tasks with a small number of iterations. In the MAML algorithm, there are two learning rates: \(\alpha\) and \(\beta\), which are updated with meta-training and meta-testing iteration. In this paper, we follow the idea of Alpha  
Figure 2: The details of meta-learning for the density estimator. There are two parts to optimize the model parameters: inner-optimization and meta-optimization. Inner-optimization is over each task, and the meta-optimization is across different tasks. MAML [63] and conduct experiments on the two learning rates. The task-inner-learning rate, \(\alpha\), is internal and affects the iteration result, while the meta-learning rate, \(\beta\), is external and improves the result when applied with the alpha-MAML algorithm. We derived an updated rule for the meta-learning rate, \(\beta\), which can be computed as below:  
\[ \begin{split}\frac{\partial\mathcal{L}_{\mathcal{T}_{test(i)}}(f_ {\beta_{i}})}{\partial\beta}&=\frac{\partial\mathcal{L}_{ \mathcal{T}_{test(i)}}(f_{\beta_{i}})}{\partial\theta_{i-1}}\cdot\frac{ \partial\theta_{i-1}}{\partial\beta}\\ &=\
abla_{\theta_{i-1}}\mathcal{L}_{\mathcal{T}_{meta-test(i)}}( f_{\beta_{i}})\cdot(-\
abla_{\theta_{i-2}}\mathcal{L}_{\mathcal{T}_{meta-test(i-1)}}( f_{\beta_{i}(i-1)}))\end{split}  \tag{3}\]  
where \(i\) is the number of iterations. We can estimate the \(\beta_{i}\) as shown below:  
\[\beta_{i}=\beta_{i-1}+\delta_{hyper}\
abla_{\theta_{i-1}}\mathcal{L}_{ \mathcal{T}_{meta-test(i)}}(f_{\beta_{i}})\cdot\
abla_{\theta_{i-2}} \mathcal{L}_{\mathcal{T}_{meta-test(i-1)}}(f_{\beta_{i}}) \tag{4}\]  
We randomly divided the synthetic data into a set of \(N\) tasks, where each task consisted of both training data and testing data. For the \(i\)-th training iteration, we denote the sample number as \(K\{1,5\}\). The algorithm we propose refers to using a small number of samples to learn a meta-learning model. The dynamic meta-learning rate makes the model faster, and the improved MAML algorithm increases the generalization of the model. The whole algorithm is shown in Algorithm 1 as below:  
```
0:\(\alpha\) is the fixed inter learning rate \(\beta_{0}\) is the initial meta learning rate \(\delta_{hyper}\) is the hyper-gradient learning rates randomly initialize \(\theta\) \(M\) is the count of training iterations Output:
0:\(\theta\) is the parameters of meta-learning model
1:for\(i\) in range(0,\(M\)) do
2:for each sample batch \(\mathcal{T}_{t}\sim\mathcal{D}_{meta-learning}\)do
3: evaluate \(\
abla_{\theta}\mathcal{L}_{\mathcal{D}_{meta-train}}(f_{\theta})\) with respect to \(K\) examples. 4: Compute adapted parameters with gradient descent \(\hat{\theta}=\theta-\alpha\
abla_{\theta}\mathcal{L}_{\mathcal{D}_{meta- train}}(f_{\theta})\)
5:endfor
6: Compute the meta-learning rate \(\beta\):
7:\(\beta_{i}=\beta_{i-1}+\delta_{hyper}\sum_{\mathcal{T}_{t}\in\mathcal{D}_{meta -learning}}\
abla_{\theta_{i-1}}\mathcal{L}_{\mathcal{T}_{meta-test(i)}}(f_ {\beta_{i}})\cdot\
abla_{\theta_{i-2}}\mathcal{L}_{\mathcal{T}_{meta-test( i-1)}}(f_{\beta_{i}})\)
8:\(\theta_{i}=\theta_{i-1}-\beta_{i}\sum_{\mathcal{T}_{t}\in\mathcal{D}_{meta- test}}\
abla_{\theta_{i-1}}\mathcal{L}_{\mathcal{T}_{meta-test(i)}}(f_{\beta_{i}})\)
9:endfor
```  
**Algorithm 1** Dynamic-\(\beta\) MAML  
In this section, we formulate the crowd-counting density estimation as a few-shot learning problem, given a set of datasets where \(\mathcal{D}_{train}\) and \(\mathcal{D}_{test}\) are the training and test sets, respectively. The CSRNet network contains several dilated convolutional layers to regress the density map according to the inputted images for different task-specific data.