Cattle face recognition method

By combining rotation invariance coordinates and deformable convolutional cow face feature extraction model, the problem of low accuracy of cow face recognition is solved, and the rotation invariance recognition of cow face images is realized, which improves the recognition accuracy and is suitable for Dairy cow insurance claims and other fields.

CN119251873APending Publication Date: 2025-01-03INNER MONGOLIA WANGXUN INFORMATION ENG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411309512.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-19
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

The recognition accuracy of the cow face recognition method is low, mainly due to the shaking of the cow's head, which changes the angle, position and size of the cow's face in the image, which increases the difficulty of recognition. The existing technology has not effectively solved this problem.

Method used

Using a machine learning-based bull face feature extraction model, combining rotation invariance coordinates and deformable convolution, the feature vectors of bull face images are captured through variant convolution operations, so as to realize rotation invariance recognition of bull face images and improve the accuracy of recognition. sex.

Benefits of technology

It effectively solves the recognition difficulties caused by head shaking of cows, improves the accuracy of cow face recognition, and provides a reliable individual recognition method in the process of dairy cow insurance claims.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119251873A_ABST
    Figure CN119251873A_ABST
Patent Text Reader

Abstract

The invention relates to a cattle face recognition method. The method comprises the steps of obtaining a to-be-recognized target cattle face image; extracting a feature vector of the target cattle face image through the trained cattle face feature extraction model based on machine learning; comparing the feature vector of the target cattle face image with the feature vector of at least one prior cattle face image of which the category is known, and determining the category of the target cattle face image according to a comparison result; wherein the cattle face images of the same type belong to the same cattle; the cattle face feature extraction model comprises a convolution layer, a first dense layer, a first transition layer, a second dense layer, a second transition layer, a third dense layer and an average pooling layer which are connected in sequence, the input of the convolution layer is a target cattle face image, and the output of the average pooling layer is a feature vector of the target cattle face image. Through the cattle face recognition method, the category of the cattle face image can be accurately recognized, and then whether the cattle face image belongs to the target cattle or not can be accurately judged. The problem that a cattle face recognition method is low in recognition accuracy is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image detection, and in particular to a cow face recognition method. Background Art

[0002] In the insurance claim process of dairy cows, the individual identification problem of judging whether the cow is an insured cow through pictures is often encountered. Currently, there is no better solution to this problem.

[0003] Cow face recognition technology usually uses a similar method to human face recognition in feature extraction, but the features of human and cow faces are different. Since the cow's face is large and long, the shaking of the cow's head is more obvious, causing the position and angle of the cow's face to change frequently. These factors work together to increase the difficulty of cow face recognition and affect the accuracy of recognition. During the cow face data shooting process, even the same cow, the images taken at different times may show different appearances due to the shaking of the cow's head. This head shaking may cause the angle, position and size of the cow's face in the image to change, making it difficult to accurately identify individual cows.

[0004] There is no effective solution to the problem of low recognition accuracy of current cow face recognition methods. Summary of the invention

[0005] The present invention provides a cow face recognition method to solve the problem of low recognition accuracy of the current cow face recognition method.

[0006] In a first aspect, the present invention provides a method for recognizing a cow face, comprising:

[0007] Obtain a target cow face image to be identified;

[0008] Extracting a feature vector of the target cow face image by using a trained cow face feature extraction model based on machine learning;

[0009] Comparing the feature vector of the target cow face image with the feature vector of at least one prior cow face image of known category, and determining the category of the target cow face image according to the comparison result; wherein cow face images of the same category belong to the same cow;

[0010] The cow face feature extraction model comprises a convolution layer, a first dense layer, a first transition layer, a second dense layer, a second transition layer, a third dense layer and an average pooling layer connected in sequence, the input of the convolution layer is the target cow face image, and the output of the average pooling layer is the feature vector of the target cow face image;

[0011] The first dense layer, the second dense layer and the third dense layer have the same feature processing flow, and the feature processing flow includes N rounds of feature processing steps, and each round of the feature processing steps includes:

[0012] The first feature map is sequentially subjected to a standard convolution operation, a Relu activation operation, and a BN batch normalization operation to obtain a second feature map;

[0013] Performing a variant convolution operation, a Relu activation operation, and a BN batch normalization operation on the second feature map in sequence to obtain a third feature map, wherein the variant convolution operation is implemented by a deformable convolution that incorporates rotation invariant coordinates;

[0014] Adding the third characteristic map to the first characteristic map to obtain a fourth characteristic map;

[0015] In the N rounds of feature processing steps, the first feature map of the first round of feature processing steps is the dense layer input feature map, the fourth feature maps of the first N-1 rounds of feature processing steps are all used as the first feature maps of the next round of feature processing steps, and the third feature map of the Nth round of feature processing steps is the dense layer output feature map.

[0016] Compared with the related art, the present invention combines rotation invariant coordinates (RIC) and deformable convolution (DConv) to obtain a new variant convolution (RIC-DConv). RIC-DConv is a deformable convolution that integrates rotation invariant coordinates. By integrating the offset of the deformable convolution with the rotation invariant coordinates, RIC-DConv can capture the features of different rotation versions of local features in a consistent manner. The network model containing RIC-DConv is used to recognize cow face images, which can accurately capture the feature vectors of cow face images, thereby solving the problem of difficulty in recognizing cows due to head shaking.

[0017] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 is a structural diagram of a cow face feature extraction model in some embodiments of the present invention;

