Cattle face recognition method and system based on A-SH-BNet

By introducing the A-SH-BNet network into cow face recognition and combining it with the SE module and HS Block module, the problem of low accuracy in cow face recognition is solved, and high-precision and stable recognition is achieved in complex scenarios.

CN120656211APending Publication Date: 2025-09-16QINGHAI UNIVERSITY
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202510824745.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-19
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

Existing cow face recognition technology has low accuracy, mainly due to insufficient data quality, weak feature expression and model structure that is not optimized for the fine-grained discrimination requirements unique to cow faces.

Method used

The A-SH-BNet network is used to improve feature extraction accuracy by embedding the SE module and HS Block module in the ArcFace architecture and combining data augmentation technology. The SE module enhances feature representation through a channel attention mechanism, while the HS Block module extracts fine-grained and global features through a hierarchical partitioning mechanism.

Benefits of technology

The accuracy and stability of cow face recognition have been significantly improved, especially when dealing with complex scenes such as occlusion and lighting changes, with stronger robustness and generalization capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120656211A_ABST
    Figure CN120656211A_ABST
Patent Text Reader

Abstract

The invention provides a cattle face recognition method and system based on A-SH-BNet, and relates to the technical field of visual inspection. The method comprises the following steps: processing a to-be-recognized cattle face picture through a pre-trained cattle face feature extraction model to obtain a to-be-recognized cattle face feature vector; and finally, carrying out similarity calculation on the to-be-recognized cattle face feature vector and a cattle face feature vector in a database to obtain a recognition result. Wherein the pre-trained cattle face feature extraction model is formed by training an A-SH-BNet network, and the A-SH-BNet network is that an SE module and an HS Block module are embedded in an ArcFace framework; the ArcFace provides a ResNet and a MobileNet, an SE attention mechanism is introduced into a backbone network of a bottom layer of an ArcFace structure, and a Bottleneck structure at the end of a stage in the ResNet is replaced with an HS Block module. According to the method, an SE module in an A-SH-BNet network enhances feature representation by means of a channel attention mechanism; and the HS Block module can extract fine-grained features and global features at different levels through a hierarchical division mechanism, so that the feature extraction precision is further improved, and the cattle face recognition precision is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of visual detection technology, and in particular to a cow face recognition method and system based on A-SH-BNet. Background Art

[0002] Cow facial recognition technology collects the facial features of cows through a mobile phone APP, uses deep algorithms to construct a 3D data set for facial recognition of live cows, generates a unique biometric digital identity for each cow, and establishes a cow face ID (unique identification code) database, thereby realizing electronic management of cows.

[0003] Many current network structures used for cow face recognition often rely on deep models designed directly for human face recognition (such as ResNet and ArcFace Standard). However, these models are not structurally optimized for the fine-grained discrimination required for cow faces. While traditional ResNets can extract strong semantic features during feature abstraction and downsampling, they often lose a significant amount of fine-grained texture information crucial for cow face discrimination in mid- and high-level features. In particular, when downsampling and transitioning to wider feature maps, local subtle differences (such as the distinctive markings on the nose or the arrangement of hair at the base of the ears) are averaged and diluted.

[0004] Furthermore, current mainstream feature embedding loss designs (such as ArcFace Standard) assume small intra-class variance and large inter-class variance. This assumption holds true for human face recognition, but in cow face recognition, individual overlap in the feature space is prone to occur, further reducing the final recognition accuracy. As can be seen from the above description, the current cow face recognition accuracy is low. Summary of the Invention

[0005] (1) Technical problems solved

[0006] In view of the shortcomings of the existing technology, the present invention provides a cow face recognition method and system based on A-SH-BNet, which solves the technical problem of low accuracy of existing cow face recognition.

[0007] (2) Technical solution

[0008] To achieve the above objectives, the present invention is implemented through the following technical solutions:

[0009] In a first aspect, the present invention provides a cattle face recognition method based on A-SH-BNet, comprising:

[0010] Get a video or picture, detect the cow face using the image detection algorithm, and obtain the cow face picture to be identified;

[0011] The cow face image to be identified is processed by a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified;

[0012] Calculate the similarity between the cow face feature vector to be identified and the cow face feature vector in the database to obtain the recognition result;

[0013] The pre-trained cow face feature extraction model is trained using the A-SH-BNet network, which embeds the SE module and HS Block module in the ArcFace architecture. ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the ResNet stage with the HS Block module.

[0014] Preferably, the training process of the pre-trained cow face feature extraction model includes:

[0015] Obtain facial images of several cows in the pasture, number each yak, and put the corresponding cow facial images into different numbered folders to obtain a database;

[0016] Data enhancement technology is used to process facial images in the database to obtain a data set;

[0017] The A-SH-BNet network is trained using the dataset to obtain a cow face feature extraction model.

[0018] Preferably, the step of obtaining facial images of several cows in the pasture includes:

[0019] Obtain videos of several cows on the pasture, and process each video frame by frame to obtain yak facial images.

[0020] Preferably, the loss function in the training process of the pre-trained cow face feature extraction model includes:

[0021]

