Method and system for facial recognition of cattle
By improving the ResNet backbone network and FaceNet model, and combining a specific loss function, the problems of high false recognition risk and low efficiency in cattle identification are solved, achieving efficient and accurate cattle facial recognition, which is suitable for the refined management of modern large-scale farms and the insurance industry.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JILIN UNIVERSITY
- Filing Date
- 2024-10-25
- Publication Date
- 2026-07-03
AI Technical Summary
Existing cattle identification methods have a high risk of false identification, low identification efficiency, high cost, and specific requirements for identification equipment and environment, making them unsuitable for modern large-scale farms.
We employ an improved ResNet backbone network based on residual modules and a FaceNet model, combined with Triplet loss and Arc face loss functions. Through multiple convolutional layers, batch normalization layers, and residual connections, we extract complex features from cattle facial images, enhancing model performance and generalization ability. We then use the YOLOv7 model for target detection, achieving efficient and accurate cattle face recognition.
It improves the accuracy and efficiency of cattle identification, reduces identification costs, is suitable for modern large-scale farms, can quickly identify the identity information of insured cattle, supports refined management, and reduces human resources and operating costs.
Smart Images

Figure CN119380376B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of biometrics, specifically to a method and system for facial recognition of cattle. Background Technology
[0002] In recent years, with the development of grassland animal husbandry towards large-scale, information-based, and refined operations, my country's animal husbandry industry has gradually strengthened, but the support and guarantee system remains incomplete. Therefore, the state is vigorously promoting livestock breeding insurance, encouraging the establishment of electronic livestock and poultry records, achieving refined management, strengthening technology application, and improving safety control capabilities.
[0003] Cattle, as important livestock, occupy a vital position in agricultural production and economic development. In the field of livestock insurance, accurate identification of cattle is crucial. On the one hand, cattle have high value, and insurance payouts can be substantial in the event of an accident. Regular identification of insured cattle aims to prevent cattle from being switched, avoiding risks such as duplicate claims and uninsured claims. On the other hand, in the event of natural disasters, disease, or other unforeseen circumstances, quickly determining the identity of damaged cattle and the actual extent of loss helps insurance companies make timely and reasonable compensation payments, protecting the legitimate rights and interests of farmers and promoting the healthy development of the livestock insurance industry.
[0004] However, in practical insurance applications, cattle facial recognition has become a critical challenge that the industry urgently needs to address. Compared to traditional facial recognition, cattle facial recognition faces numerous difficulties. First, cattle facial features are relatively indistinct. Human faces possess rich facial features and high recognizability, while cattle faces lack distinct human-like features, making it difficult to accurately extract and distinguish feature points. Second, cattle's living environment is more complex, and they may be obscured by food scraps, mud, and feces, affecting the overall image quality and recognition accuracy.
[0005] Currently, methods for unique identification of cattle mainly fall into two categories: traditional contact identification and non-contact identification based on deep learning algorithms. Traditional identification methods, such as ear incision, hot iron branding, and ear tagging, are not only inefficient but also harmful to the animals and affect animal welfare. While radio frequency identification (RFID)-based electronic ear tagging is convenient and fast, it is still limited by distance and the number of animals, and the worn devices are also at risk of being lost or damaged.
[0006] The methods mentioned above are all inadequate when dealing with large herds of cattle in insurance work. In contrast, non-contact identification relies on computer vision technology, deep learning algorithms, and non-contact acquisition equipment, and has the advantages of real-time performance and high efficiency, providing strong technical support for animal management and research.
[0007] Non-contact bovine identification technology has made significant progress in recent years as an important research direction in the field of biometrics. The bovine face, as the most intuitive external feature, is a unique identifier for bovines.
[0008] In 2005, Kim used associative memory neural networks for cow facial recognition. However, this method suffered from overfitting with large datasets and its accuracy was unstable in complex environments. Subsequently, Cai used face recognition methods, calibrating test images through sparse and low-rank decomposition. However, this method was not specific to cow facial features and was easily affected by external factors. Gebar et al. used classifiers to identify cow heads from WLD features, proposing k-NN and Fk-NN classifiers. However, these methods were computationally inefficient when dealing with large-scale cow herds and were not well-suited for dense herd scenarios, making them unsuitable for the insurance industry.
[0009] In recent years, domestic scholars have also begun to focus on research into cattle body recognition technology. Lü Changwei proposed an incremental recognition algorithm framework, using convolutional neural networks to achieve real-time cattle body recognition in complex environments. However, this algorithm may not be precise enough in extracting individual cattle features, and misidentification may occur in some special cases. Weng Zhi et al. combined a dual-branch structure with CNN, effectively reducing the impact of cattle posture changes on recognition accuracy; however, the recognition effect is somewhat affected when facing scenes with large changes in lighting. Zheng Peng introduced a learnable mask matrix and added a patch-shift network layer based on the visual converter model, effectively reducing the impact of image dirt on recognition performance. However, this method has high model complexity and high training and deployment costs. Wang Feng et al. extracted facial feature images using machine vision, achieving a recognition accuracy of up to 98.06% with the SIFT algorithm. However, SIFT feature calculation and matching require a large amount of computation, taking a long time and demanding high-performance equipment, making it unsuitable for use on platforms with limited computing power.
[0010] In conclusion, future insurance implementation relies on contactless, high-precision, and highly automated identification methods. However, existing identification methods have a high risk of false identification, low efficiency, high cost, and specific requirements for identification equipment and environment, making them unsuitable for modern large-scale farms. Summary of the Invention
[0011] This invention solves the problems of existing cattle identification methods, such as high risk of false identification, low identification efficiency, high cost, and specific requirements for identification equipment and environment, which make them unsuitable for modern large-scale farms.
[0012] The image target recognition method based on the improved ResNet backbone network using residual modules described in this invention is as follows:
[0013] The original image is processed sequentially through the first convolutional layer, normalization, the second convolutional layer, normalization, and the third convolutional layer.
[0014] The first convolutional layer, the second convolutional layer, and the third convolutional layer are residually connected;
[0015] After changing the number of the first, second, and third convolutional layers, the process is repeated through the first, second, and third convolutional layers with the changed numbers, and the original image after multiple iterations is output.
[0016] The original image is added to the original image after multiple iterations to identify the target in the original image.
[0017] Furthermore, in one embodiment of the present invention, the first convolutional layer is a 7×7 convolutional layer, and the second and third convolutional layers are both 3×3 convolutional layers.
[0018] The image target recognition method based on convolutional neural networks described in this invention is implemented based on the image target recognition method based on the ResNet backbone network improved by residual modules described above, specifically as follows:
[0019] The image is sequentially input into a convolutional layer, a pooling layer, a ResNet backbone network improved based on residual modules, global pooling, flattening, and normalization for target recognition;
[0020] The vector is transformed into a fixed feature vector of dimension 32 through normalization.
[0021] The face recognition method for images based on FaceNet described in this invention is implemented based on the image target recognition method based on convolutional neural networks described above, specifically as follows:
[0022] The image is processed by normalization and regularization. The processed image is then processed by a residual module, a global average pooling layer, a fully connected layer, and a convolutional neural network to identify features. After feature recognition, the loss values of the Triplet loss function and the Arc face loss function are calculated. Based on the weights of the Triplet loss function and the Arc face loss function, the two loss values are added together to obtain the total loss value. Face recognition of the image is completed based on the total loss value.
[0023] The fully connected layer keeps the embedded vector dimension to 32.
[0024] Furthermore, in one embodiment of the present invention, the weight of the Triplet loss function is 0.6, and the weight of the Arc face loss function is 0.4.
[0025] The image face recognition method of the present invention is based on the FaceNet-based image face recognition method described above, and includes the following steps:
[0026] Step S1: Acquire images and preprocess them to create an image dataset, which includes a facial feature dataset and its corresponding identity information dataset.
[0027] Step S2: Perform object detection on the facial feature dataset based on the YOLOv7 model;
[0028] Step S3: Based on the FaceNet facial recognition method for images, the facial feature dataset after target detection is identified. This completes the identification of the facial feature dataset and displays the identity information dataset corresponding to the facial feature dataset.
[0029] The image facial recognition system of the present invention, which is based on the image facial recognition method described above, includes the following modules:
[0030] Module S1 acquires images and preprocesses them to create an image dataset, which includes a facial feature dataset and its corresponding identity information dataset.
[0031] Module S2 performs object detection on a facial feature dataset based on the YOLOv7 model;
[0032] Module S3, based on the FaceNet facial recognition method for images, identifies the facial feature dataset after target detection. It then completes the identification of the facial feature dataset and displays the identity information dataset corresponding to the facial feature dataset.
[0033] The cattle facial recognition method of the present invention is based on the image facial recognition method described above to recognize the face of cattle.
[0034] The cattle facial recognition system of the present invention is a facial recognition system based on the image described in the above method to recognize the face of cattle.
[0035] This invention solves the problems of existing cattle identification methods, such as high risk of false identification, low identification efficiency, high cost, and specific requirements for identification equipment and environment, making them unsuitable for modern large-scale farms. Specific beneficial effects include:
[0036] 1. The cattle facial recognition method described in this invention suffers from several drawbacks. Existing cattle recognition methods have a high risk of false recognition, low efficiency, high cost, and specific requirements for recognition equipment and environment, making them unsuitable for modern large-scale farms. To address these issues, the improved FaceNet model proposed in this invention can better extract features and is more suitable for recognizing the facial structure of cattle. Through a combination of multiple convolutional layers, batch normalization layers, and residual connections, it can effectively extract complex features from cattle facial images, from low-level texture and color features to high-level semantic features, improving recognition accuracy, enhancing model performance and generalization ability. It can accurately identify the identity information of insured cattle, distinguish the individual identities of cattle, and be used for livestock breeding insurance, helping to achieve refined management of farms.
[0037] 2. The image target recognition method based on the improved Res Net backbone network with residual modules described in this invention integrates the original Res Net backbone network with residual modules, which effectively alleviates the gradient vanishing problem, enables gradients to propagate forward better, enhances model training effect, and improves model training efficiency.
[0038] 3. The face recognition method based on FaceNet described in this invention divides the Arc face loss function and the Triplet loss function into two parts with a weight ratio of 4:6, which can retain the advantages of both loss functions at the same time and improve the transferability and generalization ability of the model.
[0039] 4. The FaceNet-based face recognition method for images described in this invention modifies the dimension of the embedding vector from 128 in the previous model to 32. Considering that lower-dimensional embedding vectors are easier to visualize and interpret, 32-dimensional embedding vectors are more suitable for cattle face recognition, providing strong technical support for cattle management and recognition.
[0040] Meanwhile, the facial recognition system for cattle described in this invention can display relevant electronic file information based on the identity information dataset after identifying the individual cattle. By mounting the entire system on a JETSON NANO development board and connecting the board to a camera for data acquisition, leveraging its high-speed operation, it can quickly complete target detection and identity recognition comparison, record and save large amounts of data, significantly improving the work efficiency of the insurance industry and reducing human resources and operating costs. Attached Figure Description
[0041] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:
[0042] Figure 1 This is a diagram of the facial recognition system for cattle described in Embodiment Seven;
[0043] Figure 2 This is the YOLOv7 model network structure diagram described in Implementation Method 4;
[0044] Figure 3 This is a flowchart of the Face Net algorithm described in Implementation Method 2;
[0045] Figure 4 This is the original ResNet backbone network structure diagram described in Implementation Method 1;
[0046] Figure 5 This is a structural diagram of the residual module as described in Implementation Method 1. Detailed Implementation
[0047] Various embodiments of the present invention will now be clearly and completely described with reference to the accompanying drawings. The embodiments described with reference to the drawings are exemplary and intended to explain the present invention, and should not be construed as limiting the present invention.
[0048] Implementation Method 1: The image target recognition method based on the ResNet backbone network improved by residual modules described in this implementation method is as follows:
[0049] The original image is processed sequentially through the first convolutional layer, normalization, the second convolutional layer, normalization, and the third convolutional layer.
[0050] The first convolutional layer, the second convolutional layer, and the third convolutional layer are residually connected;
[0051] After changing the number of the first, second, and third convolutional layers, the process is repeated through the first, second, and third convolutional layers with the changed numbers, and the original image after multiple iterations is output.
[0052] The original image is added to the original image after multiple iterations to identify the target in the original image.
[0053] In this embodiment, the first convolutional layer is a 7×7 convolutional layer, and the second and third convolutional layers are both 3×3 convolutional layers.
[0054] In this embodiment, the image input is used to identify the target based on a ResNet backbone network improved by residual modules. The basic structure of the ResNet backbone network improved by residual modules is as follows:
[0055] y = F(x) + x;
[0056] Here, x is the input, F(x) is the residual mapping obtained through a series of convolutional operations, and y is the output. Features are extracted from the input x through convolutional operations to obtain an intermediate result r. Then, a series of convolutional and batch normalization operations are performed on r to obtain the residual mapping F(x) of x. Finally, the original input x and the residual mapping F(x) are added to obtain the output. This structure allows the network to directly learn the residual between the input and output, rather than directly learning the target output. In this way, even as the number of network layers increases, the residual module ensures effective information flow and stable backpropagation of gradients. The residual module also makes it easier for the network to learn simple mapping relationships such as identity mappings, improving the network's performance and generalization ability.
[0057] like Figure 5 As shown, the original ResNet backbone network structure is as follows: Figure 4 As shown, the ResNet backbone network improved based on residual modules is specifically as follows:
[0058] Based on the principle of residual learning, this implementation performs a cyclic operation on different numbers of convolutional layers in the ResNet backbone network [16, 32, 64, 128, 512]. When the number of the first, second, and third convolutional layers is 16, the original image is first passed through a first convolutional layer with a stride of 7x7, then batch normalization is performed, then a 3x3 convolutional layer with a stride of 3 is connected, then batch normalization is performed again, and finally a 3x3 convolutional layer with a stride of 3 is connected. The first convolutional layer with a stride of 7x7, the second convolutional layer with a stride of 3x3, and the third convolutional layer with a stride of 3x3 are connected using the Add() function to achieve residual connections. When the number of the first, second, and third convolutional layers is changed to 32, the above operation is repeated until the number of the first, second, and third convolutional layers is changed to 512. Then the above operation ends, and the original image is added to the original image after multiple convolutional processing to form the residual module.
[0059] The improved ResNet backbone network based on residual modules in this implementation helps alleviate the vanishing gradient problem, allowing gradients to propagate more directly to earlier layers and improving network training performance. Simultaneously, it allows the network to learn the residual mapping between input and output, enhancing feature learning capabilities, better capturing details and patterns in facial images, improving recognition accuracy, strengthening the model's non-linear expressive power, and avoiding the vanishing gradient and performance degradation problems that occur with increasing network depth.
[0060] Implementation Method Two: The image target recognition method based on convolutional neural networks described in this implementation method is based on the image target recognition method based on the ResNet backbone network improved by residual modules described in Implementation Method One. Specifically:
[0061] The image is sequentially input into a convolutional layer, a pooling layer, a ResNet backbone network improved based on residual modules, global pooling, flattening, and normalization for target recognition;
[0062] The vector is transformed into a fixed feature vector of dimension 32 through normalization.
[0063] In this embodiment, the input to the convolutional neural network is image data x of type (224, 224, 3). input The initial convolutional and pooling layers are Conv & Pool, the deep convolutional and residual connections described in Implementation 1 are Deep Conv & Res, and the global pooling and flattening are Global Pool & Flat. The output is a normalized feature vector x with a dimension of 32. output .
[0064] First, through Conv&Pool, x input =BatchNormalization()(x input );
[0065] x input =MaxPooling2D((3,3))(x input );
[0066] Deep Conv&Res is used to repeatedly perform convolution and normalization operations on the feature map, repeating the process three times to alleviate the gradient vanishing problem.
[0067] Next, through Global Pool & Flat, x = GlobalAveragePooling2D()(x);
[0068] x = Flatten()(x);
[0069] The final output is a normalized feature vector with an embedding dimension of 32:
[0070] x output =Dense(32)(x output );
[0071] outputs = Lambda(lambda x output : tf.nn.12-normalize(x output ,axis=-1))(x output ).
[0072] Therefore, the image is sequentially passed through initial convolutional and pooling layers. Sixteen 7x7 filters are used to convolve the input image with a stride of 2x2, employing the ReLU activation function to extract preliminary feature vector information. Batch normalization of the convolutional layer outputs accelerates model training and improves stability and generalization ability. The initial pooling layer further performs max pooling with a 3x3 window, selecting the maximum value within each pooling window as the output. This reduces the spatial size of the feature map and the number of parameters, improving computational efficiency and translation invariance while preserving key feature information. This provides a more abstract and representative feature vector representation for subsequent network layers, laying the foundation for accurate image classification and other tasks.
[0073] Implementation Method 3: The face recognition method for images based on FaceNet described in this implementation method is based on the image target recognition method based on convolutional neural networks described in Implementation Method 2, specifically as follows:
[0074] The image is processed by normalization and regularization. The processed image is then processed by a residual module, a global average pooling layer, a fully connected layer, and a convolutional neural network to identify features. After feature recognition, the loss values of the Triplet loss function and the Arc face loss function are calculated. Based on the weights of the Triplet loss function and the Arc face loss function, the two loss values are added together to obtain the total loss value. Face recognition of the image is completed based on the total loss value.
[0075] The fully connected layer keeps the embedded vector dimension to 32.
[0076] In this embodiment, the weight of the Triplet loss function is 0.6, and the weight of the Arc face loss function is 0.4.
[0077] In this embodiment, such as Figure 3 As shown, the face recognition method for images based on FaceNet is specifically as follows:
[0078] First, the input layer cropped the object detection dataset to (224, 224, 3), representing that the input image size is 224x224 pixels and has three color channels.
[0079] Then, the input of each layer is normalized and regularized. The Dropout layer randomly sets the output of some neurons to 0 during training, reducing co-adaptation between neurons, making the model more stable during training, accelerating convergence, and reducing the risk of overfitting. L2 normalization normalizes the length of the vector to 1, making the features of different samples comparable, improving the model's stability and convergence speed. Its calculation formula is:
[0080]
[0081] in, It is an n-dimensional vector, (v1, v2, ..., v n These are the component values of the vector in each dimension. The length of a vector, also known as the L2 norm, is represented by v. i It is the original vector The component value in the i-th dimension, u i It is the component value of the new vector in the i-th dimension after L2 normalization.
[0082] Subsequently, the image passes through the feature embedding module and the convolutional neural network described in Implementation Method 2 to identify features. The feature embedding module includes a residual module, a global average pooling layer, and a fully connected layer. The fully connected layer adjusts the weights and biases, combines and abstracts the extracted feature vectors, and learns the complex relationship between input features and output categories or embeddings to adapt to specific task requirements.
[0083] The formula for a fully connected layer is:
[0084] y = Wx + b;
[0085] Where x is the input of the fully connected layer, W is the weight matrix, and b is the bias vector.
[0086] This implementation uses a fully connected layer to control the embedding vector dimension to 32. Compared to the previous 128-dimensional embedding vectors, 32-dimensional vectors require less computational resources and time during training and inference. Regarding model performance, while the reduced dimensionality may lead to some information loss, it also reduces the risk of overfitting and improves the model's generalization ability. In terms of visualization and interpretability, 32-dimensional vectors are easier to visualize and analyze, allowing for a better understanding of the relationships and feature changes between different categories, making them more suitable for facial feature recognition. The output of the fully connected layer passes through a lambda layer, ensuring the normalization of the output vector in spatial orientation, making the model's output more stable and comparable.
[0087] The global average pooling layer compresses the feature maps, which have been processed by the complex convolution and residual modules, in terms of spatial dimension. It calculates the element-wise average of each feature map, transforming each feature map into a single value. This effectively reduces the number of parameters, avoids overfitting, and makes the model more robust to spatial variations of the input image. The collaborative work of the feature embedding modules gradually transforms the features of the input image into the final classification result and the output for the specific task.
[0088] Finally, after obtaining the feature vector through the convolutional neural network, since each feature block contains information about itself and other feature blocks, in order to improve the discriminative power, this implementation combines the Arcface loss function and the Tripletloss loss function to form a new loss function to guide network training.
[0089] The Arc Face loss function is primarily used for face recognition. It focuses on learning discriminative angular margins and highly discriminative feature embeddings, effectively distinguishing features and making samples of the same class more compact in the feature space, while further separating samples of different classes. The Arc Face loss function adds angular margins to the traditional loss function, and its calculation formula is as follows:
[0090] Assume the input feature vector is x, the weight vector is W, and the class label is y;
[0091]
[0092] Where, θ yj It is the eigenvector x j With weight vector W y The angle between the two sides, s is the scaling factor, and m is the angle interval penalty term. By introducing the angle interval m, the features that the model can learn are more discriminative in the angle space.
[0093] The triplet loss function is primarily used to learn the relative relationships between samples. It constrains the similarity and dissimilarity between sample triples, minimizing the distance between the anchor sample and positive samples and maximizing the distance between the anchor sample and negative samples. This ensures effective model training even with a limited number of samples and provides robustness to noise and variations, improving the accuracy and stability of the model in recognition and classification tasks.
[0094] The calculation formula is as follows:
[0095]
[0096] Where N is the number of training samples, a i It is an anchor point sample, p i It is a positive sample, n iThe positive and negative samples are denoted by d, which represents the Euclidean distance between the samples. α is a boundary value used to control the distance interval between the positive and negative samples.
[0097] This implementation calculates the losses of the Triplet loss function and the Arc Face loss function separately, and then sums them with a weighted average of 6:4. The new loss function fully leverages the advantages of both functions: the former focuses on the relative relationships between samples, enabling the learning of more discriminative feature representations, while the latter enhances the discriminative power of features through angular spacing, making samples of the same class more compact. Using them in combination enhances the model's ability to learn highly discriminative features, improves recognition performance, increases the model's adaptability to various situations, and improves the model's robustness.
[0098] Implementation Method 4: The image face recognition method described in this implementation method is based on the FaceNet-based image face recognition method described in Implementation Method 3, and includes the following steps:
[0099] Step S1: Acquire images and preprocess them to create an image dataset, which includes a facial feature dataset and its corresponding identity information dataset.
[0100] Step S2: Perform object detection on the facial feature dataset based on the YOLOv7 model;
[0101] Step S3: Based on the FaceNet facial recognition method for images, the facial feature dataset after target detection is identified. This completes the identification of the facial feature dataset and displays the identity information dataset corresponding to the facial feature dataset.
[0102] Based on facial recognition of images, this embodiment designs a facial recognition method for images, including the following steps:
[0103] Step S1, Data Acquisition:
[0104] 1. To improve the robustness of the training model, multiple angle transformations should be performed during video shooting to ensure the diversity of background and angle differences between faces in the image data. At the same time, two time periods with significant differences in lighting should be selected for shooting to ensure the lighting changes in the captured video.
[0105] 2. Shoot two videos, one from a frontal angle and the other from a low angle, to ensure that facial feature data is obtained from different angles.
[0106] Step S2, Data Preprocessing:
[0107] 1. Extract one frame from every 20 frames of the captured video to obtain the initial feature information image;
[0108] 2. To obtain a dataset rich in facial features, it is necessary to ensure significant differences between keyframe images. This implementation uses SSIM to clean the images and provides similarity metrics by comparing brightness, contrast, and structure between images, thus measuring the degree of image similarity. Excluding similar images can improve the model's generalization ability and transferability, making the model more suitable for application on this dataset.
[0109] Assuming the two images being compared are x and y, the formula for calculating their SSIM value is:
[0110] SSIM(x,y)=[l(x,y)] α [c(x, y)] β [s(x,y)] γ α>0, β>0, γ>0;
[0111] The above equation is the definition of SSIM, where the expressions for the functions l, c, and y are as follows:
[0112]
[0113] Where l(x,y) is the brightness comparison, c(x,y) is the contrast comparison, s(x,y) is the structure comparison, and μ x and μ y These represent the average values of x and y, respectively, and σ x and σ y σ represents the standard deviation of x and y, respectively. xy Let α represent the covariance of x and y, and let c1, c2, and c3 be constants to avoid calculation errors caused by denominators of 0. In practical engineering calculations, α = β = γ = 1, and c3 = c2 / 2 are generally taken. To simplify the calculation steps, SSIM can be simplified to:
[0114]
[0115] Step S3, Dataset Creation:
[0116] 1. Use the labellmg annotation tool to annotate the images after removing duplicate features. Select PASCAL VOC as the annotation format and generate an XML annotation file. The file contains information such as image name, size, coordinates of the annotation rectangle, target category, degree of occlusion, and recognition difficulty.
[0117] 2. Divide the preprocessed images into a dataset in an 8:1:1 ratio, with 80% used as the training set, 10% as the test set, and 10% as the validation set.
[0118] 3. To enhance the model's generalization ability for individual recognition, five image enhancement techniques were used to expand the dataset: image flipping, color contrast adjustment, color intensity adjustment, and brightness adjustment.
[0119] 4. The facial feature data is now complete;
[0120] 5. In order to display the electronic information archive of the images, this implementation method also needs to establish an identity information dataset. It is necessary to collect information for each image, such as age, weight, gender, etc., place the image data and the corresponding tag data in different folders, and then place the two folders in the same path.
[0121] Step S4, Target Detection:
[0122] This implementation uses the YOLOv7 model to perform the face detection task. This model consists of three core modules: a backbone network, a neck network, and a head network. Its network structure is as follows: Figure 2 As shown.
[0123] 1. Target detection is performed using the powerful feature extraction network, multi-scale detection, and anchor box clustering techniques of the YOLOv7 model, facilitating better subsequent feature extraction. The backbone integrates CBS, MP-1, and ELAN modules, and with the help of auxiliary head training and corresponding positive and negative sample matching strategies, it achieves accurate capture of image features, precise classification of target categories, and reliable evaluation of confidence levels.
[0124] CBS module: This module typically includes convolution, batch normalization, and activation function operations. The convolution operation is as follows:
[0125] Y = W*X + b;
[0126] Where Y is the output feature map, W is the convolution kernel, X is the input feature map, and b is the bias term.
[0127] Batch normalization helps stabilize the training process and improve the model's generalization ability. Its formula is:
[0128]
[0129] Where x is the input data, μ is the mean, σ is the standard deviation, and ∈ is a small constant.
[0130] MP-1 Module: This module represents max pooling, which reduces the spatial resolution of the feature map by selecting the maximum value in a local region, thereby reducing computation and extracting the main features. Its formula is:
[0131]
[0132] Among them, Y i,jIt is the value of the output feature map at position (i,j), R i,j It corresponds to a local region of the input feature map.
[0133] ELAN module: This module effectively improves the accuracy and speed of target detection by extending and connecting features at different levels, thereby fusing multi-scale information.
[0134] 2. By utilizing FPN and PAN structures, effective combination of semantic and spatial information at different levels can be achieved. FPN transmits semantic information from higher levels to lower levels, enhancing the semantic expression of lower-level features, while PAN transmits spatial information from lower levels to higher levels, improving the localization accuracy of higher-level features.
[0135] 3. Anchor frame clustering technology is employed to adaptively adjust the size and proportion of anchor frames to accommodate the diversity of different facial features. The size and proportion of the anchor frames are optimized by calculating the Euclidean distance from the samples to the cluster centers. The calculation formula is as follows:
[0136]
[0137] Where x and y are sample points, and n is the feature dimension.
[0138] 4. Utilize a feature extraction network incorporating the SPPCS module to enhance the convolutional neural network's ability to express detailed features. Through a series of convolution, pooling, and concatenation operations, richer feature information is extracted.
[0139] 5. Finally, the robustness of the model to facial features under different lighting, angles, and occlusion conditions is enhanced through the CAT and RAP modules. The CAT module stitches together different feature maps, while the RAP module highlights important regions by calculating attention weights.
[0140] The formula for calculating attention weights is:
[0141] ω=σ(f(X));
[0142] Where X is the input feature, f is a function, σ is the activation function, and ω is the attention weight.
[0143] 6. Use the images after object detection as a new facial feature dataset for subsequent recognition models.
[0144] Step S5, design an improved face recognition model based on FaceNet:
[0145] The improved FaceNet facial recognition model described in Implementation Method 3 used in this embodiment can leverage the powerful feature extraction capabilities of deep learning to maintain a high recognition accuracy even in complex aquaculture environments.
[0146] Implementation Method 5: An image-based facial recognition system, which is based on the image-based facial recognition method described in Implementation Method 4, and includes the following modules:
[0147] Module S1 acquires images and preprocesses them to create an image dataset, which includes a facial feature dataset and its corresponding identity information dataset.
[0148] Module S2 performs object detection on a facial feature dataset based on the YOLOv7 model;
[0149] Module S3, based on the FaceNet facial recognition method for images, identifies the facial feature dataset after target detection. It then completes the identification of the facial feature dataset and displays the identity information dataset corresponding to the facial feature dataset.
[0150] In this embodiment, the overall system assembly is as follows:
[0151] The trained model is deployed on the edge device JETSON NANO.
[0152] Facial recognition systems can create a unique identity information file for each image, enabling precise management of individuals. In livestock insurance, this implementation method can ensure the accuracy and fairness of insurance claims, prevent insurance fraud, improve management efficiency, reduce labor costs, and promote the modernization and intelligentization of the livestock breeding industry.
[0153] Implementation Method Six: The cattle face recognition method described in this implementation method is based on the image face recognition method described in Implementation Method Five to achieve the recognition of cattle faces.
[0154] Existing identification methods have a high risk of false identification, low identification efficiency, high cost, and specific requirements for identification equipment and environment, making them unsuitable for modern large-scale farms.
[0155] To address the aforementioned technical problems, this embodiment designs a facial recognition method for cattle, providing strong technical support for fields such as livestock breeding insurance, including the following steps:
[0156] Step S1, Data Acquisition:
[0157] Videos of the facial features of cattle in a livestock farm were recorded using data acquisition equipment;
[0158] All experimental images in this embodiment were collected from Jiutai Cattle Breeding Co., Ltd. in Baicheng City, Jilin Province, China. During the filming, the camera was fixed on a tripod about 1 meter away from the cattle to record videos of Holstein and Simmental cattle in actual breeding scenarios. The recording time was about 20 seconds.
[0159] After recording, the video files were named sequentially from "cow1". To ensure efficient data acquisition, the raw data were all in MP4 video format, the frame rate of the recorded video sequence was 30fps, and the resolution was 1920x1080 pixels.
[0160] Step S2, Data Preprocessing:
[0161] To obtain a dataset rich in facial features, it is necessary to ensure significant differences between keyframe images. This implementation uses SSIM for image cleaning, providing similarity metrics by comparing brightness, contrast, and structure between images to measure their degree of similarity. With the SSIM similarity threshold set to 0.5, pairwise comparisons were performed on adjacent images of each cow. From 106 cows, a total of 3152 images were obtained for data model training and validation.
[0162] Step S3: Create a dataset;
[0163] The dataset should include two parts: one part is the facial feature information of the cattle, which is used for model training and recognition comparison; the other part is the identification information of the cattle, such as breed, age, and health status.
[0164] The specific steps for creating a facial feature dataset are as follows:
[0165] 1. Use the labellmg annotation tool to annotate the data in the preprocessed image from step two;
[0166] 2. Divide the preprocessed images into a dataset in an 8:1:1 ratio, with 80% used as the training set, 10% as the test set, and 10% as the validation set.
[0167] 3. Five image enhancement techniques, including image flipping, color contrast adjustment, color intensity adjustment, and brightness modification, were used to expand the dataset and enhance the model's generalization ability for individual recognition.
[0168] Step S4, Preliminary Target Detection:
[0169] The YOLOv7 model is designed with three core modules: the backbone network, the neck network, and the head network. The specific method for individual feature object detection using this model is as follows:
[0170] 1. Improve the accuracy and speed of target detection through CBS, MP-1 and ELAN modules in the backbone network;
[0171] 2. By utilizing multi-scale feature fusion technology and through FPN and PAN structures, semantic and spatial information at different levels are effectively combined;
[0172] 3. Anchor frame clustering technology is used to adaptively adjust the size and proportion of anchor frames to adapt to the diversity of facial features of different cattle;
[0173] 4. By using a feature extraction network that includes the SPPCS module, the expressive power of the convolutional neural network on detailed features is enhanced, providing richer and more accurate feature information for subsequent facial feature recognition;
[0174] 5. Finally, the robustness of the model to cattle facial features under different lighting, angles and occlusion conditions is enhanced through the CAT and RAP modules.
[0175] Step S5: Design an improved cattle face recognition model based on FaceNet:
[0176] 1. The image input module receives cattle facial image data and converts it into a format that the model can process, ensuring that the image size is uniform (224, 224, 3) and that the color channels meet the model's requirements, so that the model can process image data from different sources.
[0177] 2. Using a deep convolutional neural network, feature vectors of cattle facial images are automatically extracted through multiple convolutional kernels and pooling layers, and cattle faces are recognized based on the Arc Face loss function and Tripletloss loss function.
[0178] In summary, this implementation method, based on deep learning algorithms, provides an improved FaceNet model with stronger recognition performance and generalization ability. By simplifying the algorithm steps, it can improve recognition efficiency while ensuring recognition accuracy, making it more suitable for use in the insurance industry.
[0179] Implementation Method Seven: A facial recognition system for cattle, wherein the system is based on the facial recognition system for images described in Implementation Method Five to recognize the faces of cattle.
[0180] In this embodiment, such as Figure 1 As shown, this invention aims to design a facial recognition system for cattle and establish personalized electronic files for livestock. When applying livestock insurance, it can quickly identify target cattle and simultaneously display their electronic files, significantly promoting the technological advancement, large-scale operation, and high-quality development of livestock farms in my country.
[0181] Overall system assembly:
[0182] 1. Connect the camera, TF card, HDMI cable, etc. to the JETSON NANO development board and set up the necessary environment;
[0183] 2. Save the dataset to the cloud for easy access anytime;
[0184] 3. Use the camera on the JETSON NANO development board to acquire real-time image information, perform facial feature detection on the target cattle, and compare it with cloud data.
[0185] This embodiment describes a facial recognition system for cattle, which simultaneously displays the livestock's personalized electronic profile. Compared to current mainstream insurance identification methods, it significantly improves efficiency and reduces costs and manpower, demonstrating the effectiveness of the method proposed in this embodiment.
[0186] The above provides a detailed description of the facial recognition method and system for cattle proposed in this invention. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this invention. Therefore, the content of this specification should not be construed as a limitation of this invention.
Claims
1. A method for facial recognition of cattle, characterized in that, The method includes the following steps: Step S1: Acquire images and preprocess them, including cleaning the images using an SSIM similarity threshold of 0.5 to exclude similar images and establishing an image dataset, which includes a facial feature dataset and its corresponding identity information dataset. Step S2: Perform object detection on the facial feature dataset based on the YOLOv7 model; Step S3: Based on the FaceNet face recognition method for images, the facial feature dataset after target detection is identified. This completes the identification of the facial feature dataset and displays the identity information dataset corresponding to the facial feature dataset. The FaceNet-based facial recognition method for images is specifically as follows: The image is processed by normalization and regularization in sequence. The processed image is then processed by a residual module, a global average pooling layer, a fully connected layer, and a convolutional neural network to identify features. After feature recognition, the loss values of the Tripletloss function and the Arcface loss function are calculated. Based on the weights of the Tripletloss function and the Arcface loss function, the two loss values are added together to obtain the total loss value. Face recognition of the image is completed based on the total loss value. The fully connected layer limits the embedded vector dimension to 32 dimensions; The weight of the Triplet loss function is 0.6, and the weight of the Arc face loss function is 0.
4. Methods for feature recognition based on convolutional neural networks include: The image is sequentially input into a convolutional layer, a pooling layer, a ResNet backbone network improved based on residual modules, global pooling, flattening, and normalization for target recognition. The vector is transformed into a fixed feature vector of dimension 32 through normalization. The image target recognition method based on the improved ResNet backbone network with residual modules is as follows: The original image is processed sequentially through the first convolutional layer, normalization, the second convolutional layer, normalization, and the third convolutional layer. The first convolutional layer, the second convolutional layer, and the third convolutional layer are residually connected; By changing the number of the first, second, and third convolutional layers, and repeating the operation through the first, second, and third convolutional layers, the original image after multiple iterations is output. The original image is added to the original image after multiple iterations to identify the target in the original image; The number of the first, second, and third convolutional layers is changed to 16, 32, 64, 128, and 512, respectively.
2. The method for facial recognition of cattle according to claim 1, characterized in that, The first convolutional layer is a 7×7 convolutional layer, and the second and third convolutional layers are both 3×3 convolutional layers.
3. A facial recognition system for cattle, the system comprising the following modules: Module S1 acquires images and preprocesses them, including cleaning images with an SSIM similarity threshold of 0.5 to exclude similar images and building an image dataset, which includes a facial feature dataset and its corresponding identity information dataset. Module S2 performs object detection on a facial feature dataset based on the YOLOv7 model; Module S3, based on the FaceNet face recognition method for images, identifies the facial feature dataset after target detection. It then completes the identification of the facial feature dataset and displays the identity information dataset corresponding to the facial feature dataset. The FaceNet-based facial recognition method for images is specifically as follows: The image is processed by normalization and regularization in sequence. The processed image is then processed by a residual module, a global average pooling layer, a fully connected layer, and a convolutional neural network to identify features. After feature recognition, the loss values of the Tripletloss function and the Arcface loss function are calculated. Based on the weights of the Tripletloss function and the Arcface loss function, the two loss values are added together to obtain the total loss value. Face recognition of the image is completed based on the total loss value. The fully connected layer limits the embedded vector dimension to 32 dimensions; The weight of the Triplet loss function is 0.6, and the weight of the Arc face loss function is 0.
4. Methods for feature recognition based on convolutional neural networks include: The image is sequentially input into a convolutional layer, a pooling layer, a ResNet backbone network improved based on residual modules, global pooling, flattening, and normalization for target recognition. The vector is transformed into a fixed feature vector of dimension 32 through normalization. The image target recognition method based on the improved ResNet backbone network with residual modules is as follows: The original image is processed sequentially through the first convolutional layer, normalization, the second convolutional layer, normalization, and the third convolutional layer. The first convolutional layer, the second convolutional layer, and the third convolutional layer are residually connected; By changing the number of the first, second, and third convolutional layers, and repeating the operation through the first, second, and third convolutional layers, the original image after multiple iterations is output. The original image is added to the original image after multiple iterations to identify the target in the original image; The number of the first, second, and third convolutional layers is changed to 16, 32, 64, 128, and 512, respectively.
Citation Information
Patent Citations
CN111242222A
CN117912058A