[0019] Figure 2 is a structural diagram of a cattle-dense layer in some embodiments of the present invention;

[0020] Figure 3 is a structural diagram of a cattle transition layer in some embodiments of the present invention;

[0021] Figure 4 is a structural diagram of variant convolution in some embodiments of the present invention;

[0022] Figure 5 is an example diagram of cow face recognition results in some embodiments of the present invention;

[0023] Figure 6 This is the recognition result of cow face image pair by DenseNet and RIC-DConv-DenseNet. DETAILED DESCRIPTION

[0024] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.

[0025] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the", "these" and the like in this application do not represent quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether directly or indirectly. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. Usually, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.

[0026] The present invention provides a cow face recognition method, which comprises the following steps:

[0027] Step S110, obtaining a target cow face image to be identified.

[0028] Step S120, extracting a feature vector of the target cow face image through the trained cow face feature extraction model based on machine learning.

[0029] Among them, refer to Figure 1The cow face feature extraction model includes a convolutional layer (Conv1), a first dense layer (Dense1), a first transition layer (Trans1), a second dense layer (Dense2), a second transition layer (Trans2), a third dense layer (Dense3) and an average pooling layer (Avgpool2d) connected in sequence. The input of the convolutional layer is the target cow face image and the convolutional layer adopts standard convolution. The input of the first dense layer is the output of the convolutional layer, the input of the first transition layer is the output of the first dense layer, the input of the second dense layer is the output of the first transition layer, the input of the second transition layer is the output of the second dense layer, the input of the third dense layer is the output of the second transition layer, the input of the average pooling layer is the output of the third dense layer, and the output of the average pooling layer is the feature vector of the target cow face image.

[0030] Reference Figure 2 , the first dense layer, the second dense layer and the third dense layer have the same feature processing flow and the feature processing flow includes N rounds of feature processing steps, each round of feature processing steps includes:

[0031] Step S121, performing a standard convolution (Conv1) operation, a Relu activation operation, and a BN batch normalization operation on the first feature map in sequence to obtain a second feature map.

[0032] In step S122, a variant convolution (RIC-DConv) operation, a Relu activation operation, and a BN batch normalization operation are sequentially performed on the second feature map to obtain a third feature map. The variant convolution operation is implemented by a deformable convolution that incorporates rotation-invariant coordinates.

[0033] Among them, refer to Figure 4 The variant convolution operation includes: performing a standard convolution operation on the second feature map to obtain a first offset feature map; fusing the first offset and the rotation invariant coordinates through standard convolution to obtain a second offset feature map; integrating the first offset feature map and the second offset feature map to obtain a third offset feature map; performing a standard convolution on the third offset feature map to obtain a third feature map.

[0034] Specifically, the present invention combines rotation invariant coordinates (RIC) and deformable convolution (DConv) to obtain a new variant convolution (RIC-DConv). RIC-DConv is a deformable convolution that integrates rotation invariant coordinates. By integrating the offset of the deformable convolution with the rotation invariant coordinates, RIC-DConv can capture features of different rotation versions of local features in a consistent manner, thereby solving the problem of difficulty in identifying cows due to head shaking. Specifically, RIC-DConv fuses the offset (first offset) generated by the deformable convolution with the rotation invariant coordinates through a 1×1 standard convolution to obtain a rotation invariant coordinate offset (second offset) of the shape of B×(2×K×K)×W×H. The 1×1 standard convolution realizes information integration between different channels of the feature map, learns the weights of different channels, and offsets the rotation invariant coordinates through the offset, thereby identifying local rotation features.

[0035] Step S123, adding the third feature map to the first feature map to obtain a fourth feature map.

[0036] In N rounds of feature processing steps, the first feature map of the first round of feature processing steps is the dense layer input feature map, the fourth feature maps of the first N-1 rounds of feature processing steps are all used as the first feature maps of the next round of feature processing steps, and the third feature map of the Nth round of feature processing steps is the dense layer output feature map.

[0037] In the dense layer, there are mainly two sub-layers connected in sequence. The first sub-layer is used to implement standard convolution operations, Relu activation operations and BN batch normalization operations, and the second sub-layer is used to implement variant convolution operations, Relu activation operations and BN batch normalization operations. Each sub-layer of the dense layer is directly connected to all the previous sub-layers, realizing the dense connection of feature maps. Each sub-layer can directly access the feature maps of all previous sub-layers, thereby enhancing the reuse of feature maps, which can effectively reduce the number of parameters and the amount of calculation while maintaining or improving network performance.

[0038] Exemplarily, when the size of the first feature map is B×C×W×H, the size of the second feature map is B×(4×GrowthRate)×W×H, the size of the third feature map is B×GrowthRate×W×H, and the size of the fourth feature map is B×(C+GrowthRate)×W×H; wherein GrowthRate is a dense layer hyperparameter. In some embodiments, GrowthRate is 24; and / or, N is 7, that is, the dense layer internal loop performs 6 rounds of feature processing, and the result of the 7th round of feature processing is output to the next layer.

[0039] Reference Figure 3, the first transition layer and the second transition layer have the same feature processing flow and the feature processing flow includes:

[0040] Step S124, performing a standard convolution operation, a Relu activation operation, and a BN batch normalization operation on the transition layer input feature map in sequence to obtain a fifth feature map.

[0041] Step S125, performing an average pooling operation on the fifth feature map to obtain a transition layer output feature map.

