Yolov8-based yak target tracking detection and cow face recognition method

By combining YOLOv8 with a custom CNN model, and integrating hierarchical feature extraction and confidence fusion, the robustness and efficiency issues in livestock identification are solved, achieving efficient and accurate cattle detection and classification, suitable for applications with limited resources.

CN122135400AInactive Publication Date: 2026-06-02XICHANG COLLEGE

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XICHANG COLLEGE
Filing Date
2026-02-12
Publication Date
2026-06-02
Estimated Expiration
Not applicable · inactive patent

Smart Images

  • Figure CN122135400A_ABST
    Figure CN122135400A_ABST
Patent Text Reader

Abstract

This application relates to the field of object detection technology, and more particularly to a method for yak target tracking and cow face recognition based on YOLOv8. The method includes acquiring an image containing a yak to be identified; using a pre-trained YOLOv8 object detection model to track the target in the image and determine the best candidate detection box for locating the cow face region; determining the region of interest (ROI) of the cow face based on the best candidate detection box; and using a CNN network model configured with multiple convolutions to extract hierarchical features from low-level edge features to high-level semantic features within the ROI, and mapping the hierarchical features into a category probability distribution to obtain the recognition result, including the cow face bounding box and breed distribution. Through multi-module collaborative work and adaptive processing strategies, efficient and accurate individual cow identification is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of target detection technology, and more specifically, to a method for yak target tracking and detection and yak face recognition based on YOLOv8. Background Technology

[0002] Currently, livestock identification and management systems play a crucial role in modern animal husbandry. While traditional ear tag identification and RFID technologies can achieve basic identification, they suffer from problems such as easy tag detachment, high cost, and complex operation. With the development of computer vision technology, image-based livestock identification methods are gradually gaining attention, but existing technologies still face multiple challenges in practical applications.

[0003] First, traditional image processing methods are not robust in complex natural environments; changes in lighting, occlusions, and pose variations severely affect recognition accuracy. Second, existing deep learning models have a large number of parameters and high computational complexity, making them difficult to deploy on resource-constrained edge devices. Third, the facial features of different cattle breeds vary greatly, making it difficult for a single model to adapt to the recognition needs of different breeds. In addition, real-time detection and recognition are inefficient, and the processing speed of existing systems cannot meet the actual application needs of large-scale farms. Finally, the system integration is low; the modules for detection, recognition, and result output lack effective coordination, making it difficult to form a complete solution.

[0004] Therefore, there is an urgent need for an intelligent cow face recognition system that integrates target detection, feature extraction, and classification recognition to solve many technical bottlenecks in existing technologies. Summary of the Invention

[0005] In view of this, this application provides a yak target tracking and detection and cow face recognition method based on YOLOv8, which achieves efficient and accurate individual cow identification through module collaborative work and adaptive processing strategies.

[0006] A method for yak target tracking and face recognition based on YOLOv8 includes:

[0007] Obtain an image containing a yak to be identified;

[0008] The pre-trained YOLOv8 object detection model is used to track objects in the image to be identified, and the best candidate detection box for locating the cow face region is determined.

[0009] The region of interest for the cow face is determined based on the optimal candidate detection box;

[0010] In the region of interest of the cow face, a hierarchical feature model with multiple convolutions is used to extract hierarchical features from low-level edge features to high-level semantic features. The hierarchical feature is then mapped and converted into a category probability distribution to obtain the recognition result, including the cow face bounding box and breed distribution.

[0011] One possible implementation involves using a pre-trained YOLOv8 object detection model to track objects in the image to be identified, determining the optimal candidate detection box for locating the cow face region, including:

[0012] Forward propagation is performed using the YOLOv8 object detection model to generate candidate detection boxes;

[0013] The optimal candidate detection box is obtained by removing redundant detection boxes with high overlap using the non-maximum suppression algorithm (NMS).

[0014] In one possible implementation, after the optimal candidate detection box is generated by the YOLOv8 object detection model, the method further includes:

[0015] Iterate through each detection box and crop out the corresponding cow face region of interest from the image to be identified based on the detection box coordinates;

[0016] Color space conversion and PIL image conversion are performed on the cropped region of interest of the cow's face. The converted image is used to extract the hierarchical features.

