## 2 Materials and Methods
### YOLOv8 Network Improvement
#### 2.3.4 Experimental Setup and Evaluation Metrics for YOLOv8n-WSE-Pest Model Accuracy  
To verify the accuracy of the YOLOv8n-WSE-pest model in pest identification, the hardware environment of this study is based on a 12 th Gen Intel(R) Core(TM) i9-12900H 2.50 GHz processor, a 512 GB solid-state drive, and an NVIDIA GeForce RTX 3060 laptop GPU with 16 GB RAM. The software environment is built on the Windows 11 operating system, NVIDIA 528.24 driver, and CUDA version 11.3.1. The model development and testing were conducted using Python 3.7 and PyCharm 2017.  
Extending beyond basic validation, the incorporation of a diverse set of evaluation metrics is pivotal for a thorough understanding of our enhanced model's detection capabilities. This study employs a suite of metrics--precision, recall, F1 score, AP (average precision), mAP (mean average precision), and three types of loss functions--as benchmarks for gauging performance. Precision, as Equation (16) illustrates, is central to evaluating the model's precision in classifying truly positive instances amidst all positive predictions. A heightened precision score signifies the model's refined ability to correctly discern specific pest classes.  
\[Precision=\frac{TP}{TP+FP} \tag{16}\]  
Recall represents the ratio of correctly predicted positive samples to all actual positive samples. A higher recall indicates that the model can classify the majority of the classes, even though there may be occasional misclassifications. It is defined as Equation (17) shows.  
\[Recall=\frac{TP}{TP+FN} \tag{17}\]  
Figure 10: EMA algorithm principle diagram.  
Among these, TP represents the number of times the model predicts a positive sample as positive, FP represents the number of times it predicts a negative sample as positive, and FN represents the number of times it predicts a positive sample as negative. The F1 score is the harmonic mean of the precision and recall and is used to provide a more comprehensive reflection of the model's performance. It is defined as Equation (18) shows.  
\[F1=2\times\frac{Precision\times Recall}{Precision+Recall} \tag{18}\]  
mAP represents the AP across all classes. It is defined as Equation (19) shows.  
\[mAP=\frac{\sum_{i=1}^{C}AP(i)}{C} \tag{19}\]  
In this study, a total of three loss functions were introduced to measure the object detection performance of the model, namely box_loss, cls_loss, and dfl_loss. box_loss is utilized to assess the IoU between the predicted bounding box and the true bounding box. The objective is to minimize the discrepancy between the predicted box and the true box by maximizing their IoU, as defined in Equation (20).  
\[L_{box}=1-IoU(pred_{box},\;ture\_box) \tag{20}\]  
cls_loss is employed to measure the accuracy of the model's predictions regarding the target class by determining whether an object is present within a box. The definition is presented in Equation (21), where \(y\) is the true label (0 or 1), and \(p\) is the probability predicted as the positive class.  
\[L_{cls}=-[ylog(p)+(1-y)\text{log}(1-p)] \tag{21}\]  
dfl_loss corrects the model's errors in predicting the bounding boxes of objects, as defined in Equation (22), where \(\alpha_{t}\) is the weight balancing positive and negative samples, \(\gamma\) is the focusing parameter that adjusts the weights of easily classified samples, and \(p_{t}\) is the probability predicted by the model for the target class.  
\[L_{dfl}=-\alpha_{t}(1-p_{t})^{\gamma}log\;(p_{t}) \tag{22}\]