[0042] Exemplarily, when the size of the transition layer input feature map is B×C×W×H, the size of the fifth feature map is B×(C×Reduction)×W×H, and the size of the transition layer output feature map is B×(C×Reduction)×(W / 2)×(H / 2); Reduction is a transition layer hyperparameter, and / or Reduction is 0.5.

[0043] In the transition layer (Trans), there are mainly two sublayers connected in sequence. The first sublayer is used to implement standard convolution operations, Relu activation operations and BN batch normalization operations, and the second sublayer is used to implement average pooling operations. The transition layer can control the complexity of the model and avoid overfitting of the model. The hyperparameter Reduction in the transition layer is 0.5. The Reduction parameter controls the degree of reduction in the number of feature maps in the network, which helps maintain the efficiency of the model and avoid excessive parameter growth.

[0044] In summary, the cow face feature extraction model adopted by the present invention has been introduced relatively completely. From the overall structure, the cow face feature extraction model is a densely connected network (DenseNet). At the same time, RIC-DConv is introduced, and the cow face feature extraction model can be defined as a RIC-DConv-DenseNet model.

[0045] In the model application stage, for example, an image of size B×3×32×32 can be input into the RIC-DConv-DenseNet model, and after Conv1, it becomes a feature block of B×48×32×32. The feature block then passes through Dense1, Trans1, Dense2, Trans2, Dense3 in sequence, and then passes through an 8×8 average pooling layer to obtain a B×264 vector. The final vector is the feature vector of the target cow face image, which can be applied to subsequent steps to achieve cow face recognition.

[0046] In order to make the cow face feature extraction model learn that the features of the same category are more closely clustered, while the differences between features of different categories are greater. In some embodiments, the cow face feature extraction model is trained using ArcFace Loss, that is, in the model training stage, the vector extracted by the model is given to the ArcFace classifier, and the ArcFace classifier classifies the vector and calculates the corresponding loss. The parameters of the cow face feature extraction model can be optimized by minimizing the loss. This training can make the model learn that the features of the same category are more closely clustered, while the differences between features of different categories are greater, because this can improve the classification accuracy of the ArcFace classifier.

[0047] Specifically, the core idea of ​​ArcFace Loss is to introduce an angle boundary in the feature space, so that the sample features of the same category are closer, and the angles between the sample features of different categories are larger. ArcFace Loss is achieved by adding an angle interval to the SoftMax loss function, and its formula is as follows:

[0048]

[0049] Among them, N represents the batch size, that is, the number of samples used in one training, n represents the total number of categories, and y i represents the true category label of the i-th sample, θ j Indicates the difference between the jth sample and its positive class (i.e., y i Category), m represents the angle offset, which is a hyperparameter used to increase the angular spacing between positive classes. Represents the cosine similarity after adding the angle offset, cos(θ j ) represents the cosine of the angle between the ith sample and the centers of all other categories, and s represents the scaling factor.

[0050] The B×264 feature vector obtained by the RIC-DConv-DenseNet network is input into ArcFace Loss for classification and recognition. In order to map the features onto the unit hypersphere, the input features and weights W need to be L2 normalized. The shape of weight W is 264×num_classes, where num_classes is the number of categories. The cosine value is calculated by the normalized B×264 feature vector and weight W, and the sine value is calculated by the cosine value. Then, the angle θ between each feature vector and the class center is calculated using the cosine value and the sine value. A predefined angle interval m is added to the angle θ to increase the interval between categories. The angle with the interval is remapped back to the feature space. At this time, the feature vector shape is B×num_classes. The feature vector is multiplied by the scaling factor s to control the distribution of the feature space, making the optimization process more stable. Finally, B×num_classes and the label are used to calculate the entropy loss to achieve classification.

[0051] Step S130, comparing the feature vector of the target cow face image with the feature vector of at least one prior cow face image of known category, and determining the category of the target cow face image according to the comparison result; wherein cow face images of the same category belong to the same cow.

[0052] The cow face recognition method provided by the present invention is mainly used to identify whether the cow face in the image is the face of the target cow. For example, in the insurance claim process of dairy cows, the target cow is the insured cow. The target cow can be one or more, so different recognition and comparison methods are used.

[0053] In some embodiments, step S130 specifically includes: calculating the cosine similarity between the feature vector of the target cow face image and the feature vector of a prior cow face image of known category, and if the cosine similarity is greater than a target threshold, determining that the category of the target cow face image is the same as the category of the prior cow face image. In this embodiment, there is one target cow and one corresponding prior cow face image. If the cosine similarity between the feature vector of the target cow face image and the feature vector of the prior cow face image is greater than the target threshold, then it is determined that the cow face in the target cow face image is that of the target cow, otherwise it is not.

[0054] In some other embodiments, step S130 specifically includes: respectively calculating the cosine similarity between the feature vector of the target cow face image and the feature vectors of multiple prior cow face images of known categories and determining the maximum cosine similarity. If the maximum cosine similarity is greater than the target threshold, it is determined that the category of the target cow face image is the same as the category of the prior cow face image corresponding to the maximum cosine similarity. In this embodiment, there are multiple target cows, and the cow face in the target cow face image may belong to only one of them. Therefore, first determine a prior cow face image with the largest cosine similarity between the feature vectors of the target cow face image, and the cow face in the target cow face image is most likely to belong to the target cow corresponding to the prior cow face image. If the maximum cosine similarity between the feature vector of the target cow face image and the feature vector of the prior cow face image is greater than the target threshold, it is determined that the cow face in the target cow face image is the target cow corresponding to the maximum cosine similarity, otherwise it is considered that the cow face in the target cow face image does not belong to any target cow.