[0022] Among them, cosθ j =x i ′×W j '; x i ′ is the extracted feature vector x i is normalized to a unit vector; W j ′ is the category weight vector W j is also normalized to a unit vector; Indicates that for the correct category y i , add an angle margin m to the angle cosine; s is the scaling parameter; N is the number of samples in the batch.

[0023] Preferably, the image detection algorithm includes a Yolo detection algorithm.

[0024] Preferably, the workflow of the SE module includes two steps: Squeeze and Excitation;

[0025] In the Squeeze step, the SE module compresses the feature map of each channel into a corresponding scalar through global average pooling;

[0026] In the Excitation step, the scalar corresponding to each channel is nonlinearly mapped through a fully connected network to generate a new set of channel weights.

[0027] Preferably, the similarity calculation includes cosine distance calculation, and the calculation formula is as follows:

[0028]

[0029] Among them, A and B represent the feature vector of the cow face to be identified and the feature vector of the cow face in the database respectively.

[0030] In a second aspect, the present invention provides a cattle face recognition system based on A-SH-BNet, comprising:

[0031] The image acquisition module acquires a video or image, detects the cow face through the image detection algorithm, and obtains the cow face image to be identified;

[0032] A feature extraction module is used to process the cow face image to be identified using a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified;

[0033] The recognition module is used to calculate the similarity between the cow face feature vector to be recognized and the cow face feature vector in the database to obtain the recognition result;

[0034] The pre-trained cow face feature extraction model is trained using the A-SH-BNet network, which embeds the SE module and HS Block module in the ArcFace architecture. ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the ResNet stage with the HS Block module.

[0035] In a third aspect, the present invention provides a computer-readable storage medium storing a computer program for cattle face recognition based on A-SH-BNet, wherein the computer program enables a computer to execute the cattle face recognition method based on A-SH-BNet as described above.

[0036] In a fourth aspect, the present invention provides an electronic device, comprising:

[0037] One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including instructions for executing the A-SH-BNet-based cattle face recognition method as described above.

[0038] (3) Beneficial effects

[0039] The present invention provides a cattle face recognition method and system based on A-SH-BNet. Compared with the existing technology, it has the following advantages:

[0040] The present invention first obtains a video or picture, detects a cow face through an image detection algorithm, and obtains a cow face picture to be identified; then processes the cow face picture to be identified through a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified; finally, the cow face feature vector to be identified is similarity calculated with the cow face feature vector in the database to obtain a recognition result; wherein, the pre-trained cow face feature extraction model is trained by an A-SH-BNet network, and the A-SH-BNet network refers to embedding an SE module and an HS Block module in an ArcFace architecture; ArcFace provides ResNet and MobileNet, introduces an SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the stage in ResNet with an HS Block module. In the present invention, the SE module in the A-SH-BNet network enhances feature representation with the help of a channel attention mechanism; the HS Block module can extract fine-grained features and global features at different levels through a hierarchical division mechanism, further improving feature extraction accuracy, thereby improving cow face recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0042] Figure 1 A block diagram of a cattle face recognition method based on A-SH-BNet according to an embodiment of the present invention;

[0043] Figure 2Schematic diagram of the process of extracting facial feature vectors using the cow face feature extraction model;

[0044] Figure 3 It is the structural diagram of SE module;

[0045] Figure 4 Schematic diagram of inserting the SE attention mechanism into the end of the residual block of ResNet;

[0046] Figure 5 This is the structural diagram of the HS Block module;

[0047] Figure 6 Schematic diagram of the solution process of Arcface loss function. DETAILED DESCRIPTION

[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention are clearly and completely described. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0049] The embodiments of the present application provide a cow face recognition method and system based on A-SH-BNet, which solves the technical problem of low accuracy of existing cow face recognition and improves the accuracy and stability of cow face recognition.

[0050] The technical solution in the embodiments of the present application is to solve the above technical problems, and the overall idea is as follows:

[0051] The overall accuracy of existing cow face recognition technology still lags significantly behind that of human face recognition. The reasons behind this fall into multiple areas, including data, features, and models. First, at the data level, cow face image data itself is highly complex and poorly standardized. Unlike human face images, which typically follow standard capture procedures such as frontal view, clear image quality, and even lighting, cow face images are often captured in natural environments, subject to numerous issues such as varying shooting angles, varying lighting conditions, occlusions, mud coverage, and hair obstruction. Furthermore, individual differences in appearance between cows are far less pronounced than between humans. Cattle of the same breed and group, in particular, have highly similar facial structures, and minor local variations become the primary basis for identification. However, these subtle variations are often difficult to fully capture during capture, creating inherent data challenges for identification.

[0052] At the feature level, cow faces are less structured than human faces. Human faces have distinct geometric features (such as eyes, nose, and mouth). While features like nose lines, hair flow, patches, and horns on cow faces can serve as features, these features are less recognizable and susceptible to changes in posture and expression. For example, actions like lowering the head, tilting the head, and chewing significantly alter visible local feature patterns. Furthermore, the hair covering the surface of a cow's face causes texture features to vary significantly in different environments. Furthermore, the presence of humidity, stains, and mud spots introduces a large amount of interfering local information, making it difficult for the model to stably extract consistent deep feature expressions.