[0017] One possible implementation utilizes a CNN network model configured with multiple convolutional layers to extract hierarchical features from low-level edge features to high-level semantic features, including:

[0018] The preprocessed region of interest of the cow face is input into the CNN network model configured with multiple convolutions. Local features are extracted sequentially through each convolutional layer. After each convolutional layer extracts features, data normalization and nonlinear transformation are performed through a batch normalization layer and an activation function layer to gradually extract hierarchical features from low-level edge features to high-level semantic features.

[0019] The hierarchical features are subjected to linear mapping transformation and Dropout regularization using a fully connected layer.

[0020] The linear output of the fully connected layer is converted into a multi-class probability distribution using the Softmax function to obtain the recognition result.

[0021] In one possible implementation, the recognition result further includes the detection confidence score output by the YOLOv8 object detection model and the classification confidence score output by the CNN network model; wherein the detection confidence score is used to determine the degree of certainty that the current cow face bounding box contains a cow face, and the classification confidence score is used to characterize the reliability of the cow face in the current cow face bounding box being identified as a specific breed.

[0022] In one possible implementation, after obtaining the recognition result including the detection confidence and classification confidence, the method further includes:

[0023] The product of the detection confidence and the classification confidence is used as the comprehensive confidence. The cow face bounding boxes and breed distribution in the recognition results are then filtered out, and recognition results whose cow face bounding boxes / breed distributions do not meet the comprehensive confidence.

[0024] In one possible implementation, after obtaining the recognition result, the method further includes:

[0025] Based on the recognition results, the yak target is visually labeled on the image to be recognized, generating a recognition image containing the yak face bounding box and breed label.

[0026] Compared with the prior art, the technical solution of this application has the following beneficial effects:

[0027] This technical solution achieves accurate detection and breed classification of yaks' faces through the collaboration of a dual model of YOLOv8 and a custom CNN, while ensuring process stability through an anomaly fallback mechanism. By combining techniques such as batch normalization and Dropout, the model training efficiency and generalization ability are optimized. Furthermore, highly reliable recognition results are selected through confidence product fusion, which not only improves the accuracy of yak identification but also enables intuitive presentation of results, traceability of processes, and standardized data management, comprehensively enhancing the system's practicality, ease of use, and adaptability for deployment. Attached Figure Description

[0028] Figure 1 The flowchart of the algorithm for object detection and CNN feature extraction based on YOLOv8 provided in this application.

[0029] Figure 2 The flowchart illustrates a yak target tracking and detection and cow face recognition method based on YOLOv8, provided in Embodiment 1 of this application.

[0030] Figure 3 This is a schematic diagram of the YOLOv8 object detection architecture provided in Embodiment 1 of this application.

[0031] Figure 4This is a flowchart of feature extraction and variety classification based on a CNN network model, provided in Embodiment 1 of this application.

[0032] Figure 5 This is a flowchart of the auxiliary enhancement processing method provided in Embodiment 3 of this application. Detailed Implementation

[0033] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the embodiments of this application. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0034] To address the aforementioned technical issues, this application proposes a dual-model collaborative architecture combining YOLOv8 object detection and a custom CNN classification. Figure 1 As shown, in practical applications, the system equipped with the aforementioned dual models is used to identify different breeds of cattle in complex environments, achieving end-to-end intelligent processing from cattle face localization to breed identification. Upon startup, the system automatically performs device detection and runtime environment configuration, selects either a GPU or CPU as the computing device, creates an output directory structure, and initializes a log system to record the running status.

[0035] The following detailed description of the yak target tracking and detection and cow face recognition method based on YOLOv8 provided in this application is illustrated through specific embodiments.

[0036] Example 1

[0037] See Figure 2 This is a flowchart illustrating a yak target tracking and detection and cow face recognition method based on YOLOv8, provided in Embodiment 1 of this application. The method is implemented based on a pre-trained YOLOv8 target detection model and a CNN network model. The CNN network model is configured with multiple convolutional layers.

[0038] like Figure 2 As shown, the specific implementation steps of the above method include:

[0039] Step 101: Obtain an image containing a yak to be identified.