[0055] It should be noted that, since ArcFace Loss uses cosine similarity to calculate the similarity between each vector, cosine similarity is used in category judgment to determine whether different vectors belong to the same category. Specifically, the cosine similarity range is between -1 and 1. The closer the cosine similarity of two feature vectors is to 1, the more similar they are. Then, a target threshold can be set between -1 and 1, and when the cosine similarity of two feature vectors is greater than the target threshold, the two feature vectors belong to the same category. If the two feature vectors are in an embodiment using other loss functions, other similarities can also be used in category judgment to determine whether different vectors belong to the same category.

[0056] Furthermore, the step of determining the target threshold includes:

[0057] Step S131, randomly constructing multiple pairs of cow face images, and determining whether the two cow face images in each pair of cow face images belong to the same category of labels.

[0058] The two cow face images in the cow face image pair may belong to the same cow or not. Since they are randomly constructed, the ratio between the two is close to one to one. The labels of whether they belong to the same category can be represented by 1 (same category) or 0 (different categories).

[0059] Step S132, extracting feature vectors of each cow face image respectively through the trained cow face feature extraction model, and calculating the cosine similarity between the feature vectors of two cow face images in each pair of cow face images respectively.

[0060] Step S133, determining the current similarity threshold.

[0061] Step S134, for each pair of cow face images, if the cosine similarity of the two cow face images is greater than the current similarity threshold, then it is determined that they belong to the same category, otherwise it is determined that they do not belong to the same category;

[0062] Step S135 , comparing the determination result of whether the two cow face images in each pair of cow face images belong to the same category with the corresponding labels to obtain the determination accuracy rate.

[0063] For step S133-step S135, illustratively, there are 5 pairs of cow face image pairs, the labels of the first 3 pairs are of the same type, and the labels of the last 2 pairs are of different types. The cosine similarities of the cow face image pairs are 0.9 / 0.6 / 0.3 / 0 / -0.3 respectively. When the current similarity threshold is -0.1, the classification results of the cow face image pairs are of the same type, the same type, the same type, the same type, and different types respectively. By comparing the classification results with the labels, it can be obtained that the judgment accuracy is 80%.

[0064] Step S136, updating the current similarity threshold and obtaining the corresponding determination accuracy until all possible similarity thresholds are traversed.

[0065] This step is to repeatedly perform step S133-step S135 until all possible similarity thresholds have obtained corresponding determination accuracy. For example, for cosine similarity, the value range is between -1 and 1, then a value interval can be set to determine all values ​​between -1 and 1 as similarity thresholds in turn.

[0066] Step S137: determine the similarity threshold corresponding to the highest determination accuracy as the target threshold.

[0067] After obtaining the determination accuracy rates corresponding to the respective similarity thresholds, the similarity threshold corresponding to the highest determination accuracy rate is determined as the target threshold.

[0068] As mentioned above, at least one embodiment of each part of the cow face recognition method provided by the present invention has been described respectively. It should be noted that each part of the cow face recognition method can be combined with different embodiments to form different embodiments of the cow face recognition method.

[0069] For example, in a specific embodiment, a RIC-DConv-DenseNet model is provided. The cow face recognition method uses the model to characterize cow face images, and then calculates the class center of each cow face image to enhance the intra-class compactness and inter-class separability, thereby performing cow face recognition.

[0070] The training steps of the RIC-DConv-DenseNet model mainly include:

[0071] (1) The facial images of 240 cattle were collected and stored in various folders.

[0072] (2) Divide the data into batches and input them into RIC-DConv-DenseNet.

[0073] (3) Use the RIC-DConv-DenseNet feature extractor to output a 264-dimensional feature vector.

[0074] (4) The output 264-dimensional feature vector is passed through Arcface loss to update the classification weights and enhance the intra-class compactness and inter-class separability.

[0075] (5) Set the number of cycles to update the network.

[0076] (6)End.

[0077] The cow face recognition method using the RIC-DConv-DenseNet model has extremely high practical value and application potential, especially in the fields of agricultural technology and animal husbandry. Its main function is to accurately extract and digitally characterize the facial features of cows through advanced image processing technology, and then make a detailed similarity comparison between these features and the registered cow face features stored in the database. In this way, the system can effectively identify specific individual cows, which is especially important in the process of dairy cow insurance claims.

[0078] The introduction of this technology is mainly aimed at solving a key problem in dairy cow insurance claims: how to accurately determine whether the cow in the submitted image is an insured individual. In this process, traditional methods, such as ear tags or other physical marks, may be at risk of damage or tampering, and this image recognition-based method provides a more reliable and accurate solution.

[0079] The main steps of the cow face recognition method include:

[0080] Image collection and processing: It starts with the collection and processing of cow face images, and uses the pre-trained RIC-DConv-DenseNet model to extract cow face image features. This feature is usually a set of one-dimensional vectors, which are generated by all images in the system and stored as indexes by image names.

[0081] Image matching: After uploading a cow image, use the RIC-DConv-DenseNet model to extract the cow face image feature vector, compare the vector with all feature vectors in the system for similarity, and get a similarity list. Find the maximum value in the similarity and compare it with the set threshold: If the maximum value in the similarity is less than the set threshold, it is determined that the input cow image is not in the system. If the maximum value in the similarity is greater than the set threshold, the identity of the cow is confirmed, thereby providing key support for insurance claims. In addition, this technology not only improves the efficiency and accuracy of the claims process, but also provides a powerful tool for dairy cow management and monitoring. For example, it can be used to track the health status, production efficiency and other important indicators of specific cows, thereby providing important data support for farm managers.

