## 3 Methodology
### Adaptive Weighted Loss Mechanism  
In our multi-task framework for pest recognition, we use the uncertainty of each task as the basis for weighting the various loss functions. Specifically, we utilize homoscedastic uncertainty, a form of aleatoric uncertainty that stays constant for a specific task, regardless of input variations. This allows us to measure a task's inherent noise level or reliability. Our framework utilizes an adaptive weighted loss mechanism, adjusting the contribution of each loss based on its associated homoscedastic uncertainty. This prioritizes tasks with higher confidence, enhancing the overall performance of the framework. In our pest-recognition task, the neural network's output for an input \(\mathbf{x}\) is denoted by \(\mathbf{f^{W}}(\mathbf{x})\), where \(\mathbf{W}\) represents the network's weights. Then, the likelihood of recognition is adjusted by introducing a parameter \(\sigma\). This allows for a calibrated confidence in the output, accounting for data uncertainty:  
Figure 4: The process of the SPIM. We employ red, orange, yellow, and green to rank average activation values of windows, with red denoting the highest and green the lowest. Figure 5: A residual block of a residual network. Within this, \(x\) represents the input to the block, \(F(x)\) denotes the residual function representing the transformations within the block, and \(H(x)\) denotes the target mapping, which is the output of the residual block. \[p\Big{(}\mathbf{y}\,|\mathbf{f^{W}}(\mathbf{x}),\sigma\Big{)}=\text{Softmax}\bigg{(} \frac{1}{\sigma^{2}}\mathbf{f^{W}}(\mathbf{x})\bigg{)} \tag{12}\]  
In addition, the loss function is defined as the negative logarithm of the conditional probability of the actual class \(c\). This definition aligns with the principles of maximum-likelihood estimation, as illustrated in the following equation:  
\[\mathbf{L}(\mathbf{W},\sigma)=-\log p\Big{(}\mathbf{y}=c|\mathbf{f^{W}}( \mathbf{x}),\sigma\Big{)} \tag{13}\]  
Within this model, the log likelihood can be formulated as  
\[\log p\Big{(}\mathbf{y}=c|\mathbf{f^{W}}(\mathbf{x}),\sigma\Big{)}=\frac{1}{ \sigma^{2}}f_{c}^{W}(\mathbf{x})-\log\sum_{c^{\prime}}\exp\bigg{(}\frac{1}{ \sigma^{2}}f_{c^{\prime}}^{W}(\mathbf{x})\bigg{)} \tag{14}\]  
where \(\mathbf{f^{W}}_{c}(\mathbf{x})\) is the \(c\)'th element of the output vector \(\mathbf{f^{W}}(\mathbf{x})\). Finally, by defining \(\mathbf{L}_{1}(\mathbf{W})=-\log\text{Softmax}\big{(}\mathbf{y}_{1},\mathbf{f^ {W}}(\mathbf{x})\big{)}\), we can derive the following formula:  
\[ \begin{split}\mathbf{L}_{1}(\mathbf{W},\sigma_{1})& =-\log p\Big{(}\mathbf{y}=c|\mathbf{f^{W}}(\mathbf{x})\Big{)}+ \frac{1}{\sigma_{1}^{2}}\mathbf{L}_{1}(\mathbf{W})-\frac{1}{\sigma_{1}^{2}} \mathbf{L}_{1}(\mathbf{W})\\ &=\frac{1}{\sigma_{1}^{2}}\mathbf{L}_{1}(\mathbf{W})+\log\frac{ \sum\limits_{c^{\prime}}\exp\bigg{(}\frac{1}{\sigma_{1}^{2}}f_{c^{\prime}}^{ W}(\mathbf{x})\bigg{)}}{\bigg{(}\sum\limits_{c^{\prime}}\exp\big{(}f_{c^{\prime}}^{ W}(\mathbf{x})\big{)}\bigg{)}^{\frac{1}{\sigma_{1}^{2}}}}\\ &\approx\frac{1}{\sigma_{1}^{2}}\mathbf{L}_{1}(\mathbf{W})+\log \sigma_{1}\end{split}  \tag{15}\]  
Introducing a simplification for computational tractability, we approximate the softmax normalization constant as \(\frac{1}{\sigma_{n}}\sum\limits_{c^{\prime}}\exp\bigg{(}\frac{1}{\sigma_{n} ^{2}}f_{c^{\prime}}^{W}(\mathbf{x})\bigg{)}\approx\bigg{(}\sum\limits_{c^{ \prime}}\exp\big{(}f_{c^{\prime}}^{W}(\mathbf{x})\big{)}\bigg{)}^{\frac{1}{ \sigma_{n}^{2}}}\), which holds exactly as \(\sigma_{n}\)\(\rightarrow\)1. In the multi-task pest recognition framework, we can derive the following loss function:  
\[ \begin{split}\mathbf{L}(\mathbf{W},\sigma_{1},\sigma_{2})& =-\log p\Big{(}\mathbf{y}_{1},\mathbf{y}_{2}\mid\mathbf{f^{W}}( \mathbf{x}),\sigma_{1},\sigma_{2}\Big{)}\\ &=\frac{1}{\sigma_{1}^{2}}\mathbf{L}_{1}(\mathbf{W}_{1})+\frac{1 }{\sigma_{2}^{2}}\mathbf{L}_{2}(\mathbf{W}_{2})+\log\sigma_{1}+\log\sigma_{2} \end{split}