[0040] Step 102: Use the pre-trained YOLOv8 object detection model to perform object tracking on the above image to be identified, and determine the best candidate detection box for locating the cow face region.

[0041] In this embodiment, the image to be identified, input to the YOLOv8 object detection model, is first preprocessed, including size normalization and color space conversion. Then, forward propagation is performed through the YOLOv8 network to generate candidate detection boxes. Finally, non-maximum suppression (NMS) is used to remove redundant detection boxes with high overlap, outputting the best candidate detection boxes.

[0042] Specifically, forward propagation via the YOLOv8 network includes:

[0043] First, calculate the mean of the current batch of data. , is represented as:

[0044] ,

[0045] Where m is the number of samples in the current batch. Let be the data value of the i-th sample.

[0046] Calculate the variance of the current batch of data , is represented as:

[0047] ,

[0048] The feature values ​​of individual samples are then standardized to obtain normalized feature values. , is represented as:

[0049] ,

[0050] Where e is a preset local constant, typically taking the value of 1. This is to prevent division by zero errors.

[0051] The normalized eigenvalues ​​are scaled and offset to obtain the final output of the batch normalization transform. , is represented as:

[0052] ,

[0053] In the formula, γ and β are learnable scaling and offset parameters that can preserve the model's own feature representation capabilities.

[0054] The above method uses non-maximum suppression (NMS) to remove redundant detection boxes with high overlap, outputting the best candidate detection boxes. The retention criteria for candidate detection boxes are expressed as follows:

[0055] ,

[0056] In the formula, This represents the i-th bounding box. This represents the j-th bounding box. Represents detection box Bi and B j The area of ​​intersection Represents the detection box and The area of ​​the union, This indicates the set non-maximum suppression threshold.

[0057] Step 103: Determine the region of interest for the cow face based on the above optimal candidate detection boxes.

[0058] like Figure 3 As shown, after completing the YOLOv8 prediction, it first checks if the number of detection boxes is greater than 0. If the number of detection boxes is 0, an empty result is recorded directly. If the number of detection boxes is greater than 0, each detection box is traversed, and the corresponding cow face region of interest is cropped from the image to be recognized based on the detection box coordinates.

[0059] Furthermore, a color space conversion is performed on the cropped region of interest of the cow's face, converting the BGR format to RGB format. The converted cow's face region is then converted to PIL image format, and size normalization and data normalization are performed sequentially. The size normalization process scales the image to a standard size of 224×224 pixels to facilitate input into the CNN network model for feature extraction.

[0060] Step 104: In the above-mentioned cow face region of interest, use a CNN network model to extract hierarchical features from low-level edge features to high-level semantic features.

[0061] The aforementioned CNN network model employs a deep convolutional neural network architecture, including multiple convolutional layers, pooling layers, and activation function layers. The network design fully considers the balance between computational efficiency and feature representation capability, employing a hierarchical feature extraction mechanism to progressively abstract and refine features from low-level edge features to high-level semantic features.

[0062] In this embodiment, the preprocessed region of interest (ROI) of the cow face is input into the CNN network model configured with multiple convolutional layers. Local features are extracted sequentially through each convolutional layer. After feature extraction at each layer, data normalization is performed by a batch normalization layer, and nonlinear transformation is performed by an activation function layer. Pooling layers then reduce the feature map size and enhance feature translation invariance, progressively extracting hierarchical features from low-level edge features to high-level semantic features. Subsequently, fully connected layers perform linear mapping transformation on these hierarchical features, and Dropout regularization randomly disables some neurons to prevent overfitting. The Softmax function converts the linear output of the fully connected layers into a multi-class probability distribution, yielding the aforementioned recognition result. Specifically, this is expressed as follows:

[0063] ,

[0064] Specifically, see Figure 4 This is a flowchart illustrating feature extraction and variety classification based on a CNN network model, provided in an embodiment of this application. Figure 4 As shown, the input preprocessed 3-channel 224×224 pixel cow face image is first subjected to a 3×3 convolutional kernel and a 64-channel convolutional layer for initial feature extraction, and then processed by batch normalization (BN) and ReLU activation function layers. Subsequently, the features are refined again by a 3×3 convolutional kernel and a 64-channel convolutional layer, and similarly processed by batch normalization and ReLU activation function layers. Finally, the feature map size is reduced by a 2×2 max pooling layer.

