Once trained, this pig face detection model can serve as a preprocessing step, autonomously generating pig face data for subsequent recognition tasks without additional human intervention. Secondly, we introduce a cutting-edge method that harnesses offline knowledge distillation to optimize the balance between accuracy and compactness in the lightweight pig face recognition model. Knowledge distillation is a technique where a'student' model learns from a 'teacher' model that is more complex [20]. The essence of our approach lies in transferring the nuanced feature representations from the teacher to the student model, which allows the student to replicate the sophisticated understanding of its more advanced counterpart. This process empowers our lightweight model to maintain its reduced size, fitting embedded systems' constraints, while still delivering performance on par with the more comprehensive teacher model. Our proposed overview of the architecture of pig face recognition task is shown in Figure 1.  
In our study, empirical validation was a critical step. We initiated this process by constructing a small-scale pig face detection dataset, which included annotated images from 20 different pigs. To process this dataset, we employed a state-of-the-art detection model, YOLO-v8 [21], specifically chosen for its efficiency in detecting pig faces. This step was vital in generating a preliminary set of high-quality, relevant pig face images. Following the initial detection stage, we incorporated a filtering module that utilized the Multi-Scale Structural Similarity (MS-SSIM) technique [22]. This module played a crucial role in refining our dataset further by removing images with high similarity. Such a process ensured the diversity and quality of our dataset, laying a solid foundation for the effectiveness of the models to follow. A significant advancement in our approach was the application of relational knowledge distillation [23], conducted offline. This technique allowed us to transfer complex features from a high-capacity Vision Transformer (ViT) [24] to a more streamlined model, ShuffleNetV2 [25]. The primary benefit of this methodology was the considerable enhancement in accuracy in our lightweight pig face recognition model, achieved without increasing its computational demands. This balance of accuracy and efficiency is pivotal in applications where resources, particularly computational ones, are limited. The contributions of our proposed work can be summarized as follows:  
* We propose an innovative method that integrates a deep learning-based offline knowledge distillation technique with a lightweight model for pig face recognition. This approach effectively balances accuracy with computational efficiency, which is particularly beneficial for smart pig farming environments;
* We propose a novel, decoupled approach to pig face recognition by separating the detection from the identification process, employing a detection model to create a pre-processing step that significantly reduces the need for exhaustive re-annotation when applying the model to new datasets. This advance facilitates a universal, scalable application across varied datasets, saving considerable time and resources while maintaining high accuracy;
* We introduce a high-quality, publicly accessible 20-pig face dataset, complete with labeled bounding boxes, which serves as a substantial resource for fostering research in pig face detection and recognition within the realm of computer vision.