## 4 Experiments
### First-Stage: Automatic Pig Face Detection Module
#### 4.1.2 Implementation Results  
**Training and prediction on the small-size pig face detection dataset with annotation**. In our experimentation, four YOLO-based object detection architecture versions--YOLO-v5, YOLO-v6, YOLO-v7, and YOLO-v8--were evaluated to determine their suitability for pig face detection tasks. While YOLO-v8 was our primary detection model due to its advanced architecture and high performance, YOLO-v5, YOLO-v6, and YOLO-v7 served as benchmarks to assess improvements. The results, as presented in Table 1, show that YOLO-v8 outperforms its predecessors across various metrics. It achieved the highest average precisions (AP) at IoU thresholds of 0.50 (AP\({}_{50}\)), 0.75 (AP\({}_{75}\)), and 0.95 (AP\({}_{95}\)), with values of 0.990, 0.973, and 0.869, respectively, alongside the highest recall of 0.895. These metrics suggest that YOLO-v8 has a superior ability to detect pig faces accurately, even in challenging conditions.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Model** & **AP\({}_{\bf 50}\)** & **AP\({}_{\bf 75}\)** & **AP\({}_{\bf 50-95}\)** & **Recall** \\ \hline YOLO-v5 & 0.975 & 0.955 & 0.821 & 0.779 \\ YOLO-v6 & 0.986 & 0.969 & 0.861 & 0.865 \\ YOLO-v7 & 0.980 & 0.964 & 0.840 & 0.876 \\ YOLO-v8 & **0.990** & **0.973** & **0.869** & **0.895** \\ \hline \hline \end{tabular}
\end{table}
Table 1: Comparative performance metrics of different detection models on the pig face detection dataset.  
From the loss curve in Figure 7, YOLO-v8 shows a faster and more consistent decline, indicating a more effective learning process and stabilization compared to YOLO-v5, YOLO-v6, and YOLO-v7. After the initial sharp decrease, YOLO-v8 maintains a steady, low loss, suggesting that it has better generalized the training data without overfitting. The mAP curve of Figure 7 further supports the superiority of YOLO-v8. All models show a rapid increase in mAP during the early epochs, with YOLO-v8 achieving a higher mAP more quickly than its predecessors and maintaining this lead throughout the training process. The mAP for YOLO-v8 plateaus at a higher value, signifying that it has attained better overall detection performance across different object detection thresholds. In addition, the prediction visualization of YOLO-v8 on the testing dataset is displayed in Figure 8. The visualizations highlight the model's ability to focus on relevant features for pig face detection, confirming its effectiveness as the backbone of our detection module.  
Given the observed high performance, YOLO-v8 was chosen as the primary detection model for our pig face recognition system. The training weights from YOLO-v8 enable the automated detection of faces in unlabeled datasets, which significantly increases the amount of training data available for our recognition tasks. By leveraging YOLO-v8's superior training weights, we can enrich our dataset without the extensive manual labeling traditionally required, saving valuable time and resources.  
Figure 8: Prediction of YOLO-v8 on pig face detection testing dataset.  
Figure 7: The visualization of the training loss and average precision (AP\({}_{50-95}\)) from four YOLO models.