[0065] The next feature extraction process begins. Texture features are extracted using a 3×3 convolutional kernel and 128-channel convolutional layer. After batch normalization and ReLU activation, these features are further enhanced using another 3×3 convolutional kernel and 128-channel convolutional layer, followed by batch normalization, ReLU activation, and 2×2 max pooling. Local features are then extracted using a 3×3 convolutional kernel and 256-channel convolutional layer. After batch normalization and ReLU activation, these local features are further refined using a 3×3 convolutional kernel and 256-channel convolutional layer, followed by batch normalization, ReLU activation, and 2×2 max pooling.

[0066] Finally, high-level semantic features are extracted through a 3×3 convolutional kernel and a 512-channel convolutional layer. After batch normalization, ReLU activation function layer and 2×2 max pooling layer processing, the feature format is transformed through adaptive average pooling layer and flattening layer to complete the hierarchical extraction from low-level edge features to high-level semantic features.

[0067] The CNN convolutional neural network model extracts local features from the input image through a sliding window, as follows:

[0068] ,

[0069] in, To output the feature map at position (i,j) of the first... The feature values ​​of each channel. X is the input feature map, with dimensions H×W×C (height×width×number of channels). K is the convolution kernel weight, with dimensions k×k×C×F (kernel size×kernel size×input channels×output channels). For the first The bias term for each output channel.

[0070] The rectified linear unit ReLU is represented as:

[0071] ,

[0072] The output is 0 when the input is negative, and retains the original value when the input is positive.

[0073] Pooling layers are specifically used to aggregate and statistically analyze local feature regions, reducing feature map size, model parameters, and computational cost while enhancing the translation invariance of features. The pooling methods described in this application include max pooling, average pooling, and global average pooling (implemented using adaptive pooling in the code), with specific definitions and calculation methods as follows:

[0074] Max pooling is represented as:

[0075] ,

[0076] Average pooling is expressed as:

[0077] ,

[0078] Global average pooling (using adaptive pooling in the code) is represented as:

[0079] ,

[0080] Where k is the pooling window size, which is usually 2×2. This is the sliding step size, usually 2. Indicates the position of the input image X. Location, passage pixel values ​​on Represents the i-th row, j-th column, and i-th column. The element value in the channel.

[0081] Step 105: Convert the above hierarchical feature mapping into a category probability distribution to obtain the recognition results, including the cow face bounding box and breed distribution.

[0082] Specifically, this application utilizes a fully connected layer to perform linear mapping transformation and Dropout regularization on the aforementioned hierarchical features. Furthermore, the linear output of the fully connected layer is converted into a multi-class probability distribution using the Softmax function to obtain the aforementioned recognition results.

[0083] Specifically, the hierarchical features extracted by the convolutional layer are linearly mapped, as follows:

[0084] ,

[0085] in, This is the linear output of the l-th layer. This is the weight matrix, with dimension 1. This is the activation output of the previous layer. This is the bias vector. In the actual code implementation, the fully connected layer above adopts a three-layer cascade structure. The first layer converts the input 512×7×7 dimensional cow face features into a 4096-dimensional feature vector for learning a higher-level abstract representation. The second layer compresses the 4096-dimensional features into 1024-dimensional features to extract core information and reduce computational complexity. The third layer converts the 1024-dimensional features into a vector of breed categories, where each element corresponds to the original classification score (logits) of a yak breed. These scores can be directly used for subsequent loss calculations or Softmax probability transformations.

[0086] The Dropout regularization process described above is expressed as follows:

[0087] ,

[0088] In the formula, p is the dropout probability, which is 0.5 in the code, meaning 50% of neurons are randomly turned off. This prevents overfitting and improves the model's generalization ability. This represents the output of the i-th neuron in the l-th layer. This represents the weighted sum of the i-th neuron in the l-th layer.

[0089] The linear output of the fully connected layer described above is converted into a multi-class probability distribution using the Softmax function, as follows:

[0090] ,