[0082] In summary, this cow face retrieval system based on image recognition not only plays a vital role in the field of agricultural insurance, but also opens up a new path for the intelligent management of modern animal husbandry. By efficiently and accurately identifying and tracking individual cattle, the system brings innovation and value to the industry and significantly improves the efficiency of management and operations.

[0083] Example results: Label is 0: It means that the identification is not a cow. Label is 1: It means that the identification is a cow and the similarity is given. This helps to confirm the identity of the cow and ensure the accuracy of the insurance claim process. Figure 5 This is an example of cow face recognition results.

[0084] RIC-DConv-DenseNet model introduction:

[0085] Reference Figure 1 ,RIC-DConv-DenseNet model includes input, Conv, Dense, Trans, pooling, and output.

[0086] Reference Figure 2The network structure of Dense is the Dense Block module in the figure, which is the dense layer in DenseNet. The hyperparameter GrowthRate in this module is 24. The Dense Block module first performs a convolution, Relu activation function and BN batch normalization on the input feature block with a shape of B×C×W×H to obtain a feature map of B×(4×GrowthRate)×W×H. Then, the feature map of B×(4×GrowthRate)×W×H is downsampled, and a feature map of B×GrowthRate×W×H is obtained through RIC-DConv convolution, Relu activation function and BN batch normalization. The feature map is spliced ​​with the input feature in the channel dimension to obtain an output feature map with a shape of B×(C+GrowthRate)×W×H. Finally, the output feature map is repeated 6 times as the input feature map to end a Dense output. Each layer of Dense is directly connected to all previous layers, realizing dense connection of features. Each layer can directly access the feature maps of all previous layers, thereby enhancing feature reuse, which can effectively reduce the number of parameters and the amount of calculation while maintaining or improving network performance.

[0087] Reference Figure 3 , Trans's network structure is the Transition Layer module in the figure, which is the transition layer in DenseNet. The transition layer can control the complexity of the model and avoid overfitting of the model. The hyperparameter Reduction in the Transition Layer module is 0.5. The Reduction parameter controls the degree of reduction in the number of feature maps in the network, which helps to maintain the efficiency of the model and avoid excessive parameter growth. The Transition Layer module performs a convolution, Relu activation function and BN batch normalization on the input feature block of shape B×C×W×H to obtain a feature map of shape B×(C×Reduction)×W×H, and then an average pooling is performed to obtain an output feature map of shape B×(C×Reduction)×(W / 2)×(H / 2).

[0088] The B×3×32×32 image is input into the RIC-DConv-DenseNet network model, and becomes a B×48×32×32 feature block after Conv1. The feature block then passes through Dense1, Trans1, Dense2, Trans2, Dense3, and then passes through an 8×8 average pooling layer to obtain a B×264 vector. During the model training phase, the B×264 vector needs to be input into ArcFace Loss for classification and recognition.

[0089] The core idea of ​​ArcFace Loss is to introduce an angle boundary in the feature space, so that the sample features of the same category are closer, while the angles between the sample features of different categories are larger. ArcFace Loss is implemented by adding an angle interval to the SoftMax loss function, and its formula is as follows:

[0090]

[0091] Among them, N represents the batch size, that is, the number of samples used in one training, n represents the total number of categories, and y i represents the true category label of the i-th sample, θ j Indicates the difference between the jth sample and its positive class (i.e., y i Category), m represents the angle offset, which is a hyperparameter used to increase the angular spacing between positive classes. Represents the cosine similarity after adding the angle offset, cos(θ j ) represents the cosine of the angle between the ith sample and the centers of all other categories, and s represents the scaling factor.

[0092] The B×264 feature vector obtained by the RIC-DConv-DenseNet network is input into ArcFace Loss for classification and recognition. In order to map the features onto the unit hypersphere, the input features and weights W need to be L2 normalized. The shape of weight W is 264×num_classes, where num_classes is the number of categories. The cosine value is calculated by the normalized B×264 feature vector and weight W, and the sine value is calculated by the cosine value. Then, the angle θ between each feature vector and the class center is calculated using the cosine value and the sine value. A predefined angle interval m is added to the angle θ to increase the interval between categories. The angle with the interval is remapped back to the feature space. At this time, the feature vector shape is B×num_classes. The feature vector is multiplied by the scaling factor s to control the distribution of the feature space, making the optimization process more stable. Finally, B×num_classes and the label are used to calculate the entropy loss to achieve classification.

[0093] In the model training phase, Arcface Loss is used to update the model training parameters, so that the model learns that the features of cattle samples in the same category are more closely clustered, while the features of samples in different categories are more different. In the testing phase, the optimal threshold (target threshold) is calculated by the set image pair. Finally, the optimal threshold is used to determine whether the two cattle feature vectors are of the same category, because Arcface Loss uses the cosine distance to calculate the distance between the two vectors. The cosine distance ranges from -1 to 1. The closer the cosine distance of the two feature vectors is to 1, the smaller the distance. Therefore, when the cosine distance of the two feature vectors exceeds the optimal threshold, they are judged to be of the same category (the same individual cattle), otherwise they are of different categories (different individual cattle).

[0094] The cow face recognition method in the above specific embodiment is verified through some experiments as follows.

