A cross-angle sheep face recognition method based on improved MobileNetV2
Patent Information
- Application Number
- CN202610932526.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-26
- Publication Date
- 2026-08-18
AI Technical Summary
现有羊脸识别方法多以轻量化卷积神经网络为基础,虽在固定视角下取得一定识别效果,但在真实牧场环境中普遍存在跨角度识别性能严重退化问题:羊脸在正脸、半侧脸、侧脸等混合视角下,纹理、轮廓、局部几何结构发生显著变化,引发类内差异扩大、浅层纹理与高层语义特征错位、固定感受野无法适配几何形变、困难样本梯度不稳定等问题,导致模型在实际部署中识别精度大幅下降
Smart Images

Figure CN122598233A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent farming, and in particular to a cross-angle sheep face recognition method based on an improved MobileNetV2. Background Technology
[0002] In large-scale sheep farming, individual sheep identification is a crucial foundation for achieving precise feeding, health monitoring, reproductive management, disease tracing, and breeding selection. Traditional identification methods, such as ear tags, spray-painted numbers, and RFID tags, have drawbacks such as easy detachment, easy forgery, strong animal stress, low efficiency of manual verification, and high long-term maintenance costs, making it difficult to meet the non-contact, low-stress, and automated management needs of smart farms.
[0003] Sheep face recognition technology based on computer vision and deep learning has become an important development direction for livestock individual identification due to its advantages such as non-invasiveness, stress-free operation, and automated deployment. Existing sheep face recognition methods are mostly based on lightweight convolutional neural networks. While they achieve certain recognition results under fixed viewpoints, they generally suffer from severe performance degradation across different angles in real pasture environments. Sheep faces exhibit significant changes in texture, contour, and local geometry under mixed viewpoints such as frontal, semi-profile, and profile views. This leads to problems such as increased intra-class differences, misalignment between shallow textures and high-level semantic features, inability of fixed receptive fields to adapt to geometric deformations, and unstable gradients for difficult samples, resulting in a significant decrease in recognition accuracy during actual deployment.
[0004] Current technologies primarily focus on deepening network structures, stacking simple attention mechanisms, or expanding datasets, lacking systematic solutions for cross-layer feature alignment, receptive field adaptation, and optimization of difficult samples to address cross-angle pose variations. This makes it difficult to balance cross-angle robustness and recognition accuracy while maintaining model lightweightness. Therefore, developing a cross-angle sheep face recognition method that balances lightweight design, high accuracy, and strong generalization ability has become an urgent need in the field of large-scale smart animal husbandry. Summary of the Invention
[0005] The technical problem to be solved by this invention is how to provide a lightweight, high-precision, and highly generalizable cross-angle sheep face recognition method.
[0006] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0007] A cross-angle sheep face recognition method based on an improved MobileNetV2, the key of which includes the following steps:
[0008] Collect sheep face images from multiple angles to construct a dataset;
[0009] Construct a recognition model based on MobileNetV2 as its backbone;
[0010] The recognition model based on MobileNetV2 includes the MobileNetV2 model backbone, the multi-level residual attention fusion module MRAFM, the lightweight receptive field attention deep convolution module LiteRFAConvDW, and the pooling classification layer.
[0011] Then, a composite loss function is constructed for the cross-angle sheep face recognition scenario. The multi-angle sheep face image dataset is input into the above recognition model for model training to obtain the final recognition model.
[0012] The sheep face image to be tested is input into the final recognition model, which outputs the individual sheep recognition result.
[0013] Preferably, the process of collecting multi-angle sheep face images to construct a dataset involves using a video capture device to film individual sheep, extracting frames from the captured video, using the Structural Similarity Index (SSIM) to remove duplicates from adjacent frames, constructing a sheep face detection dataset from the deduplicated image data, labeling the sheep face regions in some images within the sheep face detection dataset with bounding boxes, training a sheep face detector, and then using the trained detector to locate and crop sheep faces in all images. The cropped images are then uniformly resized to form a standardized sheep face recognition dataset.
[0014] Preferably, the standardized sheep face recognition dataset is divided into training and validation sets using individual-level cross-angle dominant constraints. Specifically, the five angle categories are further mapped into frontal and lateral view sets, with the left half of the face, frontal face, and right half of the face belonging to the frontal view set, and the left and right sides of the face belonging to the lateral view set. The sheep individuals are then divided into two groups. For the first group of individuals, the training set mainly consists of frontal images, and the validation set mainly consists of lateral images. For the second group of individuals, the training set mainly consists of lateral images, and the validation set mainly consists of frontal images.
[0015] Preferably, the Multi-Level Residual Attention Fusion (MRAFM) module selects the low-level, mid-level, and high-level features output from the MobileNetV2 model backbone as input: the low-level features retain rich fine-grained information such as texture and edges, the mid-level features characterize the facial component structure, and the high-level features encode the overall contour and pose semantics; the three layers of features are uniformly mapped to a 64-dimensional channel dimension through 1×1 convolution, and the mid-level and high-level features are upsampled to the same spatial resolution as the low-level features using bilinear interpolation; based on the aligned features, MRAFM uses a grouped attention mechanism for adaptive fusion: after concatenating the three features along the channel dimension, a channel-wise spatial weight map is generated through a 1×1 grouped convolution with groups=64, and the attention weights are obtained by Sigmoid normalization;
[0016] After attention fusion, a lightweight residual refinement block based on depthwise separable convolution is introduced. The lightweight residual refinement block includes two cascaded depthwise separable convolution units, each of which contains a 3×3 depthwise convolution and a 1×1 pointwise convolution, connected by batch normalization and ReLU activation in between, and finally outputs an enhanced feature representation for subsequent classification and recognition.
[0017] Preferably, the pooling classification layer compresses the enhanced features output by the MRAFM module into a fixed-dimensional vector through adaptive average pooling, performs feature mapping through the embedding layer, and then outputs the sheep individual identification results by the fully connected classification layer.
[0018] Preferably, the lightweight receptive field attention-based deep convolutional module LiteRFAConvDW includes K parallel deep convolutional branches, each using the same 3×3 convolutional kernel but with different dilation rates. , D is the set of expansion rates;
[0019] Let the input features be , No. The output features of each branch are represented as follows:
[0020]
[0021] in () indicates group= Depth-separable convolution, For the first The kernel parameters and stride of each branch. and adopting the expansion rate Matching padding, i.e. B represents the batch size, C represents the number of feature channels, and H and W represent the height and depth of the feature map, respectively; and the convolution parameters of each branch are learned independently.
[0022] After obtaining multi-branch features, a lightweight branch attention reweighting mechanism is introduced to adaptively adjust the contribution of each branch. Specifically, for the input... Global average pooling is performed to obtain channel-level statistical vectors:
[0023]
[0024] Subsequently, a branch weight vector is generated through a two-layer fully connected network. And use softmax normalization:
[0025]
[0026] in , These are the parameters for the fully connected layer. () is a nonlinear activation function;
[0027] Finally, the module output is a weighted fusion of features from each branch:
[0028]
[0029] in For the first scalar weights of each branch;
[0030] Replace the last two depthwise separable convolutional 3×3 modules in the backbone network with LiteRFAConvDW modules.
[0031] Preferably, the constructed composite loss function for the cross-angle sheep face recognition scenario collaboratively models the cross-angle feature distribution rebalancing and hard sample reinforcement constraints from the perspective of optimization objectives, and its definition is as follows:
[0032]
[0033] in These are the weighting coefficients for the composite loss;
[0034] Label smoothing is used to improve the standard cross-entropy loss, assuming the true labels of the samples are one-hot vectors. The model obtains the predicted probability after softmax. ,in Indicates the first The predicted probability corresponding to the class is used to introduce a label smoothing factor. Then, the smooth label is defined as:
[0035]
[0036] The corresponding label smoothing cross-entropy loss is:
[0037]
[0038] Focus loss is introduced as a supplementary term, and the focus loss is expressed through the focus factor. Dynamically adjust the gradient weights for each sample to make easily classifiable samples... The contribution of larger samples is suppressed, while the contribution of hard-to-classify samples is... The contribution of smaller samples is preserved and relatively enhanced;
[0039] In multi-class softmax classification, the definition is...
[0040]
[0041] in For the true category index, The focus loss form is used to calculate the predicted probability for this category:
[0042]
[0043] Where γ>0 is the focusing parameter, the larger γ is, the stronger the emphasis on difficult cases.
[0044] The beneficial effects of adopting the above technical solution are as follows:
[0045] This invention uses MobileNetV2 as the feature extraction backbone and combines it with the receptive field attention deep convolution module LiteRFAConvDW to significantly improve cross-angle recognition performance while maintaining extremely low parameter and computational costs, thus preserving the lightweight nature of the model.
[0046] This invention achieves multi-receptive field adaptation through LiteRFAConvDW, effectively adapting to the geometric deformation of sheep faces caused by changes in viewing angle; it completes cross-scale fusion of low, medium and high-level features through MRAFM, and further enhances feature stability by using lightweight residual refinement blocks, alleviating cross-layer semantic misalignment, so that the model can maintain stable recognition in mixed scenarios of frontal face, half-side face and side face, and significantly improves recognition accuracy and generalization ability. Attached Figure Description
[0047] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0048] Figure 1 This is a flowchart illustrating the structure of a cross-angle sheep face recognition method based on an improved MobileNetV2 proposed in this invention.
[0049] Figure 2 This is a schematic diagram of the sheep face detector in an embodiment of the present invention;
[0050] Figure 3 This is a schematic diagram of the structure of the multi-level residual attention fusion module proposed in this invention;
[0051] Figure 4 This is a schematic diagram of the lightweight receptive field attention deep convolution module proposed in this invention;
[0052] Figure 5 This is a comparison chart of the PR curves of various models in the embodiments of the present invention;
[0053] Figure 6 These are heatmaps of various models in the embodiments of this invention;
[0054] Figure 7 This is a schematic diagram of the generalization experiment training process for the Xinjiang Uygur Autonomous Region dataset in an embodiment of the present invention. Detailed Implementation
[0055] To make the above-mentioned objectives, features, and advantages of the present invention more apparent and understandable, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0056] This invention addresses the shortcomings of existing lightweight models in the intelligent livestock farming industry, such as insufficient model accuracy and poor generalization ability in cross-angle scenarios. It proposes a cross-angle sheep face recognition method based on an improved MobileNetV2, as follows: Figure 1 Includes the following steps:
[0057] Collect sheep face images from multiple angles to construct a dataset;
[0058] Construct a recognition model based on MobileNetV2 as its backbone;
[0059] The recognition model based on MobileNetV2 includes the MobileNetV2 model backbone, the multi-level residual attention fusion module MRAFM, and the lightweight receptive field attention deep convolution module LiteRFAConvDW.
[0060] Then, a composite loss function is constructed for the cross-angle sheep face recognition scenario. The multi-angle sheep face image dataset is input into the above recognition model for model training to obtain the final recognition model.
[0061] The sheep face image to be tested is input into the final recognition model, which outputs the individual sheep recognition result.
[0062] Data acquisition serves as the foundation of the data. In this invention, video acquisition equipment is used to capture videos of individual sheep. Frames are extracted from the acquired videos, and adjacent frames are deduplicated using the Structural Similarity Index (SSIM). A sheep face detection dataset is then constructed from the deduplicated image data. Boundary boxes are then labeled for sheep face regions in some images within the sheep face detection dataset to train a sheep face detector. The trained detector is then used to locate and crop sheep faces in all images, and the cropped images are uniformly resized to form a standardized sheep face recognition dataset.
[0063] In actual use, a mobile phone with a resolution of 1920×1080 pixels and an industrial camera were used to shoot videos of sheep under natural breeding conditions. The camera or mobile phone was held at approximately the same height as the sheep's face. The shooting time included 07:00-09:00, 10:00-12:00, and 14:00-18:00. A total of 74 close-up sheep face videos and 86 long-distance sheep face videos were collected, totaling 160 videos involving 114 sheep.
[0064] The captured video was processed using FFmpeg to extract frames, selecting one frame every 15 frames. Subsequently, the Structural Similarity Index (SSIM) was used to deduplicate adjacent frames, with a threshold of 0.80 to reduce highly similar redundant samples. This resulted in 3821 high-quality original images. The images cover five typical angles: left side of the face, left half of the face, frontal view, right half of the face, and right side of the face.
[0065] To avoid inconsistencies in boundaries and scale deviations caused by manual cropping, this invention first constructs a sheep face detection dataset, uses DarkLabel 2.41 to annotate the bounding boxes of the sheep face regions, and trains the YOLOv11n sheep face detector; as follows Figure 2 The trained detector is then used to locate and crop sheep faces in all images, and the cropped images are uniformly adjusted to 224×224 pixels to form a standardized sheep face recognition dataset.
[0066] To simulate the potential perspective shifts that may occur during the training and deployment phases in real-world livestock farming scenarios, this invention, based on conventional image-level segmentation, employs individual-level cross-angle dominance constraints to construct training and validation sets. Specifically, five types of angles are further mapped into frontal and lateral view sets, with the left half of the face, frontal view, and right half of the face belonging to the frontal view set, and the left and right sides of the face belonging to the lateral view set. Individual sheep are then divided into two groups. For the first group, the training set primarily consists of frontal images, while the validation set primarily consists of lateral images. For the second group, the training set primarily consists of lateral images, while the validation set primarily consists of frontal images. The dominant perspective ratio threshold is set to be no less than 80%. This organizational method can create significant perspective shifts at the individual level, making training and evaluation more closely resemble the cross-angle challenges in real-world deployment environments.
[0067] A recognition model based on MobileNetV2 is constructed. The recognition model based on MobileNetV2 includes the MobileNetV2 model backbone, the multi-level residual attention fusion module MRAFM, and the lightweight receptive field attention deep convolution module LiteRFAConvDW.
[0068] This invention uses MobileNetV2 as the base network. This network utilizes inverse residual structures and depthwise separable convolutions to achieve feature extraction with low parameter and computational requirements, making it suitable as the backbone of an edge recognition model and better suited to the lightweight goal of sheep face recognition tasks. Addressing the issues of semantic misalignment, limited receptive field, and insufficient optimization of difficult samples in cross-angle sheep face recognition tasks, this invention makes targeted improvements. The last two depthwise separable convolutional layers of the MobileNetV2 backbone network are replaced with a lightweight receptive field attention-based deep convolutional module, LiteRFAConvDW. Low, medium, and high-level features from the MobileNetV2 backbone network output are selected as inputs to the multi-level residual attention fusion module, MRAFM. Finally, the output features of the MRAFM module are sequentially processed through an adaptive average pooling layer, an embedding layer, and a fully connected classification layer to complete the final sheep individual classification and recognition.
[0069] In cross-view sheep face recognition, pose changes not only cause differences in local texture morphology but also lead to the redistribution of identity-related discrimination cues across different semantic levels, resulting in cross-layer semantic misalignment. Specifically, the fine-grained texture information retained in shallow features may be more critical in profile scenes, while high-level semantic structure features dominate in frontal scenes, making it difficult for single-level features to maintain stable discrimination ability under different viewpoints. To alleviate this cross-layer semantic drift problem, this invention designs a multi-level residual attention fusion module (MRAFM). By performing cross-scale alignment and adaptive weighted fusion of shallow, mid-level, and high-level features, the model can comprehensively utilize multi-level discrimination information under different viewpoint conditions, thereby enhancing the consistency and robustness of cross-view identity representation.
[0070] Specifically, such as Figure 3 The module selects low-level, mid-level, and high-level features from the backbone network as input: low-level features retain rich fine-grained information such as texture and edges, mid-level features characterize facial component structures, and high-level features encode overall contours and pose semantics. Subsequently, the three features are uniformly mapped to a 64-dimensional channel dimension through 1×1 convolutions, and the mid- and high-level features are upsampled to the same spatial resolution as the low-level features using bilinear interpolation, thus achieving cross-scale spatial and channel alignment and providing a unified representation basis for subsequent fusion. Based on the aligned features, MRAFM employs a grouped attention mechanism for adaptive fusion: the three features are concatenated along the channel dimension, and a channel-wise spatial weight map is generated through 1×1 grouped convolutions with groups=64. Attention weights are then obtained through Sigmoid normalization, highlighting relatively stable key regions across different angles, including the eyes, nose, and ears, while suppressing background interference and deformed regions introduced by changes in viewing angle.
[0071] To further enhance the discriminative power of the fused features while controlling computational overhead, we introduce a lightweight residual refinement block based on depthwise separable convolutions after attention fusion. This block consists of two cascaded depthwise separable convolutional units, each containing a 3×3 depthwise convolution and a 1×1 pointwise convolution, connected by batch normalization and ReLU activation. This improves the stability and separability of the fused representation while controlling computational overhead, ultimately outputting an enhanced feature representation for subsequent classification and recognition.
[0072] Besides semantic level drift, cross-angle changes can also induce non-rigid deformations in the local geometry of a sheep's face, such as ear contour stretching and changes in the proportion of the bridge of the nose and forehead. These viewpoint-induced local geometric deformations weaken the ability of fixed receptive field convolutions to model key structural regions. In lightweight networks, due to the limited receptive field adjustment capability, the model often struggles to simultaneously consider local details and global structure, thus reducing the discrimination stability of profile and large-angle samples. To address this issue, this invention proposes a lightweight receptive field attention-based deep convolution module. It constructs a variable receptive field through multi-rate, depthwise separable branches and combines branch attention to achieve structure-sensitive feature reweighting, enhancing the model's adaptability to cross-angle geometric deformations while controlling parameter scale.
[0073] Traditional 3×3 depthwise separable convolutions correspond to only a single receptive field, making it difficult to simultaneously capture local details and global structural features of a sheep's face from both frontal and side views in cross-angle recognition tasks. Especially when the sheep's head rotates, the relative position and scale of facial features change, and convolution operations with a single receptive field are prone to insufficient feature extraction or information loss. Therefore, this invention designs a lightweight convolution module with dynamically adjustable receptive fields, achieving adaptive extraction of cross-angle features through multi-branch dilated convolutions and attention-weighted mechanisms.
[0074] like Figure 4 This module contains K parallel depthwise convolutional branches. In practice, the default value for K is 3. Each branch uses the same 3×3 convolutional kernel but with a different dilation rate. D represents the set of expansion rates, thus enabling the simultaneous acquisition of multi-scale responses under different receptive fields within the same level. The default range is {1,2,3}.
[0075] Let the input features be , No. The output features of each branch are represented as follows:
[0076]
[0077] in () indicates group= Depth-separable convolution, For the first The convolution kernel parameters for each branch, where X is the input data; to ensure consistent output spatial dimensions for each branch under different dilation rates, the convolution stride is set to... And use padding that matches the expansion rate. Furthermore, the convolution parameters for each branch are learned independently to enhance the expressive power of different receptive field branches.
[0078] After obtaining multi-branch features, this invention introduces a lightweight branch attention reweighting mechanism to adaptively adjust the contribution of each branch. Specifically, for the input... Global average pooling is performed to obtain channel-level statistical vectors:
[0079]
[0080] Subsequently, a branch weight vector is generated through a two-layer fully connected network. And use softmax normalization:
[0081]
[0082] in , These are the parameters for the fully connected layer. () is a non-linear activation function.
[0083] Finally, the module output is a weighted fusion of features from each branch:
[0084]
[0085] in For the first The scalar weights of each branch enable adaptive selection and fusion of different receptive field features.
[0086] To balance performance and computational cost, only the last two depthwise separable 3×3 convolutional modules in the backbone network are replaced with LiteRFAConvDW modules. This selective replacement strategy is based on the fact that high-level features are more sensitive to pose changes and can effectively control parameter increments.
[0087] In the cross-angle sheep face recognition task, this module enables the model to adaptively capture key features from different perspectives through a dynamic receptive field adjustment mechanism: in the frontal view, a smaller receptive field, i.e., d=1, is conducive to extracting local detail features; in the side view, a larger receptive field, i.e., d=2 or 3, is helpful to capture facial contours and overall structure.
[0088] In cross-view sheep face recognition scenarios, individuals with the same identity may exhibit a significantly dispersed distribution in the feature space under different observation angles, forming so-called view-difficult samples. These samples are often located near the class decision boundary, contributing unstable gradients to the optimization process, leading to a shift in the discrimination boundary and amplifying intra-class variance. Simultaneously, real-world pasture data commonly exhibits an imbalance in the number of class samples, making the model more prone to biasing towards high-frequency classes and ignoring cross-view difficult samples during training. To alleviate this optimization bias caused by view-induced distribution drift and sample difficulty differences, a composite loss function is constructed to collaboratively model the cross-view feature distribution rebalancing and the constraint strengthening of difficult samples at the optimization objective level. Its definition is as follows:
[0089]
[0090] Label smoothing is used to improve the standard cross-entropy loss to alleviate the model's overconfidence learning on hard labels during the training phase. Let the true labels of the samples be one-hot vectors. The model obtains the predicted probability after softmax. ,in Indicates the first The predicted probability corresponding to the class, after introducing a smoothing factor, the smoothing label is defined as:
[0091]
[0092] The corresponding label smoothing cross-entropy loss is:
[0093]
[0094] Under cross-angle conditions, pose changes and occlusion increase sample uncertainty and noise. Label smoothing can suppress overfitting tendencies, reduce the model's excessive dependence on local random patterns, and make the discriminative response more stable under viewpoint perturbations, thereby improving cross-angle generalization ability. In specific applications, the present invention... The value is 0.05.
[0095] To further enhance the learning of difficult samples and boundary samples across angles, a focal loss is introduced as a supplementary term. The focal loss is calculated using a focusing factor. Dynamically adjust the gradient weights of each sample to make easily classifiable samples... The contribution of larger samples is suppressed, while that of hard-to-classify samples, i.e. The contribution of smaller samples is preserved and relatively enhanced.
[0096] In multi-class softmax classification, the definition is...
[0097]
[0098] in For the true category index, For the predicted probability corresponding to this category, this paper adopts the following focus loss form:
[0099]
[0100] Here, γ>0 is the focusing parameter; the larger γ is, the stronger the emphasis on difficult examples, but an excessively large γ may lead to training instability. In practice, γ=1.5 is chosen as a trade-off between performance and convergence stability.
[0101] The weighting coefficients in the composite loss are used to balance the overall convergence stability and the reinforcement of difficult samples. This invention determines the weighting coefficients through small-scale parameter tuning on the validation set. =0.9, =0.1. This setting ensures stable convergence of the optimization process by using the label smooth cross-entropy as the main supervision signal, while the focus loss provides additional constraints on difficult samples across different perspectives, thereby enhancing the discriminative consistency of samples from different perspectives and improving the robustness of the decision boundary from the perspective of the optimization objective.
[0102] In practice, the recognition model is implemented using the PyTorch framework, the optimizer is Adam, and the learning rate is 1×10⁻⁶. -4 The weight decays to 1×10 -4 The training run consisted of 200 epochs with a batch size of 16. Online data augmentation was enabled during the training phase, including random horizontal flipping, random cropping and scaling, random brightness / contrast / saturation perturbations, random Gaussian noise, and ±10° slight rotations, to improve the model's robustness in complex scenes.
[0103] In the inference phase, the image to be recognized is input into the YOLOv11n sheep face detector to obtain the sheep face bounding box. The sheep face region is cropped and scaled to 224×224, and then input into the improved MobileNetV2 recognition model. After feature extraction, LiteRFAConvDW receptive field adaptation, MRAFM multi-level feature fusion, pooling, embedding, and classification calculation, the model outputs the corresponding sheep individual category. This process can be used for single image recognition, frame-by-frame recognition of video streams, or online edge recognition.
[0104] In a cross-perspective validation setting, this paper systematically compares the proposed method with MobileNetV2, ResNet34, ResNet50, MobileNetV3_Small, ShuffleNetV2_1.5x, GhostNet_100, EfficientNet-B0, and GoogLeNetV1. The results are shown in Table 1, and the relevant PR curves are shown in Table 2. Figure 5To ensure fairness, all models underwent parameter statistics under the same 114-class classification task setting.
[0105] Ultimately, the proposed method achieved optimal results across all three core metrics: accuracy of 94.59%, macro-mean recall of 93.35%, and Macro-F1 score of 93.99%. Compared to the MobileNetV2 baseline, our method improves accuracy, macro-mean recall, and Macro-F1 score by 3.30, 1.91, and 3.36 percentage points, respectively, while reducing the number of parameters from 2.94M to 2.49M and the model size from 11.2MB to 9.5MB, achieving simultaneous optimization of cross-perspective recognition performance and deployment cost. Compared to the lightweight backbone MobileNetV3-Small, which has the closest overall performance in the table, our method improves accuracy, macro-mean recall, and Macro-F1 score by 2.55, 1.64, and 2.88 percentage points, respectively, with lower parameter count and model storage space, further demonstrating a better trade-off between performance and deployment complexity. Compared to larger-scale backbones, ResNet34 and ResNet50 have approximately 7.4 times and 8.6 times the number of parameters, respectively, of the proposed method. However, none of the three recognition metrics yielded corresponding improvements, indicating that in cross-angle sheep face recognition, simply relying on network capacity expansion cannot effectively alleviate the amplification of intra-class differences caused by changes in viewpoint. On the other hand, ShuffleNetV2_1.5x and GoogLeNetV1 showed more significant declines in macro-average metrics, indicating insufficient discriminative consistency across different individuals and viewpoints, and a tendency to exhibit insufficient class-level recall in side-face or difficult samples.
[0106] In summary, the results in Table 1 demonstrate that the advantage of the proposed method lies not in the accidental correctness of a small number of samples, but in the systematic improvement of the macro-average index, which can more stably cover the multi-class recognition needs under cross-angle conditions. This is consistent with the core issues that this paper focuses on regarding cross-angle facial recognition.
[0107] Table 1 Comparison of effects of different models
[0108] MobileNetv2 91.29 91.44 90.63 2.94 11.2 ResNet34 91.08 91.01 90.46 21.79 83.3 ResNet50 90.76 90.83 90.34 25.55 97.8 MobileNetv3_Small 92.04 91.71 91.11 2.54 9.8 ShuffleNetv2_1.5x 89.17 88.72 87.87 3.50 13.6 GhostNet_100 90.66 90.63 90.31 5.18 19.8 EfficientNet_B0 91.34 89.77 89.45 5.28 20.5 GoogleNetv1 89.81 89.48 88.78 6.62 25.3 Our model 94.59 93.35 93.99 2.49 9.5
[0109] To further verify the source of cross-angle robustness from the perspective of representation mechanism, this paper uses Grad-CAM++ to visualize and compare the discriminant regions of each comparative model on the same set of samples Img1 to Img6. The results are as follows: Figure 6As can be seen, most comparison models exhibit strong response dispersion and localization drift under cross-angle changes, with a large hot zone coverage area, and are more likely to extend to the facial boundary and background area in side-face samples, resulting in inconsistent discrimination cues for the same identity under different viewpoints. In contrast, the method proposed in this invention shows more stable response localization on six sets of samples, with high response areas concentrated in structural areas inside the face and maintaining weaker background activation, demonstrating more effective aggregation of stable identity cues and stronger suppression of non-identity interference factors. This visualization phenomenon is supported by the significant improvement in macro-average recall and Macro-F1 in Table 1, indicating that the proposed method can maintain more consistent discrimination criteria under the background of distribution shift caused by cross-angle, thereby obtaining more reliable cross-angle individual recognition performance.
[0110] To further evaluate the transferability and robustness of the proposed method in external scenarios, this paper collects and constructs an independent sheep face dataset from the Xinjiang Uygur Autonomous Region, in addition to the main experimental data. This dataset contains 25 individual sheep, whose shooting environment, background distribution, and individual appearance details differ from the main data, and can be used to examine the distribution shift that the model may encounter in real-world deployment. To ensure the comparability and reproducibility of the evaluation results, this section strictly follows the aforementioned cross-angle experimental protocol: data partitioning, sample organization, and evaluation metrics are consistent with the main experiment, and the detector is used to locate and normalize the sheep face regions in the original images to minimize the interference of background, scale, and positional factors, so that the evaluation focuses on the ability to distinguish identities under cross-angle conditions.
[0111] Experimental results on the Xinjiang Uygur Autonomous Region dataset show that the improved model achieves a recognition accuracy of 94.10%, which is superior to the 90.56% of the basic model MobileNetV2. The model maintains a stable improvement even under strictly consistent cross-perspective protocol constraints, indicating that the proposed method not only possesses stronger cross-perspective representation capabilities on the main dataset but also maintains good discriminative consistency across out-of-domain data distributions. The generalization training process is as follows: Figure 7 As shown.
[0112] This invention constructs a multi-angle standardized sheep face dataset, improves the MobileNetV2 backbone network by introducing a lightweight receptive field attention module (LiteRFAConvDW), combines a multi-level residual attention fusion module (MRAFM), and employs a composite loss function consisting of label smoothing cross-entropy and focus loss. While ensuring a lightweight model with low computational cost and suitability for edge deployment, it effectively solves the technical challenges of traditional sheep face recognition methods in cross-angle scenarios, such as feature drift, semantic misalignment, poor geometric deformation adaptation, and insufficient optimization of difficult samples. It significantly improves the accuracy, stability, and generalization ability of sheep individual recognition under mixed conditions of frontal, half-side, and side-face recognition. Furthermore, the proposed method is entirely non-contact, low-stress, and highly automated, making it widely applicable to scenarios such as precision feeding, individual management, breeding traceability, and health monitoring in large-scale ranches, demonstrating strong engineering practical value and promising prospects for widespread adoption.
[0113] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A cross-angle sheep face recognition method based on an improved MobileNetV2, characterized in that, Includes the following steps: Collect sheep face images from multiple angles to construct a dataset; Construct a recognition model based on MobileNetV2 as its backbone; The recognition model based on MobileNetV2 includes the MobileNetV2 model backbone, the multi-level residual attention fusion module MRAFM, the lightweight receptive field attention deep convolution module LiteRFAConvDW, and the pooling classification layer. Then, a composite loss function is constructed for the cross-angle sheep face recognition scenario. The multi-angle sheep face image dataset is input into the above recognition model for model training to obtain the final recognition model. The sheep face image to be tested is input into the final recognition model, which outputs the individual sheep recognition result.
2. The cross-angle sheep face recognition method based on improved MobileNetV2 according to claim 1, characterized in that, The process involves collecting multi-angle sheep face images to construct a dataset. This is achieved by capturing videos of individual sheep using video capture equipment, extracting frames from the captured videos, and then using the Structural Similarity Index (SSIM) to remove duplicates from adjacent frames. The deduplicated image data is then used to construct a sheep face detection dataset. Boundary boxes are then labeled for sheep face regions in a subset of the images within the sheep face detection dataset to train a sheep face detector. The trained detector is then used to locate and crop sheep faces in all images, and the cropped images are uniformly resized to form a standardized sheep face recognition dataset.
3. The cross-angle sheep face recognition method based on improved MobileNetV2 according to claim 2, characterized in that, The standardized sheep face recognition dataset is divided into training and validation sets using individual-level cross-angle dominant constraints. Specifically, the five angle categories are further mapped into frontal and lateral view sets, with the left half of the face, frontal view, and right half of the face belonging to the frontal view set, and the left and right sides of the face belonging to the lateral view set. The sheep individuals are then divided into two groups. For the first group, the training set mainly consists of frontal images, while the validation set mainly consists of lateral images. For the second group, the training set mainly consists of lateral images, while the validation set mainly consists of frontal images.
4. The cross-angle sheep face recognition method based on improved MobileNetV2 according to claim 1, characterized in that, The multi-level residual attention fusion module (MRAFM) selects low-level, mid-level, and high-level features output from the MobileNetV2 model backbone as input: low-level features retain rich fine-grained information such as texture and edges, while mid-level features characterize the facial component structure. High-level feature encoding of overall contour and pose semantics; The three layers of features are uniformly mapped to a 64-dimensional channel dimension through 1×1 convolution, and the middle and high-level features are upsampled to the same spatial resolution as the low-level features using bilinear interpolation. Based on the aligned features, MRAFM uses a grouped attention mechanism for adaptive fusion: the three features are concatenated along the channel dimension, and a channel-wise spatial weight map is generated by a 1×1 grouped convolution with groups=64, and the attention weights are obtained by Sigmoid normalization. After attention fusion, a lightweight residual refinement block based on depthwise separable convolution is introduced. The lightweight residual refinement block includes two cascaded depthwise separable convolution units, each of which contains a 3×3 depthwise convolution and a 1×1 pointwise convolution, connected by batch normalization and ReLU activation in between, and finally outputs an enhanced feature representation for subsequent classification and recognition.
5. A cross-angle sheep face recognition method based on improved MobileNetV2 according to claim 1, characterized in that, The pooling classification layer compresses the enhanced features output by the MRAFM module into a fixed-dimensional vector through adaptive average pooling, then performs feature mapping through the embedding layer, and finally outputs the individual sheep identification results by the fully connected classification layer.
6. The cross-angle sheep face recognition method based on improved MobileNetV2 according to claim 1, characterized in that, The lightweight receptive field attention-based deep convolutional module LiteRFAConvDW includes K parallel deep convolutional branches, each using the same 3×3 convolutional kernel but with different dilation rates. , D is the set of expansion rates; Let the input features be , No. The output features of each branch are represented as follows: ; in () indicates group= Depth-separable convolution, For the first The kernel parameters and stride of each branch. and adopting the expansion rate Matching padding, i.e. B represents the batch size, C represents the number of feature channels, and H and W represent the height and depth of the feature map, respectively; and the convolution parameters of each branch are learned independently. After obtaining multi-branch features, a lightweight branch attention reweighting mechanism is introduced to adaptively adjust the contribution of each branch. Specifically, for the input... Global average pooling is performed to obtain channel-level statistical vectors: ; Subsequently, a branch weight vector is generated through a two-layer fully connected network. And use softmax normalization: ; in , These are the parameters for the fully connected layer. () is a nonlinear activation function; Finally, the module output is a weighted fusion of features from each branch: ; in For the first scalar weights of each branch; Replace the last two depthwise separable convolutional 3×3 modules in the backbone network with LiteRFAConvDW modules.
7. A cross-angle sheep face recognition method based on improved MobileNetV2 according to claim 1, characterized in that, The constructed composite loss function for cross-angle sheep face recognition scenarios, from the perspective of optimization objectives, collaboratively models the rebalancing of cross-angle feature distribution and the reinforcement constraints of difficult samples, and is defined as follows: ; in These are the weighting coefficients for the composite loss; Label smoothing is used to improve the standard cross-entropy loss, assuming the true labels of the samples are one-hot vectors. The model obtains the predicted probability after softmax. ,in Indicates the first The predicted probability corresponding to the class is used to introduce a label smoothing factor. Then, the smooth label is defined as: ; Where C is the total number of sheep individuals of each category, the corresponding label smoothing cross-entropy loss is: ; Focus loss is introduced as a supplementary term, and the focus loss is expressed through the focus factor. Dynamically adjust the gradient weights for each sample to make easily classifiable samples... The contribution of larger samples is suppressed, while the contribution of hard-to-classify samples is... The contribution of smaller samples is preserved and relatively enhanced; In multi-class softmax classification, the definition is... ; in For the true category index, The focus loss form used is for predicting the probability corresponding to this category: ; Where γ>0 is the focusing parameter, the larger γ is, the stronger the emphasis on difficult cases.