[0091] in, Let K be the logit score for the j-th category. K is the total number of categories, i.e., the number of cattle breeds. The output should satisfy... The network output is then converted into a probability distribution. Represents the raw score for the j-th class. Perform exponentiation.

[0092] Furthermore, after obtaining valid recognition results for yak target detection and yak face recognition, this application can also draw precise rectangular annotation boxes at the corresponding positions in the image based on the yak face bounding box coordinates contained in the recognition results to locate the yak target. Simultaneously, the recognized yak breed classification results are labeled next to the bounding box, clearly associating the yak face region with the corresponding breed information. Finally, a recognition image is generated that integrates the yak face bounding box localization annotation and the breed category text annotation, intuitively presenting the detection and classification results of the yak target.

[0093] Example 2

[0094] Compared to Embodiment 1, Embodiment 2 of this application obtains recognition results that also include the detection confidence score output by the YOLOv8 object detection model and the classification confidence score output by the CNN network model. The detection confidence score characterizes the degree of certainty that the currently identified cow face bounding box contains a cow face. The classification confidence score characterizes the reliability of classifying the cow face within the currently identified cow face bounding box as belonging to a specific breed. Based on this, Embodiment 2 of this application proposes a confidence score fusion screening strategy based on the independent event assumption in probability theory to select recognition results that perform well in both object detection and feature classification stages, thereby improving the overall reliability of the recognition system.

[0095] Specifically, the coordinates of the cow face bounding box output by the YOLOv8 object detection model are represented as follows:

[0096] ,

[0097] In the formula, The coordinates of the top left corner The coordinates are the bottom right corner.

[0098] The detection confidence level is calculated and expressed as:

[0099] ,

[0100] In the formula, This indicates the probability that the bounding box contains the target. This represents the intersection-union ratio (IoU) between the predicted bounding box and the ground truth bounding box.

[0101] The overall confidence level is the product of the detection confidence level and the classification confidence level, expressed as:

[0102] ,

[0103] In the formula, This represents the final overall confidence level. This indicates the classification confidence level. This represents a multi-class probability distribution.

[0104] Using the above comprehensive confidence level, the cow face bounding boxes and breed distribution in the identification results are screened, and identification results that do not meet the above comprehensive confidence level are eliminated.

[0105] Example 3

[0106] This application's third embodiment adds an auxiliary enhancement process after yak target detection and cow face recognition are completed, based on embodiments one and two.

[0107] See Figure 5 This is a flowchart of the auxiliary enhancement processing method provided in Embodiment 3 of this application. Figure 5 As shown, the auxiliary enhancement processing specifically includes five processes: anomaly fallback, visualization enhancement, log enhancement, statistical management, and persistence enhancement.

[0108] In the fallback module, if the YOLO model fails to load, the system will automatically fall back to the backup yolov8n.pt model to ensure the detection process continues. If image opening fails (Image.open fails), a 224×224 black image will be generated as an alternative input to avoid interruption of the process.

[0109] In the visualization enhancement module, the system randomly samples eight images from the already labeled recognition images and reads the annotated images. A 2×4 grid display is generated using the plt tool, and a Chinese title is added using the SimHei font, achieving an intuitive and well-organized presentation of the recognition results.

[0110] The log enhancement module records logs at the Logging.INFO level and appends timestamps to the console output, enabling process traceability.

[0111] The statistics management module will iterate through the recognition results (recognition_results), count the number of recognitions for each yak breed (breed), calculate the mean and variance, and then generate and print a report.

[0112] The persistence enhancement module saves the identification results, which include the breed mapping relationship, in JSON format. It also sets the indentation to 2 and disables ASCII encoding restrictions to ensure the readability and integrity of data storage, providing comprehensive data support for the practical application of the yak identification system.

[0113] Compared with the prior art, the technical solution provided by the above embodiments of this application has the following beneficial effects:

[0114] The cattle face recognition system and method provided in this application integrate two core modules: object detection (YOLOv8) and feature classification (CNN), forming a complete workflow from input image to final breed identification, requiring no manual intervention. It employs a clear class structure design, separating functional modules such as dataset management, model definition, and the recognition system, resulting in a clear code structure that facilitates maintenance and expansion. It can automatically scan image files in a specified directory, automatically handling all stages including detection, classification, annotation, and result saving, significantly reducing the need for manual operation. It includes comprehensive anomaly capture and handling logic, such as default image return when image loading fails and backup solutions when model loading fails, enhancing the system's robustness. In addition to providing basic recognition functions, it also includes detailed statistical report generation, visualization, confidence score calculation, and other analytical tools, providing multi-dimensional support for result evaluation.

