Improved yolov8n buffalo face recognition model construction method and system
By improving the YOLOV8n model and adding a coordinate attention module and two-stage decoupled training to buffalo face recognition, the problems of insufficient positional information perception and low training efficiency in buffalo face recognition models in complex scenarios are solved. This achieves efficient and accurate individual buffalo recognition, which is suitable for intelligent breeding equipment and cloud recognition systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INST OF ANIMAL SCI & VETERINARY HUBEI ACADEMY OF AGRI SCI
- Filing Date
- 2026-04-29
- Publication Date
- 2026-07-31
AI Technical Summary
Existing buffalo facial recognition models lack the ability to perceive location information in complex scenarios, have low training efficiency, and are difficult to meet real-time monitoring requirements. Furthermore, traditional methods suffer from computational redundancy and insufficient parameter updates.
An improved version of the YOLOV8n model is adopted. By adding a coordinate attention module in the feature extraction stage and combining it with a two-stage decoupled training strategy, the model's sensitivity to positional information and training speed are improved. This includes adding a coordinate attention module after the CBM module, using pooling kernels of different sizes for feature aggregation, and adjusting the learning rate in both the front and back stages to optimize model parameters.
It significantly improves the accuracy and speed of buffalo facial recognition, reduces the cost of manual inspection, and realizes non-contact intelligent monitoring of individual buffaloes. It is applicable to intelligent breeding equipment and cloud recognition systems, filling the technological gap in the field of individual buffalo identification.
Smart Images