[0053] From a model perspective, many current network structures used for cow face recognition often utilize deep models designed directly for human face recognition (such as ResNet and ArcFace Standard Edition). However, these models are not structurally optimized for the fine-grained discrimination requirements unique to cow faces. While traditional ResNets can extract strong semantic features during feature abstraction and downsampling, they often lose a significant amount of fine-grained texture information crucial for cow face discrimination in mid- and high-level features. This is especially true during downsampling and the transition to wide feature maps, where local subtle differences (such as the distinctive markings on the nose and the arrangement of hair at the base of the ears) are averaged and diluted. Furthermore, current mainstream feature embedding loss designs (such as ArcFace Standard Edition) assume that intra-class variance is small and inter-class variance is large. This assumption holds true for human face recognition, but in cow face recognition, due to the minimal individual variation within the same herd, the distances between classes are very close, making it prone to individual overlap in the feature space, further reducing the final recognition accuracy.

[0054] In general, the core reasons for the low accuracy of existing cow face recognition can be attributed to three technical bottlenecks: insufficient data quality (high noise, low standardization), weak feature expression (fine-grained features are easily lost), and mismatch between the model and the task (the structure is not optimized in a targeted manner).

[0055] In response to the problems existing in the prior art, an embodiment of the present invention proposes a cow face recognition method and system based on A-SH-BNet. First, data enhancement technology is used to enrich the number of samples in the data set. Then, the SE module in the A-SH-BNet network enhances the feature representation through the channel attention mechanism. The HS Block module can extract fine-grained and global features at different levels through a hierarchical partitioning mechanism to further improve the accuracy of feature extraction. Combining ArcFace, SE (Squeeze-and-Excitation) module and HS Block (Hierarchical-split block) module can effectively improve the overall performance of the cow face recognition model. The synergistic effect of these three enables the model to have stronger robustness and generalization ability while maintaining high accuracy. Especially when dealing with occlusion, lighting changes, and other complex scenes, this combined strategy can significantly improve the accuracy and stability of cow face recognition.

[0056] In order to better understand the above technical solution, the above technical solution will be described in detail below with reference to the accompanying drawings and specific implementation methods.

[0057] The embodiment of the present invention provides a cow face recognition method based on A-SH-BNet, such as Figure 1 Shown, including:

[0058] S11, obtaining a video or picture, detecting a cow face using an image detection algorithm, and obtaining a cow face picture to be identified;

[0059] S12, processing the cow face image to be identified by using a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified;

[0060] S13, calculating similarity between the cow face feature vector to be identified and the cow face feature vectors in the database to obtain a recognition result;

[0061] The pre-trained cow face feature extraction model is trained using the A-SH-BNet network, which embeds the SE module and HS Block module in the ArcFace architecture. ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the ResNet stage with the HS Block module.

[0062] In the embodiment of the present invention, the SE module in the A-SH-BNet network uses the channel attention mechanism to enhance feature representation; the HS Block module uses a hierarchical partitioning mechanism to extract fine-grained features and global features at different levels, further improving the feature extraction accuracy and thus improving the cow face recognition accuracy.

[0063] It should be noted that the image detection algorithm used in the embodiment of the present invention adopts the Yolo detection algorithm. Of course, other image detection algorithms, such as Faster R-CNN and SSD, can also be used in the specific implementation process. The similarity calculation in the embodiment of the present invention adopts cosine distance. In the specific implementation process, other similarity calculation methods, such as Euclidean distance and Manhattan distance, can also be used.

[0064] The following is a detailed description of the training process of the pre-trained cow face feature extraction model:

[0065] In step S21, facial images of several cows in the pasture are obtained, and each yak is numbered. The corresponding cow facial images are placed in different numbered folders to obtain a database. Specifically, the database includes:

[0066] It should be noted that, in the embodiment of the present invention, yak face recognition is taken as an example for detailed description. In actual application, the method of the embodiment of the present invention can also be applied to other breeds of cattle.

[0067] Using a 4K GoPro camera, we filmed each yak on a particular ranch for approximately one minute. Each video segment was frame-processed to obtain yak facial images. Each yak was numbered and placed into folders with corresponding yak facial images, creating a database. The database contains facial image data for 183 yaks.

[0068] In the process of obtaining pictures by framing the video, it is found that the similarity of the pictures obtained between consecutive frames is too high. In order to avoid the high similarity between consecutive frames in the video, the frame difference method is used for processing. The frame difference method calculates the pixel difference or motion information between adjacent frames. If the pixel difference exceeds the set threshold, the frame is retained, otherwise it is discarded. In the embodiment of the present invention, the two-frame difference method is used for frame selection. The calculation formulas of the two-frame difference method are shown in formula (1) and formula (2):

[0069] P f (x,y)=|L f (x,y)-L f-1 (x,y)|

[0070]

[0071] Among them, P f (x, y) is the absolute value of the difference between the two frames of image; in formula (2) The values ​​obtained by formula (1) are filtered, and the values ​​greater than the threshold remain unchanged, while the values ​​less than the threshold are reset to zero; T p is the threshold.

