A fine-grained cattle face recognition method based on multi-view triplets of cattle faces
By constructing triplet samples for cow face recognition and combining them with a feature fusion mechanism, the problems of insufficient model robustness and incomplete data in cow face recognition are solved, achieving efficient and low-cost cow face recognition results, which are suitable for large-scale farms.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JILIN UNIVERSITY
- Filing Date
- 2025-12-27
- Publication Date
- 2026-06-26
AI Technical Summary
Existing cattle face recognition technology suffers from insufficient model robustness and incomplete data in large-scale intensive farming, especially the incomplete collection of multi-view data on cattle faces, resulting in low recognition accuracy and difficulty in meeting the needs of efficient management.
A fine-grained recognition method using bull face multi-view triplets is adopted. Three-view data are acquired through image acquisition equipment to construct triplet samples. Features are fused using a local receptive field fine-grained feature compression module and a cross-attention mechanism. The model is optimized by combining the cross-entropy loss function to achieve cross-view feature learning and data augmentation.
It significantly improves the robustness and accuracy of cow face recognition, reduces hardware costs, is suitable for widespread application in large-scale farms, and maintains high recognition efficiency even in the absence of data.
Smart Images

Figure CN122290167A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of cow face recognition technology, specifically a fine-grained cow face recognition method based on multi-view cow face triples. Background Technology
[0002] With the rapid development of precision animal husbandry and intelligent farming technologies, individual cattle identification has become the core foundation for realizing digital management of the farming process, playing an irreplaceable role in precision feeding, health monitoring, reproductive management, and product traceability. Traditional identification methods, such as ear tags and RFID tags, suffer from drawbacks such as high cost, easy detachment, and invasive installation that affects animal welfare, making it difficult to meet the efficient management needs of large-scale intensive farming. Computer vision-based cattle face recognition technology, with its advantages of non-invasiveness, automation, and low cost, has become an important direction for industry technology upgrading. However, it still faces significant challenges in practical applications: First, existing facial recognition models are mostly designed for human faces, and when directly applied to cattle faces, the high similarity between different cattle faces and the large differences in appearance of the same cattle from multiple perspectives lead to insufficient model robustness. Second, in real-world scenarios, multi-view data of cattle faces is often incomplete, with some perspective samples being scarce, making it easy for traditional methods to cause a decline in model performance during training.
[0003] To address this, we propose a fine-grained cow face recognition method based on multi-view cow face triples. Summary of the Invention
[0004] The purpose of this invention is to provide a fine-grained cow face recognition method based on multi-view cow face triples to solve the problems mentioned in the background art.
[0005] To achieve the above objectives, the present invention provides the following technical solution: a fine-grained cow face recognition method based on multi-view cow face triples, comprising the following steps:
[0006] S1: Multi-view data acquisition of cow faces, acquiring three-view image data of the left, front and right sides of each cow's face through image acquisition equipment;
[0007] S2: Data preprocessing and triplet construction: Use the view prediction model to classify the view of cow face images and construct triplet samples from the left, front, and right view images of the same cow.
[0008] S3: Construct a cow face triplet recognition model based on hierarchical receptive field fine-grainedness. Input the images of each viewpoint in the triplet into the feature extraction network, obtain fine-grained features through the local receptive field fine-grained feature compression module, fuse multi-view features through the cross-attention mechanism, and finally output the recognition result through the classification module.
[0009] S4: Model training and optimization. The model is trained using the constructed triplet dataset, and the model parameters are optimized using the cross-entropy loss function.
[0010] S5: Model Inference and Application. Input the cow face image to be recognized into the trained model and obtain the recognition result.
[0011] Preferably, step S1 specifically includes:
[0012] S11: Use a mobile app to capture three-view video of cow faces. The video size is 1920×1080, the frame rate is 60fps, and 30-60 seconds of 180° surround video of each cow, including the left side, right side and front face.
[0013] S12: Deduplication and frame extraction of video data. Merge the face data of the same cow based on the ear tag information, and use the frame extraction algorithm to extract static images from the video at a frequency of 2 frames per second.
[0014] Preferably, step S2 specifically includes:
[0015] S21: Train a cow face view prediction model, perform three-view manual annotation on some cow face images, and train a CFVPM view prediction model based on a deep convolutional network.
[0016] S22: Use the trained CFVPM model to predict the viewpoint of the cow face image and output the prediction result v∈{0,1,2}, where 0 represents the left side of the face, 1 represents the right side of the face, and 2 represents the frontal face.
[0017] S23: Construct cow face triples. For multiple images of each cow, randomly organize the images from different viewpoints into multiple triple samples Trindex∈{i0,i1,i2} based on the viewpoint prediction results, where i0, i1, and i2 represent the left face, right face, and frontal face images, respectively.
[0018] Preferably, the feature extraction network in step S3 specifically includes:
[0019] S31: Input the cow face image Trindexc from each viewpoint in the triplet into the SwinTransformer feature extractor to obtain 4 feature maps F in the 4 stages of the SwinTransformer backbone network. i Where i = 1, 2, 3, 4, and the feature map dimension of each Stage is F. i ∈{Hi,Wi,Ci};
[0020] S32: Transfer feature map F i Input the local receptive field fine-grained feature compression module to obtain the local sampled map PSi, calculated using the following formula:
[0021] PS i =Softmax(Conv 1×1 (F i ));
[0022] PS i ∈{Hi,Wi,Ci / 2},Conv 1×1 It is a convolutional layer with a kernel size of 1×1, an input dimension of Ci, and an output dimension of Ci / 2;
[0023] S33: Multiply the local sampled image PSi element-wise with the feature map Fi to obtain the fine-grained feature map PFi based on local sampling. The calculation formula is as follows:
[0024]
[0025] Where PF i ∈{Ci / 2,Ci},S i (a,b) is PS i The value of F at position (a, b) i (a,b) is F i The value at position (a, b);
[0026] S34: Input the local sampling fine-grained feature map PFi and the global receptive field feature map F4 into the cross-attention calculation module to obtain the cow face fine-grained pixel-level features F for each stage. i The calculation formula is:
[0027]
[0028] F i = Softmax(Attention) i Value i ;
[0029] in B is a learnable weight matrix. i For the bias term, F i ′∈{H4,W4,C i}
[0030] Preferably, the model training in step S4 specifically includes:
[0031] S41: Divide the triplet dataset into a training set, a validation set, and a test set;
[0032] S42: Initialize model parameters. Use ImageNet pre-trained weights to initialize the SwinTransformer feature extractor, and use random initialization for the rest.
[0033] S43: Use the cross-entropy loss function to calculate the error between the predicted result and the true label. The calculation formula is as follows:
[0034]
[0035] Where N is the batch size, C is the total number of categories, and y i,c The true label of sample i in category c. This represents the model's predicted probability for sample i in category c.
[0036] S44: Calculate the gradient using the backpropagation algorithm, and update the model parameters using the stochastic gradient descent algorithm or the Adam optimizer;
[0037] S45: Evaluate the model performance on the validation set and save the best model based on the validation set accuracy;
[0038] The model training process also includes data augmentation operations, including:
[0039] The input image is randomly horizontally flipped with a flip probability of 0.5.
[0040] The input image is randomly rotated within the range of [-15°, 15°];
[0041] The input image is randomly cropped to 80%–100% of the original image size;
[0042] Color jitter is applied to the input image, including random adjustments to brightness, contrast, and saturation.
[0043] Preferably, the model inference in step S5 specifically includes:
[0044] S51: Load the trained model weights and set the model to inference mode;
[0045] S52: Preprocess the cow face image to be identified, including resizing, normalization and viewpoint prediction;
[0046] S53: Input the preprocessed image into the model to obtain the feature extraction results;
[0047] S54: Calculate the similarity with registered cattle based on the feature extraction results. If the similarity exceeds the preset threshold, output the recognition result; otherwise, mark it as an unknown individual.
[0048] S55: Assess the confidence level of the identification results and recommend manual review for low-confidence results;
[0049] In step S54, the similarity calculation uses cosine similarity, and the calculation formula is as follows:
[0050]
[0051] Where f query Let f be the feature vector of the cow face to be identified. registered The feature vectors of the registered cattle.
[0052] Preferably, the following steps are also included:
[0053] S6 model deployment:
[0054] Convert the trained model to ONNX format to enable cross-platform deployment;
[0055] TensorRT is used for inference optimization, including layer fusion, precision calibration, and automatic kernel tuning.
[0056] Deploy the model inference service, supporting a RESTful API interface with JSON request format;
[0057] Implement request queue management and load balancing to support concurrent processing of multiple identification requests;
[0058] S7: System Monitoring and Maintenance Steps:
[0059] Collect system performance metrics in real time, including throughput, response time, and recognition accuracy;
[0060] Regularly evaluate model performance on independent test sets and monitor performance trends;
[0061] Implement an anomaly detection mechanism to trigger an alarm when performance indicators drop below a preset threshold.
[0062] Update the model regularly, and retrain or fine-tune it using new data.
[0063] Preferably, it also includes data quality control steps:
[0064] Automatic quality assessment of input images, including sharpness, brightness, contrast, and integrity checks;
[0065] Use an object detection model to locate the cow face region to ensure that the input image contains a complete cow face;
[0066] Images that do not meet quality requirements are automatically rejected or marked, and quality issues are reported.
[0067] For low-quality but critical images, try using image enhancement techniques to improve them before further processing;
[0068] User interface.
[0069] Compared with the prior art, the beneficial effects of the present invention are:
[0070] 1. Non-invasive collection of multi-view videos of cow faces can be completed through a regular mobile phone APP, which fundamentally avoids animal stress and potential harm caused by the installation of traditional ear tags or RFID tags, significantly improves animal welfare, and greatly reduces hardware deployment and maintenance costs, making it more suitable for widespread application in large-scale farms.
[0071] 2. To address the core challenge of "high inter-class similarity and large intra-class multi-view differences" in cow face recognition, this method designs a multi-view triplet sample construction and hierarchical fine-grained feature extraction and fusion mechanism. By constructing structured triplets from left, front, and right perspectives, the model is forced to learn the invariant features of the same cow across different perspectives and the subtle discriminative features between different cows. Combined with a local receptive field fine-grained feature compression module and a cross-attention fusion mechanism, the model can effectively capture the subtle textures and structural differences in key regions of the cow face and achieve the complementarity and enhancement of multi-view information, thereby significantly improving the robustness to changes in illumination, pose, and local occlusion, and overcoming the bottleneck of low accuracy in cow face recognition.
[0072] 3. Addressing the common challenges of incomplete multi-view data collection and scarce single-view samples in real-world scenarios, this method proposes a triplet construction strategy that forms an efficient closed loop with the view prediction model (CFVPM). Even if the original image of a certain view is missing, the system can complete the triplet through data augmentation or synthesis techniques. Combined with the idea of few-shot learning, the model can adapt to incomplete data distribution during the training phase. This greatly reduces the dependence on high-quality, full-view datasets and enhances the practicality and generalization ability of the method in real-world scenarios with missing data, clearing a key obstacle for the large-scale application of cow face recognition technology. Attached Figure Description
[0073] Figure 1 This is a flowchart of a fine-grained cow face recognition method based on multi-view triplets for cow faces. Detailed Implementation
[0074] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0075] This invention provides a technical solution: a fine-grained cow face recognition method based on multi-view cow face triples, comprising the following steps:
[0076] S1: Multi-view data acquisition of cow faces, acquiring three-view image data of the left, front and right sides of each cow's face through image acquisition equipment;
[0077] S2: Data preprocessing and triplet construction: Use the view prediction model to classify the view of cow face images and construct triplet samples from the left, front, and right view images of the same cow.
[0078] S3: Construct a cow face triplet recognition model based on hierarchical receptive field fine-grainedness. Input the images of each viewpoint in the triplet into the feature extraction network, obtain fine-grained features through the local receptive field fine-grained feature compression module, fuse multi-view features through the cross-attention mechanism, and finally output the recognition result through the classification module.
[0079] S4: Model training and optimization. The model is trained using the constructed triplet dataset, and the model parameters are optimized using the cross-entropy loss function.
[0080] S5: Model Inference and Application. Input the cow face image to be recognized into the trained model and obtain the recognition result.
[0081] Furthermore, step S1 specifically includes:
[0082] S11: Use a mobile app to capture three-view video of cow faces. The video size is 1920×1080, the frame rate is 60fps, and 30-60 seconds of 180° surround video of each cow, including the left side, right side and front face.
[0083] S12: Deduplication and frame extraction of video data. Merge the face data of the same cow based on the ear tag information, and use the frame extraction algorithm to extract static images from the video at a frequency of 2 frames per second.
[0084] Furthermore, step S2 specifically includes:
[0085] S21: Train a cow face view prediction model, perform three-view manual annotation on some cow face images, and train a CFVPM view prediction model based on a deep convolutional network.
[0086] S22: Use the trained CFVPM model to predict the viewpoint of the cow face image and output the prediction result v∈{0,1,2}, where 0 represents the left side of the face, 1 represents the right side of the face, and 2 represents the frontal face.
[0087] S23: Construct cow face triples. For multiple images of each cow, randomly organize the images from different viewpoints into multiple triple samples Trindex∈{i0,i1,i2} based on the viewpoint prediction results, where i0, i1, and i2 represent the left face, right face, and frontal face images, respectively.
[0088] Furthermore, the feature extraction network in step S3 specifically includes:
[0089] S31: Input the cow face image Trindexc from each viewpoint in the triplet into the SwinTransformer feature extractor to obtain 4 feature maps F in the 4 stages of the SwinTransformer backbone network. i Where i = 1, 2, 3, 4, and the feature map dimension of each Stage is F. i ∈{Hi,Wi,Ci};
[0090] S32: Transfer feature map F i Input the local receptive field fine-grained feature compression module to obtain the local sampled map PSi, calculated using the following formula:
[0091] PS i =Softmax(Conv 1×1 (F i ));
[0092] PS i ∈{Hi,Wi,Ci / 2},Conv 1×1 It is a convolutional layer with a kernel size of 1×1, an input dimension of Ci, and an output dimension of Ci / 2;
[0093] S33: Multiply the local sampled image PSi element-wise with the feature map Fi to obtain the fine-grained feature map PFi based on local sampling. The calculation formula is as follows:
[0094]
[0095] Where PF i ∈{Ci / 2,Ci},S i (a,b) is PS i The value of F at position (a, b) i (a,b) is F i The value at position (a, b);
[0096] S34: Input the local sampling fine-grained feature map PFi and the global receptive field feature map F4 into the cross-attention calculation module to obtain the cow face fine-grained pixel-level features F for each stage. i The calculation formula is:
[0097]
[0098] F i = Softmax(Attention) i Value i ;
[0099] in B is a learnable weight matrix. i For the bias term, Fi ′∈{H4,W4,C i};
[0100] S35: Perform steps S32-S34 on the four Stage feature maps of the SwinTransformer to obtain four fine-grained pixel-level features of the cow face F1', F2', F3', and F4'. Concatenate them according to the channel dimension to obtain the complete features of each viewpoint. The calculation formula is:
[0101]
[0102] in v∈{0,1,2} represents the left side of the face, the right side of the face, and the frontal view, respectively.
[0103] The multi-view feature fusion in step S3 specifically includes:
[0104] S36: Fine-grained features from different perspectives in the triplet Input feature space mapping subnetwork to obtain fine-grained corrected features of the same dimension. The calculation formula is:
[0105]
[0106] in Conv 1×1 A convolutional layer with a kernel size of 1×1;
[0107] S37: Fine-grained correction features from three perspectives The pairwise calculation of the three-view complementary features Fcomvi is as follows:
[0108]
[0109]
[0110] Matrix vi,vj ∈{H4×W4,H4×W4} is the similarity score matrix calculated after normalization of the fine-grained correction features from the two perspectives, where vi,vj∈{0,1,2} and vi≠vj. This is the sum of the residuals of the fine-grained correction features from one perspective and the supplementary features from another perspective;
[0111] S38: Combining three complementary features Concatenate the triplet along the channel dimension to obtain the final cow-face feature Ffinal, calculated using the following formula:
[0112]
[0113] Where F final ∈{H4,W4,3×C corr};
[0114] The classification module in step S3 specifically includes:
[0115] S39: Final cow-face feature F final Input the feature embedding extraction module to obtain the feature embedding vector Emb of the cow face. final The calculation formula is:
[0116] Emb final =GAP(Conv 3×3 (F final ))+GMP(Conv 3×3 (F final ));
[0117] Among them, Emb final ∈{1,1024}, GAP is a global average pooling layer, GMP is a global max pooling layer, Conv 3×3 It is a convolutional layer with a kernel size of 3×3;
[0118] S310: Embed the feature vector Emb final By inputting the multilayer perceptron (MLP) and the softmax function, the prediction results of the cow face category are obtained, and the cow face recognition is completed.
[0119] Furthermore, the model training in step S4 specifically includes:
[0120] S41: Divide the triplet dataset into a training set, a validation set, and a test set;
[0121] S42: Initialize model parameters. Use ImageNet pre-trained weights to initialize the SwinTransformer feature extractor, and use random initialization for the rest.
[0122] S43: Use the cross-entropy loss function to calculate the error between the predicted result and the true label. The calculation formula is as follows:
[0123]
[0124] Where N is the batch size, C is the total number of categories, and y i,c The true label of sample i in category c. This represents the model's predicted probability for sample i in category c.
[0125] S44: Calculate the gradient using the backpropagation algorithm, and update the model parameters using the stochastic gradient descent algorithm or the Adam optimizer;
[0126] S45: Evaluate the model performance on the validation set and save the best model based on the validation set accuracy;
[0127] The model training process also includes data augmentation operations, including:
[0128] The input image is randomly horizontally flipped with a flip probability of 0.5.
[0129] The input image is randomly rotated within the range of [-15°, 15°];
[0130] The input image is randomly cropped to 80%–100% of the original image size;
[0131] Color jitter is applied to the input image, including random adjustments to brightness, contrast, and saturation.
[0132] Furthermore, the model inference in step S5 specifically includes:
[0133] S51: Load the trained model weights and set the model to inference mode;
[0134] S52: Preprocess the cow face image to be identified, including resizing, normalization and viewpoint prediction;
[0135] S53: Input the preprocessed image into the model to obtain the feature extraction results;
[0136] S54: Calculate the similarity with registered cattle based on the feature extraction results. If the similarity exceeds the preset threshold, output the recognition result; otherwise, mark it as an unknown individual.
[0137] S55: Assess the confidence level of the identification results and recommend manual review for low-confidence results;
[0138] In step S54, the similarity calculation uses cosine similarity, and the calculation formula is as follows:
[0139]
[0140] Where f query Let f be the feature vector of the cow face to be identified. registered The feature vectors of the registered cattle.
[0141] Furthermore, it also includes the following steps:
[0142] S6 model deployment:
[0143] Convert the trained model to ONNX format to enable cross-platform deployment;
[0144] TensorRT is used for inference optimization, including layer fusion, precision calibration, and automatic kernel tuning.
[0145] Deploy the model inference service, supporting a RESTful API interface with JSON request format;
[0146] Implement request queue management and load balancing to support concurrent processing of multiple identification requests;
[0147] S7: System Monitoring and Maintenance Steps:
[0148] Collect system performance metrics in real time, including throughput, response time, and recognition accuracy;
[0149] Regularly evaluate model performance on independent test sets and monitor performance trends;
[0150] Implement an anomaly detection mechanism to trigger an alarm when performance indicators drop below a preset threshold.
[0151] Update the model regularly, and retrain or fine-tune it using new data.
[0152] Furthermore, it also includes data quality control steps:
[0153] The input image undergoes automatic quality assessment, including sharpness, brightness, contrast, and integrity checks; an object detection model is used to locate the cow face region, ensuring that the input image contains a complete cow face.
[0154] Images that do not meet quality requirements are automatically rejected or marked, and quality issues are reported.
[0155] For low-quality but critical images, try using image enhancement techniques to improve them before further processing;
[0156] User interface:
[0157] Provides a data acquisition interface to guide users in completing multi-view video shooting;
[0158] Provides a display interface for recognition results, showing the recognition results and confidence levels in a visual format;
[0159] Provides a model management interface that supports model version switching and parameter adjustment;
[0160] Provides a system monitoring interface to display the system's operating status and performance indicators in real time;
[0161] Data security and privacy protection measures:
[0162] The collected images of cow faces were anonymized to remove any personal information that might be included.
[0163] Encrypt the data in transit and use the SSL / TLS protocol to ensure data transmission security;
[0164] Encrypt the data in storage to prevent unauthorized access;
[0165] Establish a data access control mechanism and assign different access permissions based on user roles;
[0166] System integration capabilities:
[0167] It supports integration with existing aquaculture management systems to achieve data sharing and business collaboration;
[0168] Supports integration with IoT devices to automatically acquire environmental and physiological data related to cattle;
[0169] Supports integration with blockchain technology to achieve tamper-proof cattle identity records;
[0170] It supports multilingual interfaces to meet the needs of users in different regions.
[0171] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0172] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A fine-grained cow face recognition method based on multi-view cow face triples, characterized in that, Includes the following steps: S1: Multi-view data acquisition of cow faces, acquiring three-view image data of the left, front and right sides of each cow's face through image acquisition equipment; S2: Data preprocessing and triplet construction: Use the view prediction model to classify the view of cow face images and construct triplet samples from the left, front, and right view images of the same cow. S3: Construct a cow face triplet recognition model based on hierarchical receptive field fine-grainedness. Input the images of each viewpoint in the triplet into the feature extraction network, obtain fine-grained features through the local receptive field fine-grained feature compression module, fuse multi-view features through the cross-attention mechanism, and finally output the recognition result through the classification module. S4: Model training and optimization. The model is trained using the constructed triplet dataset, and the model parameters are optimized using the cross-entropy loss function. S5: Model Inference and Application. Input the cow face image to be recognized into the trained model and obtain the recognition result.
2. The fine-grained cow face recognition method based on multi-view triplets of cow faces according to claim 1, characterized in that: The specific steps of step S1 include: S11: Use a mobile app to capture three-view video of cow faces. The video size is 1920×1080, the frame rate is 60fps, and 30-60 seconds of 180° surround video of each cow, including the left side, right side and front face. S12: Deduplication and frame extraction of video data. Merge the face data of the same cow based on the ear tag information, and use the frame extraction algorithm to extract static images from the video at a frequency of 2 frames per second.
3. The fine-grained cow face recognition method based on multi-view triplets of cow faces according to claim 1, characterized in that: The specific steps of step S2 include: S21: Train a cow face view prediction model, perform three-view manual annotation on some cow face images, and train a CFVPM view prediction model based on a deep convolutional network. S22: Use the trained CFVPM model to predict the viewpoint of the cow face image and output the prediction result v∈{0,1,2}, where 0 represents the left side of the face, 1 represents the right side of the face, and 2 represents the frontal face. S23: Construct cow face triples. For multiple images of each cow, randomly organize the images from different viewpoints into multiple triple samples Trindex∈{i0,i1,i2} based on the viewpoint prediction results, where i0, i1, and i2 represent the left face, right face, and frontal face images, respectively.
4. The fine-grained cow face recognition method based on multi-view triplets of cow faces according to claim 1, characterized in that: The feature extraction network in step S3 specifically includes: S31: Input the cow face image Trindexc from each viewpoint in the triplet into the SwinTransformer feature extractor to obtain 4 feature maps F in the 4 stages of the SwinTransformer backbone network. i Where i = 1, 2, 3, 4, and the feature map dimension of each Stage is F. i ∈{Hi,Wi,Ci}; S32: Transfer feature map F i Input the local receptive field fine-grained feature compression module to obtain the local sampled map PSi, calculated using the following formula: PS i =Softmax(Conv 1×1 (F i )); PS i ∈{Hi,Wi,Ci / 2},Conv 1×1 It is a convolutional layer with a kernel size of 1×1, an input dimension of Ci, and an output dimension of Ci / 2; S33: Multiply the local sampled image PSi element-wise with the feature map Fi to obtain the fine-grained feature map PFi based on local sampling. The calculation formula is as follows: Where PF i ∈{Ci / 2,Ci},S i (a,b) is PS i The value of F at position (a, b) i (a,b) is F i The value at position (a, b); S34: Input the local sampling fine-grained feature map PFi and the global receptive field feature map F4 into the cross-attention calculation module to obtain the cow face fine-grained pixel-level features F for each stage. i The calculation formula is: F i ′=Softmax(Attention i )Value i ; in B is a learnable weight matrix. i For the bias term, F i ′∈{H4,W4,C i } 5. The fine-grained cow face recognition method based on multi-view triplets of cow faces according to claim 1, characterized in that: The specific steps of model training in step S4 include: S41: Divide the triplet dataset into a training set, a validation set, and a test set; S42: Initialize model parameters. Use ImageNet pre-trained weights to initialize the SwinTransformer feature extractor, and use random initialization for the rest. S43: Use the cross-entropy loss function to calculate the error between the predicted result and the true label. The calculation formula is as follows: Where N is the batch size, C is the total number of categories, and y i,c The true label of sample i in category c. This represents the model's predicted probability for sample i in category c. S44: Calculate the gradient using the backpropagation algorithm, and update the model parameters using the stochastic gradient descent algorithm or the Adam optimizer; S45: Evaluate the model performance on the validation set and save the best model based on the validation set accuracy; The model training process also includes data augmentation operations, including: The input image is randomly horizontally flipped with a flip probability of 0.
5. The input image is randomly rotated within the range of [-15°, 15°]; The input image is randomly cropped to 80%–100% of the original image size; Color jitter is applied to the input image, including random adjustments to brightness, contrast, and saturation.
6. The fine-grained cow face recognition method based on multi-view triplets of cow faces according to claim 1, characterized in that: The specific steps of model inference in step S5 include: S51: Load the trained model weights and set the model to inference mode; S52: Preprocess the cow face image to be identified, including resizing, normalization and viewpoint prediction; S53: Input the preprocessed image into the model to obtain the feature extraction results; S54: Calculate the similarity with registered cattle based on the feature extraction results. If the similarity exceeds the preset threshold, output the recognition result; otherwise, mark it as an unknown individual. S55: Assess the confidence level of the identification results and recommend manual review for low-confidence results; In step S54, the similarity calculation uses cosine similarity, and the calculation formula is as follows: Where f query Let f be the feature vector of the cow face to be identified. registered The feature vectors of the registered cattle.
7. The fine-grained cow face recognition method based on multi-view cow face triples according to claim 1, characterized in that: It also includes the following steps: S6 model deployment: Convert the trained model to ONNX format to enable cross-platform deployment; TensorRT is used for inference optimization, including layer fusion, precision calibration, and automatic kernel tuning. Deploy the model inference service, supporting a RESTful API interface with JSON request format; Implement request queue management and load balancing to support concurrent processing of multiple identification requests; S7: System Monitoring and Maintenance Steps: Collect system performance metrics in real time, including throughput, response time, and recognition accuracy; Regularly evaluate model performance on independent test sets and monitor performance trends; Implement an anomaly detection mechanism to trigger an alarm when performance indicators drop below a preset threshold. Update the model regularly, and retrain or fine-tune it using new data.
8. The fine-grained cow face recognition method based on multi-view triplets of cow faces according to claim 1, characterized in that: It also includes data quality control steps: Automatic quality assessment of input images, including sharpness, brightness, contrast, and integrity checks; Use an object detection model to locate the cow face region to ensure that the input image contains a complete cow face; Images that do not meet quality requirements are automatically rejected or marked, and quality issues are reported. For low-quality but critical images, try using image enhancement techniques to improve them before further processing; User interface.