Figure CN122493489A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of buffalo facial recognition technology, and particularly relates to an improved YOLOV8n buffalo facial recognition model construction method and system. Background Technology
[0002] Precision farming is one of the important directions for the development of modern smart animal husbandry. In precision buffalo farming, individual identification is a fundamental link in realizing intelligent and large-scale farming. It provides identity information support for the formulation of individual feeding programs, milk production efficiency analysis, and health status monitoring. At the same time, it is also an important basis for management work such as traceability of buffalo-related products, disease prevention and control, and insurance claims.
[0003] Traditional buffalo identification relies primarily on manual observation methods such as ear tags, branding, neck chains, and barbs. These methods are not only time-consuming and labor-intensive but also prone to causing stress in buffaloes, increasing the risk of injury to both personnel and animals. While radio frequency identification (RFID) technology can automate the tracking of individual buffaloes, the durability and cost of electronic tags limit their widespread application in large-scale farming. Some researchers have attempted to use physiological characteristics such as the buffalo's nasal mirror pattern, iris, and retinal vessels for individual identification; however, the collection process for these biometric features is complex and inconvenient, making large-scale application in farms difficult.
[0004] With the widespread adoption of surveillance cameras in livestock farms and the development of computer vision technology, research on livestock individual recognition based on deep learning has become increasingly in-depth. Object detection algorithms such as Faster R-CNN, SSD, the YOLO series, and CenterNet, with their powerful feature extraction and target localization capabilities, have provided new technical pathways for buffalo individual recognition. Among them, the YOLO series algorithms have received widespread attention due to their fast detection speed and high accuracy. The optimizations in network structure and training strategies of YOLOv8 have provided strong support for building buffalo facial recognition models.
[0005] Among existing technologies, the Institute of Agricultural Information, Chinese Academy of Agricultural Sciences, and other institutions have proposed a cow face detection and recognition model, CowSiamese, based on Siamese networks and metric learning. This model first uses an improved YOLOv8s to detect cow face locations, and then identifies individual cows through feature metric learning, achieving a recognition accuracy of 99.4% on a self-built dataset. This technical approach employs an improved EfficientNet as the Siamese network backbone and introduces a 3D multi-scale attention mechanism to enhance feature discriminative power. It also proposes a Tri-Arcface loss function to optimize the geometric distribution of the feature space.
[0006] However, the existing technical solution still has the following technical shortcomings: First, the method adopts a two-stage detection and recognition framework, first detecting the position of the buffalo face and then performing feature measurement learning, which has high computational redundancy and limited inference speed, making it difficult to meet the real-time monitoring needs of the breeding site; Second, the 3D multi-scale attention mechanism introduced by the solution focuses on the feature interaction between channels, and has limited ability to encode spatial location information. When the buffalo's face shows changes in posture or partial occlusion, the model's localization accuracy for key discrimination regions is insufficient; Third, the method does not fully consider the parameter update requirements at different stages of model training and adopts a uniform training strategy, which leads to limited model convergence efficiency and needs to be improved in adaptability to small sample datasets.
[0007] Therefore, how to improve the location information perception capability and training efficiency of buffalo facial recognition models in complex scenarios while maintaining high recognition accuracy has become a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0008] To address the problems existing in the prior art, this invention provides an improved method for constructing a YOLOV8n buffalo facial recognition model.
[0009] This invention is implemented as follows: an improved method for constructing a YOLOv8n buffalo face recognition model includes:
[0010] Step 1, parameter settings: Set the training image size to 416 pixels × 416 pixels, the training batch size to 8, the total number of training cycles to 100, and save the weight parameters once after each training cycle.
[0011] Step 2: Improve training speed by pre-training the model. Freeze the backbone network parameters for the first 50 training epochs and set the learning rate to 1×10. -3 The backbone network parameters were unfrozen over the last 50 training cycles, with the learning rate set to 1×10⁻⁶. -4 ;
[0012] Step 3: In the feature extraction stage, a coordinate attention module is added after the CBM module. The coordinate attention module is used to encode channel relationships and long-range dependencies, including two sub-steps: coordinate information embedding and coordinate attention.
[0013] Furthermore, the coordinate information embedding sub-step includes: for the input image, using pooling kernels of different sizes, decoding each channel along the horizontal and vertical coordinate directions, and after feature aggregation in the two spatial directions, obtaining a pair of orientation-aware feature maps. Each feature map captures the long-range dependency of the input feature map along a spatial direction, and retains the positional information in the generated feature map.
[0014] Furthermore, the coordinate attention sub-step includes: applying the pair of direction-aware feature maps to the input feature map by multiplication to highlight the representation of the attention region.
[0015] Furthermore, the hardware environment for training the model uses an A6000 graphics processor with 12GB of video memory, an Ubuntu 16.04 operating system, and the PyTorch deep learning framework to build the model.
[0016] Another object of the present invention is to provide an improved YOLOv8n buffalo facial recognition model construction system for performing the method described above, characterized in that the improved YOLOv8n buffalo facial recognition model construction system comprises:
[0017] The parameter setting module is used to set the training image size to 416 pixels × 416 pixels, the training batch size to 8, the total number of training cycles to 100, and to save the weight parameters once after each training cycle.
[0018] The training module is used to improve training speed by pre-training the model. It freezes the backbone network parameters and sets the learning rate to 1×10⁻⁶ for the first 50 training epochs. -3 In the last 50 training cycles, the backbone network parameters were unfrozen and the learning rate was set to 1×10. -4 ;
[0019] The feature extraction module is used to add a coordinate attention module after the CBM module. The coordinate attention module is used to encode channel relationships and long-range dependencies, including two sub-steps: coordinate information embedding and coordinate attention.
[0020] Furthermore, the coordinate information embedding sub-step in the feature extraction module is specifically used for: for the input image, using pooling kernels of different sizes, decoding each channel along the horizontal and vertical coordinate directions, and after feature aggregation in the two spatial directions, obtaining a pair of orientation-aware feature maps, each feature map capturing the long-range dependency of the input feature map along a spatial direction, and retaining the position information in the generated feature map.
[0021] Furthermore, the coordinate attention sub-step in the feature extraction module is specifically used to: apply the pair of direction-aware feature maps to the input feature map through multiplication, highlighting the representation of the attention region.
[0022] Another objective of this invention is to provide a method for constructing a YOLOV8n buffalo face recognition model based on two-stage decoupled training. In the step of improving training speed through pre-training the model, the first 50 training cycles involve freezing the backbone network parameters and using a 1×10⁻⁶ training method. -3The classifier was trained using a learning rate of 10000, and the backbone network parameters were unfrozen and combined with 1×100000 for the last 50 training epochs. -4 The learning rate is used to fine-tune the backbone network.
[0023] Another objective of this invention is to provide a method for constructing a buffalo face recognition model based on coordinate information embedding. The coordinate information embedding sub-step includes: pooling each channel along the horizontal and vertical coordinate directions for the input image to generate a pair of orientation-aware feature maps. Each feature map captures a long-range dependency of a spatial direction and retains the position information in the feature map.
[0024] Another objective of this invention is to provide a coordinate attention construction method based on feature map fusion, wherein the coordinate attention sub-step includes: expanding the pair of direction-aware feature maps as attention weights, and applying them to the input feature maps through element-wise multiplication to enhance the position-sensitive feature representation.
[0025] Based on the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solution to be protected by this invention are as follows:
[0026] This invention constructs a dataset of facial images of 92 buffaloes in various poses. Based on the YOLOv8n model, coordinate information is incorporated into the feature map to increase the model's sensitivity to buffalo location, thereby improving the accuracy and speed of buffalo facial recognition and providing effective technical support for individual buffalo identification.
[0027] In the feature extraction stage, given that high-resolution feature maps are more sensitive to location, coordinate attention can be added after the CBM (Convolution-Batch Normalization-Mish) module to retain the location information of the buffalo image. This module consists of convolutional layers, batch regularization, and activation functions. The coordinate attention module encodes channel relationships and long-range dependencies using precise location information, and consists of two steps: coordinate information embedding and coordinate attention generation. First, for the input image X, pooling kernels of different sizes are used to decode each channel along the horizontal and vertical coordinate directions. After feature aggregation in the two spatial directions, a pair of orientation-aware feature maps are obtained. Each feature map captures the long-range dependencies of the input feature map along a spatial direction, thus preserving the location information in the generated feature map. Next, both feature maps are applied to the input feature map through multiplication to highlight the representation of the attention region.
[0028] In the detection head, two-dimensional channel features composed of coordinate information are stacked with high-level semantic features to enhance the positional sensitivity of the detection head. The key to coordinate convolution is the explicit addition of coordinate features before the convolutional layer, allowing for computation based on the combination of the convolutional layer and positional information. It adds two channels to the input data of the convolutional layer, representing the horizontal and vertical coordinate values of the feature map. For the horizontal coordinate feature channel, each pixel represents the horizontal coordinate value, with the first row filled with 0, the second row with 1, the third row with 2, and so on; the vertical coordinate channel is similar, and normalization is performed. The relative positions between features are preserved, facilitating convolutional access to feature coordinate information.
[0029] (1) The expected benefits and commercial value of the technical solution of this invention after transformation are as follows:
[0030] This technology enables non-contact intelligent monitoring of buffalo, significantly reducing the cost of manual inspections in large-scale buffalo farms. The results can be transformed into intelligent livestock monitoring equipment, cloud-based identification systems, and ranch management software, and promoted for application by buffalo farming enterprises, livestock equipment manufacturers, and smart livestock platforms. It possesses the potential for large-scale implementation and sustained commercial benefits, while also contributing to the digital upgrade of the buffalo farming industry, demonstrating significant economic and industrial value.
[0031] (2) The technical solution of this invention fills a technical gap in the industry both domestically and internationally:
[0032] Currently, there is limited research both domestically and internationally on facial recognition and lightweight estrus behavior detection for buffalo, particularly lacking deep learning models that are suitable for complex breeding environments and balance high accuracy with lightweight deployment. This invention achieves facial recognition for buffalo, filling a technological gap in the field of intelligent, contactless identification and behavioral monitoring of buffalo.
[0033] (3) The technical solution of the present invention solves a technical problem that people have long wanted to solve but have never been able to solve successfully:
[0034] For a long time, buffalo farming has faced challenges such as easily damaged individual tags, low efficiency of manual identification, untimely estrus observation, and high cost and difficulty in deploying traditional identification equipment at edge computing environments. The industry has long desired a non-contact, low-cost, and highly robust intelligent monitoring solution. This invention, through a lightweight deep learning model, significantly reduces the number of parameters and improves inference speed while maintaining accuracy, successfully solving the aforementioned long-standing and difficult-to-overcome technical problems.
[0035] (4) The technical solution of the present invention overcomes technical bias:
[0036] Traditional research on livestock visual recognition has largely focused on common livestock such as dairy cows and pigs. It is generally believed in the industry that the small differences in facial features and the complex farming environment of buffalo make high-precision individual identification and behavior detection difficult. This invention achieves lightweight, real-time intelligent recognition even in buffalo scenarios, providing a new technical approach for visual monitoring of similar ruminant livestock. Attached Figure Description
[0037] Figure 1 This is a flowchart of the improved YOLOV8n buffalo facial recognition model construction method provided in this embodiment of the invention.
[0038] Figure 2 This is a structural block diagram of the improved YOLOV8n buffalo facial recognition model construction system provided in this embodiment of the invention.
[0039] Figure 3 This is a schematic diagram of the structure of the improved YOLOv8n detection algorithm provided in the embodiments of the present invention.
[0040] Figure 4 This is a structural diagram of the cow face recognition model provided in an embodiment of the present invention.
[0041] Figure 5 This is a cow face recognition result image provided in an embodiment of the present invention.
[0042] Figure 6 This is a data enhancement effect diagram provided by an embodiment of the present invention.
[0043] Figure 7 This is a schematic diagram of the structure of the improved YOLOv8n detection algorithm provided in the embodiments of the present invention.
[0044] Figure 8 This is a structural diagram of the cow face recognition model provided in an embodiment of the present invention.
[0045] Figure 9 This is a comparison chart of the mAP metrics of different target detection algorithms provided in the embodiments of the present invention.
[0046] Figure 10 This is a comparison chart of the performance indicators of different target detection algorithms provided in the embodiments of the present invention.
[0047] Figure 11 This is a radar comparison chart of the performance of different target detection algorithms provided in the embodiments of the present invention. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0049] like Figure 1 As shown in the figure, an improved YOLOv8n buffalo face recognition model construction method provided by this invention includes the following steps:
[0050] S101, Parameter settings: Set the training image size to 416 pixels × 416 pixels, the training batch size to 8, the total number of training cycles to 100, and save the weight parameters once after each training cycle.
[0051] S102 improves training speed by using a pre-trained model, freezing backbone network parameters for the first 50 training cycles, and setting the learning rate to 1×10. -3 The backbone network parameters were unfrozen over the last 50 training cycles, with the learning rate set to 1×10⁻⁶. -4 ;
[0052] S103, In the feature extraction stage, a coordinate attention module is added after the CBM module. The coordinate attention module is used to encode channel relationships and long-range dependencies, including two sub-steps: coordinate information embedding and coordinate attention.
[0053] The coordinate information embedding sub-step provided in this embodiment of the invention includes: for the input image, using pooling kernels of different sizes, decoding each channel along the horizontal and vertical coordinate directions, and after feature aggregation in the two spatial directions, obtaining a pair of direction-aware feature maps, each feature map capturing the long-range dependency of the input feature map along a spatial direction, and retaining the position information in the generated feature map.
[0054] The coordinate attention sub-step provided in this embodiment of the invention includes: applying the pair of direction-aware feature maps to the input feature map by multiplication to highlight the representation of the attention region.
[0055] The hardware environment for training the model provided in this embodiment of the invention uses an A6000 graphics processor with 12GB of video memory, an Ubuntu 16.04 operating system, and the PyTorch deep learning framework to build the model.
[0056] Another object of the present invention is to provide an improved YOLOv8n buffalo facial recognition model construction system for performing the method described above, characterized in that the improved YOLOv8n buffalo facial recognition model construction system comprises:
[0057] The parameter setting module is used to set the training image size to 416 pixels × 416 pixels, the training batch size to 8, the total number of training cycles to 100, and to save the weight parameters once after each training cycle.
[0058] The training module is used to improve training speed by pre-training the model. It freezes the backbone network parameters and sets the learning rate to 1×10⁻⁶ for the first 50 training epochs. -3 In the last 50 training cycles, the backbone network parameters were unfrozen and the learning rate was set to 1×10. -4 ;
[0059] The feature extraction module is used to add a coordinate attention module after the CBM module. The coordinate attention module is used to encode channel relationships and long-range dependencies, including two sub-steps: coordinate information embedding and coordinate attention.
[0060] The coordinate information embedding sub-step in the feature extraction module provided in this embodiment of the invention is specifically used for: for the input image, using pooling kernels of different sizes, decoding each channel along the horizontal and vertical coordinate directions, and after feature aggregation in the two spatial directions, obtaining a pair of orientation-aware feature maps, each feature map capturing the long-range dependency of the input feature map along a spatial direction, and retaining the position information in the generated feature map.
[0061] The coordinate attention sub-step in the feature extraction module provided in this embodiment of the invention is specifically used to: apply the pair of direction-aware feature maps to the input feature map through multiplication to highlight the representation of the attention region.
[0062] Another objective of this invention is to provide a method for constructing a YOLOV8n buffalo face recognition model based on two-stage decoupled training. In the step of improving training speed through pre-training the model, the first 50 training cycles involve freezing the backbone network parameters and using a 1×10⁻⁶ training method. -3 The classifier was trained using a learning rate of 10000, and the backbone network parameters were unfrozen and combined with 1×100000 for the last 50 training epochs. -4 The learning rate is used to fine-tune the backbone network.
[0063] Another objective of this invention is to provide a method for constructing a buffalo face recognition model based on coordinate information embedding. The coordinate information embedding sub-step includes: pooling each channel along the horizontal and vertical coordinate directions for the input image to generate a pair of orientation-aware feature maps. Each feature map captures a long-range dependency of a spatial direction and retains the position information in the feature map.
[0064] Another objective of this invention is to provide a coordinate attention construction method based on feature map fusion, wherein the coordinate attention sub-step includes: expanding the pair of direction-aware feature maps as attention weights, and applying them to the input feature maps through element-wise multiplication to enhance the position-sensitive feature representation.
[0065] The model provided in this embodiment of the invention:
[0066] The hardware environment uses an A6000 GPU with 12GB of video memory, the operating system is Ubuntu 16.04, and the model is built using the PyTorch deep learning framework.
[0067] This invention provides an embodiment of improving training speed through pre-trained models:
[0068] First, freeze the backbone network parameters during the first 50 training iterations to train the classifier, setting the learning rate to 1×10. -3 A larger learning rate allows for faster parameter updates and quicker convergence; in the last 50 training iterations, the backbone network parameters are unfrozen, and the learning rate is set to 1×10. -4 At this point, by setting a smaller learning rate, the network can be fine-tuned to gradually approach the optimal solution.
[0069] The coordinate information embedding and coordinate attention provided in this embodiment of the invention:
[0070] First, for the input image X, pooling kernels of different sizes are used to decode each channel along the horizontal and vertical coordinate directions. After feature aggregation in the two spatial directions, a pair of orientation-aware feature maps are obtained. Each feature map captures the long-range dependencies of the input feature map along a spatial direction, thus preserving the positional information in the generated feature map. Then, the two feature maps are applied to the input feature map through multiplication to highlight the representation of the attention region.
[0071] like Figure 2 As shown in the figure, an improved YOLOv8n buffalo face recognition model construction system provided by this invention includes:
[0072] The parameter setting module is used for parameter settings. The training image size is set to 416 pixels × 416 pixels, the model is trained for 100 epochs, and the weight parameters are saved once after each epoch is completed in the experiment. After the model training is completed, there are a total of 100 model weight parameters, which are used to evaluate the performance of the trained model. The batch size is set to 8.
[0073] The training module is used to improve training speed through pre-trained models;
[0074] The feature extraction module is used to retain the location information of the buffalo image during the feature extraction stage. Coordinate attention can be added after the CBM (Convolution-Batch Normalization-Mish) module. This module consists of convolutional layers, batch regularization, and activation functions. The coordinate attention module encodes channel relationships and long-range dependencies with the help of accurate location information and is divided into coordinate information embedding and coordinate attention.
[0075] This invention uses the SSD model, CenterNet model, Faster R-CNN model, YOLOV8n model, CA-YOLOV8 model with coordinate attention added to the feature extraction network, and improved YOLOV8n model to recognize test set images.
[0076] It can be observed that the improved YOLOV8n buffalo face recognition model proposed in this invention outperforms other models. Specifically, from the classic YOLOv3 to the new generation YOLO series (v5n-v11n), all indicators show a continuous upward trend, demonstrating the value of iterative advancements in object detection model technology. Taking the core indicator mAP50 as an example, YOLOv3's mAP50 was only 0.321, while YOLOv8n improved to 0.814, and YOLOv10n reached 0.875, an increase of over 170%. Precision and recall also improved simultaneously; for example, YOLOv3's precision was 0.622 and recall was 0.521, while YOLOv10n improved to 0.878 and 0.87 respectively. This indicates that the new model has made significant progress in core capabilities such as feature extraction and object localization, resulting in more accurate recognition of buffalo faces and fewer missed detections.
[0077] However, YOLOv11n shows slight fluctuations compared to YOLOv10n, with mAP50 decreasing from 0.875 to 0.863 and recall from 0.87 to 0.843. This may be due to the lightweight design or network structure adjustments of v11n, resulting in slightly inferior adaptability to certain scenarios in this specific task (buffalo face detection) compared to v10n. RT-DETR, as a detection framework different from the YOLO series, significantly outperforms most lightweight YOLO models (v5n-v11n) in various metrics. Its precision reaches 0.942, recall 0.904, and mAP50 is 0.926, meaning that in buffalo face detection, it can not only accurately identify targets (fewer false positives) but also efficiently capture more real targets (fewer false negatives).
[0078] While the mAP50-95 is 0.596, which is higher than most lightweight YOLO models, it is significantly lower than its own mAP50. This indicates that it is stable at high confidence thresholds, but there is still room for improvement in the accuracy of its bounding box adaptation when facing multiple scenarios with different confidence requirements. However, overall it already possesses the basic capabilities for industrial-scale detection. The self-developed model "Ours" achieves top performance across all metrics, demonstrating a significant lead, and is particularly well-suited for buffalo face detection: its precision of 0.979 is near perfect, indicating that the model almost never misidentifies background elements (such as grass or debris around the buffalo horns) as buffalo faces, greatly reducing the ineffective costs of subsequent processing; its high recall of 0.956 means that even buffalo faces at long distances, from challenging angles, or with slight occlusions can be reliably detected, reducing missed detections of key targets; its mAP50 of 0.964 indicates extremely high accuracy in defining the bounding box of buffalo faces, precisely selecting the facial region and adapting to subsequent refined tasks such as facial feature extraction; most notably, its mAP50-95 of 0.683 far surpasses other models. This metric measures the model's comprehensive detection capability at different confidence thresholds. The high value indicates that "Ours" is highly adaptable to variables such as buffalo face size, pose, and shooting distance, and can handle diverse detection needs in complex outdoor scenes such as farmland and pastures, making it a customized, high-quality solution specifically optimized for buffalo faces.
[0079] yolov3 0.622 0.521 0.321 0.182 yolov5n 0.721 0.623 0.632 0.384 yolov7 0.785 0.684 0.742 0.483 yolov8n 0.829 0.743 0.814 0.541 yolov10n 0.878 0.87 0.875 0.571 yolo11n 0.879 0.843 0.863 0.556 RT-DETR 0.942 0.904 0.926 0.596 Ours 0.979 0.956 0.964 0.683
[0080] Example 1
[0081] An improved YOLOv8n buffalo face recognition model construction method based on two-stage decoupled training is proposed, and the specific implementation is as follows: A total of 5000 buffalo face images with different poses, lighting conditions, and occlusions are collected and divided into training and validation sets at an 8:2 ratio. During the parameter setting phase, all training images are uniformly scaled to 416 pixels × 416 pixels, with a batch size of 8 and a total of 100 training epochs. A YOLOv8n model pre-trained on the ImageNet dataset is used as the initial weights. In the first 50 training epochs, all parameters of the backbone network are frozen, and only the classifier part is trained with a learning rate of 0.001. The Adam optimizer is used to update the parameters, allowing the classifier to quickly adapt to the buffalo facial feature distribution. At the beginning of the 51st training epoch, all parameters of the backbone network are unfrozen, the learning rate is adjusted to 0.0001, and the entire network is fine-tuned until the 100th training epoch is completed. The model weights are saved once after each epoch. Experimental results show that after adopting this two-stage decoupled training strategy, the average accuracy of the model on the validation set reaches 94.3%, which is 4.7 percentage points higher than the traditional end-to-end training method, and the training time is shortened by 18%, effectively solving the problems of model convergence instability and overfitting under small sample conditions.
[0082] Example 2
[0083] A method for constructing a buffalo facial recognition model based on coordinate information embedding is proposed, introducing a coordinate attention mechanism in the feature extraction stage. The input feature map has a size of 416 pixels × 416 pixels and 64 channels. During the coordinate information embedding process, average pooling is performed on each channel along both the horizontal and vertical directions to generate two orientation-aware feature maps with sizes of 416 pixels × 1 pixel and 1 pixel × 416 pixels, respectively. Each feature map captures long-range dependencies along a spatial direction; for example, the horizontal feature map retains the relative position information between the left and right eyes in the buffalo facial image, and the vertical feature map retains the longitudinal texture distribution information from the forehead to the nose. These two feature maps are then expanded in channel dimension through convolutional layers with a kernel size of 1, maintaining the channel number relative to the input feature map. Figure 1 The attention weights are then generated using the Sigmoid activation function. Finally, the generated attention weights are multiplied element-wise with the input feature map to focus the network on discriminative facial regions. Experiments show that adding the coordinate attention module improves the model's accuracy in locating key facial points such as eyes, nostrils, and horn bases by 12.6%, and improves the recall rate for side profiles and partially occluded images by 9.8%.
[0084] Example 3
[0085] A coordinate attention construction method based on feature map fusion is proposed to improve the feature representation capability of YOLOv8n in buffalo face recognition tasks. Specifically, a coordinate attention module is inserted after the CBM module. After processing by the CBM module, the input feature map has a size of 52 pixels × 52 pixels and 128 channels. In the coordinate information embedding stage, adaptive average pooling is performed along the height and width directions respectively to obtain feature vectors in two directions, each with dimensions of 128 × 1 × 52 and 128 × 52 × 1. These two vectors are concatenated and then passed through a convolutional layer with a kernel size of 1, a batch regularization layer, and a non-linear activation function to achieve cross-directional feature interaction. Subsequently, the feature map is re-split into two independent attention tensors along the spatial dimension, and each tensor is passed through a convolutional layer with a kernel size of 1 to adjust the number of channels, and then normalized using the Sigmoid function. Finally, the attention weights of the two directions are multiplied by the original input feature map to form a direction-aware enhanced feature map. This module is embedded into multiple layers of the YOLOv8n backbone network and neck network, enabling the model to retain positional information at multiple scales. Experiments show that compared to the traditional channel attention mechanism, this module improves the average accuracy by 6.2% in the buffalo face recognition task, while increasing the number of parameters by only 0.2 megabytes, meeting the deployment requirements of edge computing devices.
[0086] Example 4
[0087] This paper presents a method for constructing a buffalo facial recognition model for complex scenarios, optimizing for issues such as facial occlusion, pose changes, and uneven lighting in group farming environments. In the data preprocessing stage, a mosaic data augmentation method is used to stitch together four buffalo facial images from different scenes into a single 416-pixel × 416-pixel image, enriching background diversity. The model construction employs a two-stage decoupled training strategy: the backbone network is frozen for the first 50 cycles with a learning rate of 0.001, and unfrozen for the next 50 cycles with a learning rate of 0.0001. A cosine annealing strategy is used at the 75th cycle to dynamically adjust the learning rate to improve convergence accuracy. In the feature extraction part, coordinate attention modules are embedded after the second and fourth CBM modules of the backbone network and before sampling on the neck network. Each module independently calculates orientation-aware feature maps and performs feature fusion. Experiments use a self-built dataset containing 8000 facial images of 120 buffaloes, with an average of 66 images collected from different angles per buffalo. Validation results show that the model achieves an individual recognition accuracy of 96.7% on the test set, and maintains an accuracy of 89.2% even with 30% image occlusion, outperforming the baseline model without coordinate attention by 12.5 percentage points. The model's inference time per image on the A6000 GPU is 12 milliseconds, meeting real-time monitoring requirements.
[0088] It should be noted that embodiments of the present invention can be implemented in hardware, software, or a combination of both. The hardware portion can be implemented using dedicated logic; the software portion can be stored in memory and executed by a suitable instruction execution system, such as a microprocessor or dedicated-design hardware. Those skilled in the art will understand that the above-described devices and methods can be implemented using computer-executable instructions and / or included in processor control code, for example, such code provided on a carrier medium such as a disk, CD, or DVD-ROM, a programmable memory such as read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. The devices and modules of the present invention can be implemented by hardware circuitry such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, or programmable hardware devices such as field-programmable gate arrays, programmable logic devices, etc., or by software executed by various types of processors, or by a combination of the above-described hardware circuitry and software, such as firmware.
[0089] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications, equivalent substitutions, and improvements made by those skilled in the art within the scope of the technology disclosed in the present invention, and within the spirit and principles of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. An improved method for constructing a YOLOv8n buffalo facial recognition model, characterized in that, Includes the following steps: Step 1, parameter settings: Set the training image size to 416 pixels × 416 pixels, the training batch size to 8, the total number of training cycles to 100, and save the weight parameters once after each training cycle. Step 2, improve the training speed by pre-training model, freeze the backbone network parameters in the first 50 training periods, and set the learning rate to 1x10 -3 ; unfreeze the backbone network parameters in the last 50 training periods, and set the learning rate to 1x10 -4 ; Step 3: In the feature extraction stage, a coordinate attention module is added after the CBM module. The coordinate attention module is used to encode channel relationships and long-range dependencies, including two sub-steps: coordinate information embedding and coordinate attention.
2. The improved YOLOv8n buffalo face recognition model construction method as described in claim 1, characterized in that, The coordinate information embedding sub-step includes: for the input image, using pooling kernels of different sizes, decoding each channel along the horizontal and vertical coordinate directions, and after feature aggregation in the two spatial directions, obtaining a pair of orientation-aware feature maps. Each feature map captures the long-range dependencies of the input feature map along a spatial direction, and retains the positional information in the generated feature map.
3. The improved YOLOv8n buffalo face recognition model construction method as described in claim 2, characterized in that, The coordinate attention sub-step includes: applying the pair of orientation-aware feature maps to the input feature map by multiplication to highlight the representation of the attention region.
4. The improved YOLOv8n buffalo face recognition model construction method as described in claim 1, characterized in that, The hardware environment for training the model uses an A6000 graphics processor with 12GB of video memory, an Ubuntu 16.04 operating system, and the PyTorch deep learning framework to build the model.
5. An improved YOLOv8n buffalo facial recognition model construction system, used to execute the method of claim 1, characterized in that, The improved YOLOV8n buffalo facial recognition model construction system includes: The parameter setting module is used to set the training image size to 416 pixels × 416 pixels, the training batch size to 8, the total number of training cycles to 100, and to save the weight parameters once after each training cycle. The training module is used to improve the training speed through a pre-trained model, freeze backbone network parameters in the first 50 training periods and set a learning rate to 1x10 -3 -4 in the last 50 training periods and set a learning rate to 1x10 -4 -4. The feature extraction module is used to add a coordinate attention module after the CBM module. The coordinate attention module is used to encode channel relationships and long-range dependencies, including two sub-steps: coordinate information embedding and coordinate attention.
6. The improved YOLOV8n buffalo facial recognition model construction system as described in claim 5, characterized in that, The coordinate information embedding sub-step in the feature extraction module is specifically used for: for the input image, using pooling kernels of different sizes, decoding each channel along the horizontal and vertical coordinate directions, and after feature aggregation in the two spatial directions, obtaining a pair of orientation-aware feature maps. Each feature map captures the long-range dependency of the input feature map along a spatial direction, and retains the position information in the generated feature map.
7. The improved YOLOV8n buffalo face recognition model construction system as described in claim 6, characterized in that, The coordinate attention sub-step in the feature extraction module is specifically used to: apply the pair of direction-aware feature maps to the input feature map through multiplication to highlight the representation of the attention region.
8. A method for constructing a YOLOv8n buffalo face recognition model based on two-stage decoupled training, characterized in that, Referring to claim 1, in the step of improving training speed through pre-trained models, the first 50 training cycles involve freezing the backbone network parameters and using a 1×102 model. -3 The classifier was trained using a learning rate of 10000, and the backbone network parameters were unfrozen and combined with 1×100000 for the last 50 training epochs. -4 The learning rate is used to fine-tune the backbone network.
9. A method for constructing a buffalo facial recognition model based on coordinate information embedding, characterized in that, Referring to claim 1, the coordinate information embedding sub-step includes: pooling each channel along the horizontal and vertical coordinate directions for the input image to generate a pair of orientation-aware feature maps, each feature map capturing a long-range dependency of a spatial direction and retaining the position information in the feature map.
10. A coordinate attention construction method based on feature map fusion, characterized in that, Referring to claim 9, the coordinate attention sub-step includes: expanding the pair of orientation-aware feature maps as attention weights, and applying them to the input feature maps through element-wise multiplication to enhance the position-sensitive feature representation.