[0095] Dataset:

[0096] The dataset used contains facial images of 240 individual cows. These images contain various postures of cows shaking their heads. First, resize the image size of the cow face data to 32×32. Store the image of each cow in a folder, and number the 240 cows from 0 to 239. Each cow is considered a separate category. Each category contains 15 RGB images of different postures, a total of 3600 cow face images, which constitute a small sample dataset. Among the 240 cow categories, 0-119 are used for closed dataset experimental comparison, and 120-239 are used for open dataset experimental comparison. In the 0-119 cow categories, 1800 cow face images are divided into a dataset of 6:4, 1080 images are used for training set, and 720 images are used for validation set. The test part needs to obtain the optimal threshold (target threshold).

[0097] The process of confirming the optimal threshold is as follows: input a list of image pairs and labels indicating whether each pair of images is similar, calculate the cosine similarity list of the image pairs, sort the cosine similarity values, traverse all possible thresholds, and calculate the classification accuracy for each possible threshold. The threshold corresponding to the highest accuracy will be selected as the optimal threshold.

[0098] For the cow face comparison and recognition experiment of the open dataset, 3000 closed dataset image pairs were generated from images in the cattle categories 0-119 (the image pair generation process is: constructing image pairs by randomly selecting two images, the input content includes the path of the image folder and the number of image pairs to be generated, and the output is the image pair and its corresponding label. The algorithm constructs image pairs cyclically according to the number of input image pairs. In order to prevent the imbalance of the number of image pairs of the same class and image pairs of different classes in the generated image pairs, the image pair label is represented by a randomly generated 0 or 1. When the label of the image pair is 1, the two images belong to the same category, and when the label of the image pair is 0, the two images belong to different categories. The randomly generated labels ensure that the probabilities of generating image pairs of the same class and image pairs of different classes are consistent), and the trained RIC-DConv-DenseNet model is used to extract features from the closed dataset image pairs, calculate the cosine similarity of the image pair feature vectors, obtain the similarity list, and obtain the optimal threshold of the model. 3000 open dataset image pairs were generated from images in the cattle category 120-239, and the optimal threshold was used to test the 3000 open dataset image pairs.

[0099] Experimental setup:

[0100] This experiment was completed using a computer with a Tesla P4023 GB GPU and a Pytorch 1.10.0 deep learning framework development platform on a Centos 7.9 operating system. The experiment used the moving average accuracy as the evaluation metric. The moving average accuracy is a method for evaluating model performance by calculating the average accuracy of all previous iterations. The SGD optimizer was used in the experiment, with a learning rate of 1e-4, and the learning rate was decreased using the cosine annealing method. The scaling factor s=64 in ArcFace Loss, and the additional interval m=0.5 for the angle between categories.

[0101] Experimental results:

[0102] 1. Experimental comparison and analysis of RIC-DConv-DenseNet and other recognition network models

[0103] Table 1 Experimental results of RIC-DConv-DenseNet compared with other recognition models

[0104] Model MovingAverageAccuracy(%) ResNet18 70.93% ResNet50 75.62% MobileNetV1 82.5% MobileFaceNet 83.43% DenseNet40 89.34% RIC-DConv-DenseNet 93.66%

[0105] In order to prove that RIC-DConv-DenseNet has good performance in the cow face recognition task, five models, ResNet18, ResNet50, DenseNet40, MobileNetV1 and MobileFaceNet, were selected for experimental comparison. Classic deep convolutional neural network models such as ResNet18 and ResNet50 are combined with ArcFace Loss to perform individual cow face recognition. Lightweight neural network models MobileNetV1 and MobileFaceNet are used to achieve efficient face recognition on mobile devices. The proposed RIC-DConv-DenseNet is compared with the above five recognition network models. Their advantages and disadvantages in the task of individual cow face recognition are discussed. Table 1 shows the experimental results of RIC-DConv-DenseNet and other recognition models. The results show that ResNet50 has a 4.69% higher accuracy than ResNet18, which is attributed to the deeper network structure of ResNet50 than ResNet18. As an improved version of MobileNetV1, MobileFaceNet uses improved global deep convolution to effectively capture differential features at different locations in the feature map. The accuracy of MobileFaceNet is 0.93% higher than that of MobileNetV1. The accuracy of DenseNet40 reaches 89.34%. This is because, in the cow face recognition task, the underlying features such as color, texture and edge play an important role in recognition. The dense connection mechanism of DenseNet enables each layer in the network to directly access the feature maps from all previous layers and use them as input, so that the underlying features of the cow face image can be repeatedly used in the deeper layers of the network, thereby improving the accuracy of the model. The proposed RIC-DConv-DenseNet model replaces the feature fusion convolution in the dense block of DenseNet with a deformable convolution that fuses rotationally invariant coordinates, so that the model can extract features from different images formed by the shaking of the cow's head in a consistent manner. The dense blocks in the model can also repeatedly use the captured cow face image features to effectively recognize the cow face. The accuracy of RIC-DConv-DenseNet reached 93.66%, which was 4.32% higher than that of the DenseNet model, proving that RIC-DConv-DenseNet has a significant advantage in the cow face recognition task.

[0106] 2. Ablation experiment:

[0107] To ensure the fairness of the experiment, other parameters are set the same in the experiment. DenseNet is used as the baseline model for comparison. RIC-DenseNet is a DenseNet using rotation-invariant convolution (RIC-CNN). DConv-DenseNet is a DenseNet using deformable convolution (DConv), and RIC-DConv-DenseNet is a DenseNet using RIC-DConv.