[0115] It generates various output formats, including labeled visualizations, structured result files in JSON format, and console statistical reports, to meet diverse usage needs. Features such as processing quantity limits, automatic device detection (CPU / GPU), and memory optimization ensure stable operation across different hardware environments. Employing ImageNet standard image preprocessing workflows and normalization parameters guarantees consistency and compatibility of model inputs. Adjustable parameters such as the maximum number of images processed and the number of samples displayed allow users to flexibly configure system operation according to their specific needs.

[0116] Although embodiments of this application have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A method for yak target tracking and yak face recognition based on YOLOv8, characterized in that, include: Obtain an image containing a yak to be identified; The pre-trained YOLOv8 object detection model is used to track objects in the image to be identified, and the best candidate detection box for locating the cow face region is determined. The region of interest for the cow face is determined based on the optimal candidate detection box; In the region of interest of the cow face, a hierarchical feature model with multiple convolutions is used to extract hierarchical features from low-level edge features to high-level semantic features. The hierarchical feature is then mapped and converted into a category probability distribution to obtain the recognition result, including the cow face bounding box and breed distribution.

2. The yak target tracking and cow face recognition method based on YOLOv8 according to claim 1, characterized in that, The image to be identified is tracked using a pre-trained YOLOv8 object detection model to determine the optimal candidate detection box for locating the cow face region, including: Forward propagation is performed using the YOLOv8 object detection model to generate candidate detection boxes; The optimal candidate detection box is obtained by removing redundant detection boxes with high overlap using the non-maximum suppression algorithm (NMS).

3. The YOLOv8 yak target tracking and yak face recognition method according to claim 1, characterized in that, After the optimal candidate detection box is generated by the YOLOv8 object detection model, the method further includes: Iterate through each detection box and crop out the corresponding cow face region of interest from the image to be identified based on the detection box coordinates; Color space conversion and PIL image conversion are performed on the cropped region of interest of the cow's face. The converted image is used to extract the hierarchical features.

4. The yak target tracking and cow face recognition method based on YOLOv8 according to claim 1, characterized in that, A hierarchical feature extraction method, from low-level edge features to high-level semantic features, is used with a CNN network model configured with multiple convolutions, including: The preprocessed region of interest of the cow face is input into the CNN network model configured with multiple convolutions. Local features are extracted sequentially through each convolutional layer. After each convolutional layer extracts features, data normalization and nonlinear transformation are performed through a batch normalization layer and an activation function layer to gradually extract hierarchical features from low-level edge features to high-level semantic features. The hierarchical features are subjected to linear mapping transformation and Dropout regularization using a fully connected layer. The linear output of the fully connected layer is converted into a multi-class probability distribution using the Softmax function to obtain the recognition result.

5. The yak target tracking and cow face recognition method based on YOLOv8 according to claim 1, characterized in that, The recognition result also includes the detection confidence score output by the YOLOv8 object detection model and the classification confidence score output by the CNN network model; wherein, the detection confidence score is used to characterize the degree of certainty that the current cow face bounding box contains a cow face, and the classification confidence score is used to characterize the reliability of the cow face in the current cow face bounding box being identified as a specific breed.

6. The yak target tracking and cow face recognition method based on YOLOv8 according to claim 5, characterized in that, After obtaining the recognition result including the detection confidence and classification confidence, the method further includes: The product of the detection confidence and the classification confidence is used as the comprehensive confidence. The cow face bounding boxes and breed distribution in the recognition results are then filtered out, and recognition results whose cow face bounding boxes / breed distributions do not meet the comprehensive confidence.

7. The yak target tracking and cow face recognition method based on YOLOv8 according to claim 1, characterized in that, After obtaining the recognition result, the method further includes: Based on the recognition results, the yak target is visually labeled on the image to be recognized, generating a recognition image containing the yak face bounding box and breed label.