[0072] It should be noted that, in practice, the database can also be obtained through other methods, such as directly obtaining facial images of multiple cows (the images are obtained from a single photo shoot), cropping the images, and then forming a database of the cropped facial images of the cows. The embodiments of the present invention use video framing to obtain images of cow faces, effectively resolving image quality issues caused by changes in animal posture and improving image quality. Furthermore, compared to a single photo shoot, this method more comprehensively captures details such as ear tag recognition and facial texture.

[0073] In step S22, data enhancement technology is used to process the facial images in the database to obtain a data set. The specific implementation process is as follows:

[0074] First, the processed data was cropped to a 512×512 resolution using Python image processing tools combined with the trained Yolov8 detection model. Images of varying sizes were then rescaled to a uniform size of 112×112. Next, the image data was randomly augmented using OpenCV's related functions: clockwise rotations of 5° and counterclockwise rotations of 5°, brightness reduction parameters set to 0.75 and brightness enhancement parameters set to 1.2, and random noise with a Gaussian noise coefficient set to 0.3. Finally, for categories with significantly excessive sample sizes, a portion of the samples were randomly removed, maintaining the same number of samples for each category in the validation set. Furthermore, some yak facial images were aligned.

[0075] Using data augmentation technology to enrich the number of samples in the dataset not only significantly reduces the manpower and material costs incurred during data labeling and collection, but also plays a key role in the subsequent model training process: by introducing diverse data distribution, the model's tolerance to local perturbations in the input data is improved, thereby enhancing the model's robustness; using new samples to balance the distribution of training data, alleviating overfitting caused by insufficient sample size or uneven data distribution; and ultimately prompting the model to learn more universal feature expressions, thereby demonstrating stronger generalization capabilities on unseen data, effectively improving the model's performance in actual application scenarios.

[0076] In step S23, the A-SH-BNet network is trained using the dataset to obtain a cow face feature extraction model. The specific implementation process is as follows:

[0077] The A-SH-BNet network embeds the SE module and HS Block module in the ArcFace framework. Specifically, ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the original ResNet stage with the HSBlock module.

[0078] The embodiment of the present invention selects ResNet100 to extract the features of yak facial images, and enhances the inter-class separation by optimizing the loss function AAM. The SE module enhances the feature representation through the channel attention mechanism, while the HS Block module can extract fine-grained and global features at different levels through a hierarchical partitioning mechanism to further improve the accuracy of feature extraction. Combining ArcFace, SE module and HS Block module together can effectively improve the overall performance of the cow face recognition model. The synergistic effect of these three enables the model to have stronger robustness and generalization capabilities while maintaining high accuracy. Especially when dealing with occlusion, lighting changes, and other complex scenes, this combined strategy can significantly improve the accuracy and stability of cow face recognition.

[0079] The process of extracting facial feature vectors through the cow face feature extraction model is as follows Figure 2 shown.

[0080] The Squeeze-and-Excitation (SE) module is a general network module, such as Figure 3 As shown in , it aims to enhance the ability of feature representation by adaptively adjusting the weights of each channel. The SE attention mechanism is inserted into the end of the residual block of ResNet, as shown in Figure 4 As shown in the figure, by recalibrating the channel features, the discriminability of the cow face features is improved. The SE module can be used to adaptively adjust the channel weights of the feature map, helping the network to focus on the facial feature areas and suppress the influence of the hair area. The workflow of the SE module is divided into two steps: Squeeze and Excitation. In the Squeeze step, the SE module compresses the feature map of each channel into a scalar through global average pooling to obtain global context information. In the Excitation step, these scalars are nonlinearly mapped through a fully connected network to generate a set of new channel weights. These weights are then used to weight each channel of the original feature map, thereby highlighting important feature channels and suppressing irrelevant channels. The introduction of the SE module enables the network to handle the relationship between different feature channels more flexibly, thereby improving the performance of the model.

[0081] In the SE module, the following operations are performed:

[0082] (1)Transformation(F tr )(Transformation)

[0083] X→U, through F tr , the feature map X becomes the feature map U. F tr It can be regarded as a standard convolution operator. The formula is defined as follows:

[0084]

[0085] Among them, X∈R^(H′×W′×C′) is the input feature map U∈R^(H×W×C): output feature map, V represents a set of learned filter kernels, V c refers to the parameters of the c-th filter, Represents a 2D spatial kernel, and * represents a convolution operation. Formula (3) indicates that each layer of the input feature map X undergoes convolution with a 2D spatial kernel to obtain C output feature maps, forming the feature map U.

[0086] (2) Squeeze (global information embedding)

[0087] F sq It uses global average pooling of channels. To solve the problem of utilizing channel dependencies, we choose to compress the global spatial information into a channel descriptor. That is, we use global average pooling of channels to directly compress the W×H×C feature map containing global information into a 1×1×C feature vector Z. The channel features of the C feature maps are compressed into a single value. In this way, the generated channel-level statistics Z contain contextual information, alleviating the problem of channel dependencies. It is defined as follows:

[0088]

[0089] Among them, z c is the cth element of Z.

[0090] (3) Excitation (Adaptive Recalibration)

[0091] A gate mechanism consisting of two fully connected layers is adopted. The first fully connected layer compresses C channels into C / r channels to reduce the amount of computation. Then, a ReLu nonlinear activation layer is passed through the second fully connected layer to restore the number of channels back to C channels. The weight s is obtained through Sigmoid activation. The dimension of the final s is 1×1×C, which is used to characterize the weights of the C feature maps in the feature map U. r refers to the compression ratio.

[0092] s=F ex(z,W)=σ(g(z,W))=σ(W2δ(W1z))

[0093] (4) Scale (reweighting)

[0094] Finally, the Scale operation is performed to weight the attention weights obtained above to the features of each channel. The final output of the SE module is obtained by multiplying each feature map in the feature map U by the corresponding weight.

[0095] HS Block module (Hierarchical-split block):

[0096] Hierarchical-split block is a method used to improve the computational efficiency of neural network models and compress model parameters. It is mainly used in convolutional neural networks (CNN) in deep learning. For yaks with complex facial areas and more hair coverage, the hierarchical design of the HS Block module can help the model extract more detailed and accurate facial features. By adding the HS Block module, the Bottleneck at the end of the stage in the original ResNet is replaced to enhance the diversity of local and global features. It can effectively process local and global information, enhance the robustness of the model, reduce redundant calculations, and improve the overall feature extraction effect. This method reduces the amount of computation and memory usage by splitting the parameters of the convolutional layer hierarchically while maintaining the expressive power of the model. The HS Block module mainly works through three steps: channel splitting (Split) → hierarchical processing (Hierarchical) → feature fusion (Fuse). The structural diagram of the HS Block module is shown below. Figure 5 As shown,

[0097] 1. Input feature grouping: The input feature map is divided into several groups according to the channel dimension, and each group represents a part of the input feature. The size of the input feature map is H×W×C, where H and W represent the height and width respectively, and C represents the number of channels. After segmentation, the size of each sub-feature map is H i ×W i ×C.

[0098] 2. Hierarchical convolution processing: For each set of feature maps, the HS Block module performs convolution operations in sequence. The initial layer only processes the first group. In subsequent layers, it not only processes the current group but also combines the output features of the previous layer. This layer-by-layer convolution processing method enables the module to gradually integrate richer feature information. For each sub-feature map X i Apply different convolution kernels. Assume there are k different convolution kernels K1, K2...K k, then the operation of applying the jth convolution kernel on the i-th sub-feature map can be expressed as:

[0099] Y ij =K j *X i

[0100] Among them, * represents the convolution operation.

[0101] 3. Channel splicing: The output of each convolution operation is split into two parts. One part is spliced ​​with the output feature map of the previous layer, and the other part is spliced ​​with the input feature map of the next group. In this way, the module fuses the feature maps layer by layer, and finally merges the output feature maps of all groups into a complete output feature map. By fusing features through the concatenation operation, the fused features can be expressed as:

[0102] Y=concat(Y 11 ,Y 12 ,…,Y ij ,…,Y nk )

[0103] ArcFace Architecture:

[0104] ArcFace is a fundamental algorithm for face recognition tasks. It enhances feature differentiation by introducing angular metrics. Its primary goal is to cluster features of the same identity more closely together and distance features of different identities further apart, thereby improving the performance of face recognition models. Here, an ArcFace architecture capable of cow face recognition is obtained by training on a dataset of cow faces.

[0105] The feature extraction process of the ArcFace model first performs preliminary downsampling and feature extraction on the input 112×112 cow face image through a Stem module consisting of 7×7 convolution (stride 2), batch normalization (BN), ReLU activation and 3×3 maximum pooling, generating an initial 56×56 feature map; then it goes through four residual stages (Res1-Res4), each of which is composed of multiple standard Bottleneck blocks stacked together. These blocks gradually reduce the feature map size from 56×56 to 7×7 through 1×1 convolution, extract spatial features through 3×3 convolution, and increase the dimension through 1×1 convolution combined with residual connections, while expanding the number of channels from 64 to 2048; then the 7×7×2048 features are compressed into a 1×1×2048 global descriptor through global average pooling (avg) and flattening, and then mapped to a 512-dimensional feature vector through a fully connected layer.

[0106] In this embodiment of the present invention, in order to further improve the recognition accuracy, the inter-class separation is enhanced by optimizing the loss function AAM (Additive Angular Margin Penalty). The calculation process is as follows:

[0107] The extracted feature vector x i And the weight vector W for each category j Normalize: eigenvector x i Normalized to a unit vector Class weight vector W j Also normalized to a unit vector

[0108] After normalization, calculate the eigenvector x i ′ and each category center W j The cosine of the angle between:

[0109] cosθ j =x i ′×W j '

[0110] Among them, θ j is the angle between the feature vector and the class center.

[0111] For the correct category y i , add an angle margin m to the angle cosine:

[0112]

[0113] Use the cosine value with angle margin to calculate the Softmax loss function, such as Figure 6 As shown:

[0114]

[0115] Where s is the scaling parameter, typically set to 64, and N is the number of samples in the batch. ArcFace converts the adjusted probability distribution for each category into a probability distribution using the Softmax function. These probability values ​​reflect the model's confidence in its prediction of each category. For the cow face recognition task, these probability values ​​can be used to determine which category a sample is most likely to belong to. The probability distribution formula is as follows:

[0116]

[0117] The following is a detailed description of the cow face recognition method based on A-SH-BNet:

[0118] In step S11, a video or picture is obtained, and a cow face is detected using the Yolov8 detection algorithm to obtain a cow face picture to be identified;

[0119] In step S12, the cow face image to be identified is processed by the cow face feature extraction model to obtain a cow face feature vector to be identified;

[0120] In step S13, similarity calculation is performed between the cow face feature vector to be identified and the cow face feature vector in the database to obtain the recognition result, which specifically includes:

[0121] The similarity between two cows is determined by calculating the distance between the eigenvectors of the cow face data. Commonly used distance calculation methods include Euclidean distance and cosine distance. Euclidean distance is a common measurement method that measures the absolute distance between different points in a multidimensional space; in contrast, cosine distance focuses more on the directional differences of vectors rather than the absolute differences in the modulus. In the embodiment of the present invention, priority is given to the differences in the spatial direction of the eigenvectors, and therefore cosine distance is selected as the main metric. The cosine distance is defined as 1-cosine similarity, where cosine similarity is the cosine value of the angle between two vectors, and theoretically has a value range of [-1,1]. However, in the embodiment of the present invention, the eigenvectors output by the ArcFace model have been normalized, and during the training process, it is generally ensured that the cosine similarity between vectors is mainly concentrated in the [0,1] interval, so the corresponding cosine distance also mainly falls within the [0,1] range. In other words, the smaller the cosine distance, the closer the directions of the two eigenvectors are, that is, the more similar the two pictures are; conversely, the larger the distance, the lower the similarity. The definition of cosine distance is as follows:

[0122]

[0123] Among them, A and B represent two vectors, which are usually the feature vectors of two extracted samples. Here, they represent the feature vector of the cow face to be identified and the feature vector of the cow face in the database respectively.

[0124] It should be noted that the original ArcFace predict.py function only compares the cosine distance between two input photos. Here, we design a code that can output the ID of a cow face when inputting a cow face photo. The idea is to use different folder naming methods for different yaks. In this experiment, we use folders named 1, 2, ..., n. Using the trained cow face feature extraction model from an embodiment of the present invention, we extract cow face features from these folders. When an image is input, the code performs the following operations: 1. Automatically crop the input image to a suitable format; 2. Use the cow face feature extraction model to extract a 512-dimensional cow face feature vector; 3. Use the cosine distance to compare the cow face feature vector of the input cow face image with the cow face feature vectors of other cow faces in each folder. The one with the smallest cosine distance is saved, and the predicted ID of the cow face is displayed in the upper left corner of the input image; 3. Set a cosine distance threshold of 0.9. If the cosine distance between the input image and any image in the validation set is greater than the threshold, the predicted ID is output as error.

[0125] To verify the effectiveness of this embodiment of the present invention, we selected several facial recognition algorithms, including MobileNetv2, ConvNeXt, InceptionV3, FaceNet, and VGG16, for comparative testing. The experimental results are shown in Table 1 below.

[0126] Table 1 Comparative data of different methods

[0127] Test methods Accuracy (%) Model size (MB) Model parameter number (M) Arcface 92.96 249.74 65.19 A-SH-Bnet 94.98 167.87 43.32 MobileNetv2 88.32 67.74 18.13 ConvNeXt 86.61 120.07 31.34 InceptionV3 91.89 123.56 32.36 FaceNet 92.41 224.32 57.93 VGG16 90.74 484.53 127.21

[0128] The parameter count refers to the total number of trainable parameters in a model. A larger parameter count generally indicates a more complex model, potentially offering greater expressiveness, but also increasing the risk of overfitting. Furthermore, the parameter count directly impacts the model's training and inference speed.

[0129] Model size refers to multi-classification tasks. Since the goal is to assign a label to each input (from multiple categories), the model's design and size directly impact its classification capabilities and evaluation performance. We hope to achieve faster model training, faster inference speed, and easier deployment, especially for mobile devices.