[0108] Table 2 Ablation experiment results

[0109] Model MovingAverageAccuracy(%) DenseNet 89.34% RIC-DenseNet 91% DConv-DenseNet 92.16% RIC-DConv-DenseNet 93.66%

[0110] Table 2 shows the experimental results. On the validation set, the accuracy of DenseNet reached 89.34%. The RIC-DenseNet model with rotation invariance increased the accuracy to 91%, which proves that rotation invariance is effective in the recognition performance of some cow face images. However, since the shaking of the cow's head is mainly manifested as local rotation of the image, there are certain limitations in improving the cow face recognition performance by only using rotation invariant convolution. DConv-DenseNet further improves the model to 92.16% accuracy by strengthening the adaptability to local deformation of the image, indicating that strengthening the consideration of local deformation is an effective way to improve the accuracy in the cow face recognition task. The RIC-DConv-DenseNet model, which combines rotation invariant coordinates and deformable convolution, achieved the highest accuracy of 93.66%. This result shows the importance of focusing on both rotation invariance and deformation adaptability in the cow face recognition task. RIC-DConv-DenseNet effectively handles the problem of recognition difficulties caused by the shaking of the cow's head by integrating these two technologies.

[0111] 3. Comparison and analysis of cow face recognition experiments on open datasets.

[0112] In the cow face recognition experiment of the open dataset, the following steps can be performed. The optimal threshold is found by completing the trained model, and the optimal threshold is used to distinguish similar and dissimilar sample pairs. Using 3000 image pairs generated by the closed dataset, the threshold can be used to distinguish whether the cow face image pairs are of the same class.

[0113] The optimal threshold is used to test 3000 image pairs of the open dataset, and the experimental results are shown in Table 3.

[0114] Table 3 Comparison results of the open dataset 3000 image pair recognition experiment

[0115]

[0116] The experimental results show that ResNet18, ResNet50, DenseNet40, MobileNetV1, MobileFaceNet and RIC-DConv-DenseNet have achieved high accuracy in the experimental results of 3000 image pairs of the closed dataset. This phenomenon is attributed to the fact that the model fully learns the characteristics of the cow face in the closed dataset during the training process, so it can achieve a high accuracy in the recognition of closed image pairs. RIC-DConv-DenseNet achieved an accuracy of 99.77% in the experiment of 3000 image pairs of the closed dataset, which exceeds other recognition models. The trained model is tested on 3000 image pairs of the open dataset after obtaining the optimal threshold through Algorithm 2. In the experiment, the accuracy of the RIC-DConv-DenseNet model is 89.53%, which exceeds DenseNet (88.80%), Mobilefacenet (87.70%), Mobilenetv1 (86.10%), Resnet50 (86.66%), and Resnet18 (85.26%). Experimental results show that in the cow face recognition task, RIC-DConv-DenseNet can effectively identify the image produced by shaking the cow's head, and this advantage is also applicable to the comparative recognition task of the open cow face dataset.

[0117] Figure 6 The following are the results of DenseNet and RIC-DConv-DenseNet recognition of cow face images. All the image pairs in the figure are from the image pairs of open data sets. The left one is the result of DenseNet recognition of cow face images, and the right one is the result of RIC-DConv-DenseNet recognition of cow face images. The best threshold obtained by DenseNet is 0.6967, so Figure 6 The four image pairs in the image are identified by threshold comparison, and the optimal threshold obtained by RIC-DConv-DenseNet is 0.6021, so Figure 6 The four image pairs in the figure are correctly identified through threshold comparison. It can be concluded from the figure that in the cow face recognition task, the cow's head shaking presents different appearances, resulting in changes in the angle and position of the cow's face in the image. This significant change makes it difficult to accurately identify the cow's face. The cow's head twists to cause the face to rotate, and the RIC-DConv-DenseNet model can well capture the key features in the image caused by the shaking of the cow's face, and effectively identify the cow's face image through these key features.

[0118] 4. Summary.

[0119] To overcome the problem of recognition difficulties caused by the shaking of the cow's head, we proposed a method for comparative recognition of cow faces based on the RIC-DConv-DenseNet network. The rotation-invariant coordinate convolution (RIC-CNN) in this method can maintain the consistency of recognition for objects rotated about the center of the image. Deformable convolution (DConv) provides additional flexibility, allowing the convolution kernel to adaptively adjust its shape to better match the features of the cow's face. RIC-DConv combines rotation-invariant coordinates with deformable convolution to enable the model to capture features of different rotation versions of local features in a consistent manner. Therefore, RIC-DConv can recognize different images of cows formed by shaking their heads. The RIC-DConv-DenseNet network is trained with the metric function ArcFace Loss to enable the model to extract more discriminative cow face features. The model performance is verified and analyzed in the image pair recognition task of the open cow face dataset, realizing cow face recognition based on one-shot learning.

[0120] Through a series of experiments, this paper compares RIC-DConv-DenseNet with several existing network models, including ResNet18, ResNet50, DenseNet40, MobileNetV1 and MobileFaceNet. The experiments show that RIC-DConv-DenseNet achieves an accuracy of 93.66% on the validation set, which exceeds other recognition models. In the image pair recognition experiment of the closed cow face dataset containing 120 cows, the recognition rate reaches 99.77%. In the image pair recognition experiment of the open cow face dataset containing 120 cows, the recognition rate reaches 89.53%. The results show that our method of cow face comparison recognition based on the RIC-DConv-DenseNet network shows excellent recognition effect when dealing with the problem of difficulty in recognition due to head shaking of cows, and this effect can be applied to the recognition task of the open cow face dataset.

[0121] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.

[0122] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.

Claims

1. A cow face recognition method, characterized in that: include: Obtain a target cow face image to be identified; Extracting a feature vector of the target cow face image by using a trained cow face feature extraction model based on machine learning; Comparing the feature vector of the target cow face image with the feature vector of at least one prior cow face image of known category, and determining the category of the target cow face image according to the comparison result; wherein cow face images of the same category belong to the same cow; The cow face feature extraction model comprises a convolution layer, a first dense layer, a first transition layer, a second dense layer, a second transition layer, a third dense layer and an average pooling layer connected in sequence, the input of the convolution layer is the target cow face image, and the output of the average pooling layer is the feature vector of the target cow face image; The first dense layer, the second dense layer and the third dense layer have the same feature processing flow, and the feature processing flow includes N rounds of feature processing steps, and each round of the feature processing steps includes: The first feature map is sequentially subjected to a standard convolution operation, a Relu activation operation, and a BN batch normalization operation to obtain a second feature map; Performing a variant convolution operation, a Relu activation operation, and a BN batch normalization operation on the second feature map in sequence to obtain a third feature map, wherein the variant convolution operation is implemented by a deformable convolution that incorporates rotation invariant coordinates; Adding the third characteristic map to the first characteristic map to obtain a fourth characteristic map; In the N rounds of feature processing steps, the first feature map of the first round of feature processing steps is the dense layer input feature map, the fourth feature maps of the first N-1 rounds of feature processing steps are all used as the first feature maps of the next round of feature processing steps, and the third feature map of the Nth round of feature processing steps is the dense layer output feature map.

2. The cow face recognition method according to claim 1, characterized in that: When the size of the first feature map is B×C×W×H, the size of the second feature map is B×(4×GrowthRate)×W×H, the size of the third feature map is B×GrowthRate×W×H, and the size of the fourth feature map is B×(C+GrowthRate)×W×H; The GrowthRate is a dense layer hyperparameter.

3. The cow face recognition method according to claim 2, characterized in that: The GrowthRate is 24; and / or, the N is 7.

4. The cow face recognition method according to claim 2, characterized in that: The variant convolution operation includes: Performing a standard convolution operation on the second feature map to obtain a first offset feature map; fusing the first offset and the rotation invariant coordinates through standard convolution to obtain a second offset feature map; Integrate the first offset feature map and the second offset feature map to obtain a third offset feature map; Performing standard convolution on the third offset feature map to obtain the third feature map.

5. The cow face recognition method according to claim 1, characterized in that: The first transition layer and the second transition layer have the same feature processing flow and the feature processing flow includes: The fifth feature map is obtained by sequentially performing standard convolution operation, Relu activation operation and BN batch normalization operation on the input feature map of the transition layer; An average pooling operation is performed on the fifth feature map to obtain a transition layer output feature map.

6. The cow face recognition method according to claim 5, characterized in that: When the size of the transition layer input feature map is B×C×W×H, the size of the fifth feature map is B×(C×Reduction)×W×H, and the size of the transition layer output feature map is B×(C×Reduction)×(W / 2)×(H / 2); The Reduction is a transition layer hyperparameter, and / or the Reduction is 0.

5.

7. The cow face recognition method according to any one of claims 1 to 6, characterized in that: The cow face feature extraction model is trained using ArcFace Loss.

8. The cow face recognition method according to any one of claim 7, characterized in that: Comparing the feature vector of the target cow face image with the feature vector of at least one prior cow face image of known category, and determining the category of the target cow face image according to the comparison result, comprising: The cosine similarity between the feature vector of the target cow face image and the feature vector of a prior cow face image of known category is calculated. If the cosine similarity is greater than a target threshold, it is determined that the category of the target cow face image is the same as the category of the prior cow face image.

9. The cow face recognition method according to any one of claim 7, characterized in that: Comparing the feature vector of the target cow face image with the feature vector of at least one prior cow face image of known category, and determining the category of the target cow face image according to the comparison result, comprising: The cosine similarities between the feature vector of the target cow face image and the feature vectors of multiple prior cow face images of known categories are respectively calculated and a maximum cosine similarity is determined. If the maximum cosine similarity is greater than a target threshold, it is determined that the category of the target cow face image is the same as the category of the prior cow face image corresponding to the maximum cosine similarity.

10. The cow face recognition method according to claim 8 or 7, characterized in that: The step of determining the target threshold comprises: Randomly construct multiple pairs of cow face images, and determine whether the two cow face images in each pair of cow face images belong to the same category; Extracting feature vectors of each cow face image respectively through the trained cow face feature extraction model, and calculating the cosine similarity between the feature vectors of two cow face images in each pair of cow face images respectively; Determine the current similarity threshold; For each pair of cow face images, if the cosine similarity of the two cow face images is greater than the current similarity threshold of the pair, then they are determined to belong to the same category, otherwise, they are determined not to belong to the same category; Comparing the determination result of whether the two cow face images in each pair of cow face images belong to the same category with the corresponding labels to obtain the determination accuracy rate; Update the current similarity threshold and obtain the corresponding judgment accuracy until all possible similarity thresholds are traversed; The similarity threshold corresponding to the highest determination accuracy is determined as the target threshold.