[0130] In this comparative experiment, A-SH-Bnet demonstrated significant advantages over other models. In terms of Acc, A-SH-Bnet achieved 94.98%, a 2.02% improvement over the baseline model (94.98-92.96), a 6.66% improvement over MobileNetv2 (94.98-88.32), an 8.37% improvement over ConvNeXt (94.98-86.61), a 3.09% improvement over InceptionV3 (94.98-91.89), a 2.57% improvement over FaceNet (94.98-92.41), and a 4.24% improvement over VGG16 (94.98-90.74). In terms of model size, the A-SH-Bnet model is 167.87MB, smaller than the 484.53MB of the VGG16 model, the 224.32MB of the FaceNet model, and the 249.74MB of the base ArcFace model, and larger than the 67.74MB of the MobileNetv2 model, the 120.07MB of the ConvNeXt model, and the 123.56MB of the InceptionV3 model. In terms of model parameter count, the A-SH-Bnet model is 43.32MB, smaller than the 127.21MB of the VGG16 model and the 57.93MB of the FaceNet model, and larger than the 18.13MB of the MobileNetv2 model, the 31.34MB of the ConvNeXt model, and the 32.36MB of the InceptionV3 model. Overall, the A-SH-Bnet model demonstrates strong overall advantages in this multi-model comparison experiment. Its accuracy is higher than that of several mainstream models, demonstrating its superior expressive capabilities in feature extraction and classification. At the same time, although the model size and parameter count of A-SH-Bnet are higher than those of lightweight models (such as MobileNetv2, ConvNeXt, etc.), it can achieve a high accuracy of nearly 95% while ensuring low resource overhead, reflecting a good balance between performance and complexity.

[0131] It's important to note that in the fine-grained visual recognition task of cow face recognition, where individual differences between images are minimal and local features are volatile and susceptible to interference, ArcFace, a discriminative recognition framework based on deep embedding, must achieve optimal performance with its underlying feature extraction network, which must possess stronger detail modeling capabilities, information filtering capabilities, and the ability to maintain intra-class consistency. To this end, introducing the SE attention mechanism into the underlying backbone network of the ArcFace architecture and replacing the Bottleneck structure at the end of the original ResNet stage with the HS Block module is an effective technical approach to enhance discriminative feature extraction at a structural level.

[0132] The SE (Squeeze-and-Excitation) attention mechanism, embedded within the residual blocks of ResNet, imbues the model with dynamic channel recalibration capabilities within each residual unit. Through a mechanism of "global information compression + weight redistribution," the model automatically learns which channels in the current input carry pattern information that is more critical for individual recognition, and which may be background noise or redundant interference. In cow face images, in particular, discriminative information is often concentrated in tiny regions such as nose prints, spots, and ear hair, with varying representational strengths across different channels. The introduction of the SE module enables the network to continuously strengthen the responses of these key channels during layer-by-layer information propagation, effectively avoiding the problem of important information being averaged and diluted during deep propagation. This mechanism effectively imbues the network with a "self-attention" capability, enabling it to accurately preserve the local structures that determine individual differences while learning global identity features.

[0133] HSBlock (Hierarchical-Split Block), a replacement for the bottleneck module at the end of a ResNet stage, overcomes the inherent limitations of the bottleneck block's unified channel processing and single information path. While effective for semantic extraction, the bottleneck architecture employs a serial compression-convolution-expansion approach, which can easily lose spatial resolution and local structure when processing low-contrast, high-noise, fine-grained images. HSBlock, on the other hand, divides the channel into multiple branches, each performing convolutions with different receptive fields, forming parallel information channels. This allows for simultaneous modeling of multi-scale details within a single convolutional stage. This architecture is particularly well-suited for fine-grained recognition in cow face images, as the local discriminative features of cows are characterized by inconsistent scales, complex textures, and variable morphology. A single-scale approach often struggles to balance detail preservation and semantic abstraction. HSBlock, through its multi-scale, hierarchical information fusion process, preserves subtle texture features without sacrificing overall structural semantics, effectively enhancing the model's robustness to local variations and pose perturbations. Furthermore, HSBlock significantly reduces computational effort by reducing the number of channels involved in each operation.

[0134] From the perspective of overall feature flow, the combination of the SE module and HSBlock forms a more refined and efficient information extraction path. The SE mechanism improves the information density and effectiveness of each feature pathway, making the information transmission within the channel more concentrated and orderly; HSBlock enhances the richness and detail integrity of features at the spatial and semantic levels through layered processing and scale diversification. Ultimately, in the Embedding branch of ArcFace, this enhanced feature abstraction is directly reflected in the increased inter-class spacing and enhanced intra-class compactness in the vector space, allowing cow-face individuals to maintain a stable and highly discriminative feature distribution even in complex scenarios such as lighting changes, posture shifts, and partial occlusion.

[0135] The embodiment of the present invention provides a cattle face recognition system based on A-SH-BNet, comprising:

[0136] The image acquisition module acquires a video or image, detects the cow face through the image detection algorithm, and obtains the cow face image to be identified;

[0137] A feature extraction module is used to process the cow face image to be identified using a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified;

[0138] The recognition module is used to calculate the similarity between the cow face feature vector to be recognized and the cow face feature vector in the database to obtain the recognition result;

[0139] The pre-trained cow face feature extraction model is trained using the A-SH-BNet network, which embeds the SE module and HS Block module in the ArcFace architecture. ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the ResNet stage with the HS Block module.

[0140] It can be understood that the A-SH-BNet-based cattle face recognition system provided in the embodiment of the present invention corresponds to the above-mentioned A-SH-BNet-based cattle face recognition method. The explanation, examples, beneficial effects, etc. of the relevant contents can refer to the corresponding contents in the A-SH-BNet-based cattle face recognition method, and will not be repeated here.

[0141] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program for cattle face recognition based on A-SH-BNet, wherein the computer program enables a computer to execute the cattle face recognition method based on A-SH-BNet as described above.

[0142] An embodiment of the present invention also provides an electronic device, comprising: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the programs include a method for executing the A-SH-BNet-based cow face recognition method as described above.

[0143] In summary, compared with the existing technology, the present invention has the following beneficial effects:

[0144] 1. In this embodiment of the present invention, the SE module in the A-SH-BNet network enhances feature representation through the channel attention mechanism, while the HS Block module, through a hierarchical partitioning mechanism, can extract fine-grained and global features at different levels to further improve the accuracy of feature extraction, thereby improving the accuracy of cow face recognition.

[0145] 2. Data augmentation technology is used to enrich the number of samples in the dataset. This not only significantly reduces the manpower and material costs incurred during data labeling and collection, but also, by introducing diverse data distributions, improves the tolerance of the cow face feature extraction model to local perturbations in the input data, thereby enhancing the robustness of the model. New samples are used to balance the distribution of training data, alleviating overfitting caused by insufficient sample numbers or uneven data distribution. Ultimately, the model learns more universal feature expressions, thereby demonstrating stronger generalization capabilities on unseen data, effectively improving the model's performance in practical application scenarios.

[0146] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0147] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A cattle face recognition method based on A-SH-BNet, characterized in that: include: Get a video or picture, detect the cow face using the image detection algorithm, and obtain the cow face picture to be identified; The cow face image to be identified is processed by a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified; Calculate the similarity between the cow face feature vector to be identified and the cow face feature vector in the database to obtain the recognition result; The pre-trained cow face feature extraction model is trained using the A-SH-BNet network, which embeds the SE module and HS Block module in the ArcFace architecture. ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the ResNet stage with the HS Block module.

2. The cattle face recognition method based on A-SH-BNet according to claim 1, characterized in that: The training process of the pre-trained cow face feature extraction model includes: Obtain facial images of several cows in the pasture, number each yak, and put the corresponding cow facial images into different numbered folders to obtain a database; Data enhancement technology is used to process facial images in the database to obtain a data set; The A-SH-BNet network is trained using the dataset to obtain a cow face feature extraction model.

3. The cattle face recognition method based on A-SH-BNet according to claim 2, characterized in that: The step of obtaining facial images of several cows in a pasture includes: Obtain videos of several cows on the pasture, and process each video frame by frame to obtain yak facial images.

4. The cattle face recognition method based on A-SH-BNet according to any one of claims 1 to 3, characterized in that: The loss function in the training process of the pre-trained cow face feature extraction model includes: Among them, cosθ j =x′ i ×W j '; x′ i is the extracted feature vector x i is normalized to a unit vector; W j ′ is the category weight vector W j is also normalized to a unit vector; Indicates that for the correct category y i , add an angle margin m to the angle cosine; s is the scaling parameter; N is the number of samples in the batch.

5. The cow face recognition method based on A-SH-BNet according to any one of claims 1 to 3, characterized in that: The image detection algorithm includes a Yolo detection algorithm.

6. The cow face recognition method based on A-SH-BNet according to any one of claims 1 to 3, characterized in that: The workflow of the SE module includes two steps: Squeeze and Excitation; In the Squeeze step, the SE module compresses the feature map of each channel into a corresponding scalar through global average pooling; In the Excitation step, the scalar corresponding to each channel is nonlinearly mapped through a fully connected network to generate a new set of channel weights.

7. The cattle face recognition method based on A-SH-BNet according to any one of claims 1 to 3, characterized in that: The similarity calculation includes cosine distance calculation, and its calculation formula is as follows: Among them, A and B represent the feature vector of the cow face to be identified and the feature vector of the cow face in the database respectively.

8. A cattle face recognition system based on A-SH-BNet, characterized in that: include: The image acquisition module acquires a video or image, detects the cow face through the image detection algorithm, and obtains the cow face image to be identified; A feature extraction module is used to process the cow face image to be identified using a pre-trained cow face feature extraction model to obtain a cow face feature vector to be identified; The recognition module is used to calculate the similarity between the cow face feature vector to be recognized and the cow face feature vector in the database to obtain the recognition result; The pre-trained cow face feature extraction model is trained using the A-SH-BNet network, which embeds the SE module and HS Block module in the ArcFace architecture. ArcFace provides ResNet and MobileNet, introduces the SE attention mechanism into the underlying backbone network of the ArcFace structure, and replaces the Bottleneck structure at the end of the ResNet stage with the HS Block module.

9. A computer-readable storage medium, characterized in that The computer program for cattle face recognition based on A-SH-BNet is stored therein, wherein the computer program enables a computer to execute the cattle face recognition method based on A-SH-BNet according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the programs include instructions for executing the A-SH-BNet-based cattle face recognition method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Face recognition attendance checking method and system based on improved ArcFace algorithm

    CN121033917A

  • Face recognition attendance method and system based on improved ArcFace algorithm

    CN121033917B

  • Livestock identity verification method and system based on multi-modal image analysis

    CN121789252A