Pig face recognition method and system based on double-feature sensing network
Through the pig face recognition method of dual feature perception network, combined with multi-layer feature aggregation and FPN feature pyramid network, the accuracy and efficiency of pig face recognition in complex environments are solved, and efficient and accurate pig face recognition effect is achieved.
Patent Information
- Application Number
- CN202411358063.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-27
AI Technical Summary
The existing pig face recognition technology is difficult to effectively integrate global and local information in complex environments, resulting in poor recognition results, especially in the rapid growth of live pigs, similar facial features of multiple animals, changes in light and facial defilement, which is difficult to meet. Efficient and accurate identification of requirements.
The pig face recognition method based on the dual feature perception network is adopted. By constructing a multi-layer feature aggregation module and a global extraction head, combining the FPN feature pyramid network, global and local features at different depth levels are integrated to improve the recognition accuracy and efficiency of the model.
It significantly improves the accuracy and efficiency of pig face recognition, reduces the misidentification and misidentification rate, ensures the high recognition performance of the model under different lighting and angles, and the structural optimization reduces the computing burden, and is suitable for resource-constrained environments.
Smart Images

Figure CN119314203A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and more particularly to a pig face recognition method and system based on a dual-feature perception network. Background Art
[0002] At present, with the advancement of agricultural technology and the acceleration of digital transformation, agricultural insurance plays an increasingly important role in ensuring the stability of agricultural production, especially in the settlement of pig death claims. Among them, accurate confirmation of pig identity is crucial. At present, commonly used pig identification methods include ear tags, RFID tags, and manual marking. Although these methods have certain application value, with the expansion of breeding scale, traditional identification methods are difficult to meet the needs of efficiency and accuracy. To this end, insurance companies have begun to gradually introduce facial recognition technology to improve the accuracy and efficiency of the claims process.
[0003] There are still several technical difficulties in the field of pig face recognition with existing computer vision technology. First, the normal breeding cycle of live pigs is 150-180 days. They grow fast and have a short fattening cycle, and their facial features change significantly. Secondly, because pigs are multi-birth animals, the facial features of piglets in the same litter are similar and the individual features vary little. Finally, the large changes in lighting conditions in the pig house, facial stains and occlusions on the pigs will all cause difficulties for the recognition performance of the model. Traditional neural network recognition models are difficult to effectively integrate global and local information under complex environmental conditions and when the facial features of the objects to be detected vary greatly, resulting in poor recognition results. These technical difficulties limit the promotion and popularization of pig face recognition technology in practical applications.
[0004] Therefore, how to effectively improve the accuracy and efficiency of pig face recognition is an urgent problem that technical personnel in this field need to solve. Summary of the invention
[0005] In view of this, in order to overcome the shortcomings of the prior art, the present invention provides a pig face recognition method and system based on a dual-feature perception network, which effectively improves the accuracy and efficiency of the pig face recognition model by simultaneously paying attention to the global and local features of different depth levels and efficiently splicing them together.
[0006] In order to achieve the above object, the present invention adopts the following technical solution:
[0007] On the one hand, a pig face recognition method based on a dual-feature perception network is provided, comprising:
[0008] Step 1: Collect the facial images of the pig faces to be detected and crop them to a uniform size, and establish a pig face dataset based on the individual identity number;
[0009] Step 2: Divide the pig face dataset into a training set and a test set. Perform data enhancement on the training set for model training; the test set is used to evaluate model performance.
[0010] Step 3: Construct a pig face recognition network model based on a dual-feature perception network;
[0011] Step 4: Use the training set to train the pig face recognition network model based on the dual-feature perception network, and use the Adam gradient descent method to update the loss function value of the model;
[0012] Step 5: Use the test set to verify the network performance and calculate the performance index. If the performance index reaches the specified threshold, save the model weight;
[0013] Step 6: Input the pig face image to be identified into the verified pig face recognition network model based on the dual-feature perception network to obtain the pig face recognition result.
[0014] Optionally, the specific process of step 3 is as follows:
[0015] Step 3.1, build the backbone network of the pig face recognition model, and output three layers of feature maps with different resolutions;
[0016] Step 3.2, transfer the three layers of feature maps with different resolutions to the FPN feature pyramid network, and obtain three feature maps of different scales as the output of the feature pyramid network;
[0017] Step 3.3, establish an MFA multi-layer feature aggregation module to extract local features of three different scale feature maps;
[0018] Step 3.4, establish a global extraction head to extract global features of three feature maps of different scales;
[0019] Step 3.5, the splicing network splices the extracted local features and global features to obtain fused features;
[0020] Step 3.6: Input the concatenated fusion features into the FFN feedforward neural network to obtain the final predicted category of the input sample.
[0021] Optionally, the step 3.1 specifically includes:
[0022] Build the backbone network of the pig face recognition model: use the DLA deep aggregation backbone network, and connect the following structures in series along the input-output direction: the initial convolution layer, whose convolution kernel size is 7×7, the stride is 1, the padding is 3, and the number of channels is 64; the normalization layer, which normalizes the output of the initial convolution layer 1; the activation layer, which uses the ReLU activation function to introduce nonlinear features; the layer-by-layer aggregation module, which contains multiple convolution layers, each of which has a convolution kernel size of 3×3, a stride of 1, a padding of 1, and a number of channels of 64, and the outputs of each convolution layer are fused by addition operations; the convolution block, which contains a combination of multiple convolution layers and normalization layers, where the convolution kernel size of the convolution layer is 3×3, the stride is 1, the padding is 1, and the number of channels is 128, and a ReLU activation layer is placed after each batch normalization layer; the last is an SPPF structure, which outputs 3 layers of feature maps with different resolutions.
[0023] Optionally, the specific operation process of the FPN feature pyramid network in step 3.2 is:
[0024] When the three layers of feature maps with different resolutions are transmitted to the FPN feature pyramid network, bilinear interpolation is used to gradually upsample the deep low-resolution feature maps to the size of the adjacent high-resolution layer, and the upsampled feature maps are horizontally connected with the feature maps of the same resolution from the backbone network; after each horizontal connection, a 1×1 convolution layer is followed to fuse the upsampled features with the features of the backbone network. After the horizontal connection and upsampled feature maps, a convolution layer with a convolution kernel size of 3×3, a stride of 2, and a padding of 1 is passed to obtain three different scale feature maps as the output of the feature pyramid network.
[0025] Optionally, the step 3.3 specifically includes:
[0026] Use the minimum size feature map: Let F n As the input feature map, the dilated convolution and SiLU activation function are used to obtain the intermediate feature F' n , and then perform context-aware attention operations on it to obtain a new feature map F″ n , finally, F″ n Connect the original features on the channel axis and then reduce the dimension to get F″′ n , and finally the local features of different receptive fields are aggregated and calculated as:
[0027]
[0028] in For the connection operation, For each channel, element multiplication is performed, φ represents a 1×1 convolution operation, and after aggregation, a corresponding local feature vector is obtained. W c is the weight of the channel direction.
[0029] Optionally, the step 3.4 specifically includes:
[0030] The size of the three different scale feature maps output by the feature pyramid network is cropped to 30×30, and the global extraction head is constructed using deformable attention: is the input feature map layer level, where For each layer, K reference points are assigned. For each reference point q of a feature map, its initial normalized coordinate p in the input feature map is determined. q ∈[0,1] 2 , the sampling offset of each reference point in each layer of the feature mapping layer is dynamically calculated through the deformable attention mechanism, and the formula is as follows:
[0031] d=(R l (p q )+Δp mlgk );
[0032] Where R l (p q ) is the physical coordinate of the initial reference point q, Δp mlqk is the offset of the kth sampling point of the lth feature layer and the mth attention head, and then the input feature map is bilinearly interpolated to obtain the corresponding sampling feature φ(x l ; d), the formula is as follows:
[0033] A mlqk =W m ·φ(x l ; d)
[0034] Where W m is the learnable weight matrix, φ(x l ; d) is the characteristic value obtained through sampling point d;
[0035] Then the features of all sampling points are weighted and summed, and fused and activated through a fully connected layer to obtain the final global feature matrix A glob , the formula is as follows:
[0036]
[0037] in and is a learnable weight matrix, φ represents a bilinear interpolation to calculate the interpolation features of each reference point of the sampling offset d; Represents a fully connected layer, used to activate the information obtained by sampling, by transforming the matrix A glob Perform pooling operation to obtain the global feature vector
[0038] Optionally, the specific structure of the FFN feedforward neural network is:
[0039] The FFN feedforward neural network includes four fully connected layers, and its output dimensions are: 256, 128, 64, N, where N is the predetermined number of pig identity categories; the sizes of the weight matrix W are: 256×512, 128×256, 64×128, N×64, and the sizes of the bias vector b are 256, 128, 64, N, respectively. The first three layers all use the ReLU activation function, and the output layer does not use the activation function and directly outputs the prediction result vector z; Softmax layer: The Softmax layer converts the output of z into a category probability distribution The formula is as follows:
[0040]
[0041] where z j is the value of the jth output node in z, and N is the number of categories;
[0042] According to the category probability distribution output by the Softmax layer, the category with the largest probability value is selected as the final predicted category of the input sample. The specific calculation formula is as follows:
[0043]
[0044] in Represents the final predicted category of the i-th input sample.
[0045] Optionally, step 4 specifically includes:
[0046] Step 4.1. At the end of each training cycle, calculate the loss function value L of the current cycle, and continuously monitor the change of the loss function value over multiple training cycles;
[0047] Step 4.2: Set the number of training cycles T1 and a continuous number of cycles T2. If the change in the value of the loss function L gradually decreases during these T2 cycles and meets the following conditions, the training is considered to have converged:
[0048]
[0049] Among them, L t is the loss function value of the tth training cycle, and ∈ is the set change amplitude threshold.
[0050] Optionally, the loss function L is the classification loss L cls With the regression loss L reg The weighted sum of is calculated as follows:
[0051] L=α*·Lcls +β·L reg ;
[0052] Among them, α and β are weight coefficients used to balance the impact of classification loss and regression loss.
[0053] On the other hand, a pig face recognition system based on a dual-feature perception network is provided, comprising:
[0054] The data collection module collects the facial images of the pig faces to be detected and crops them into a uniform size, and establishes a pig face dataset based on the individual identification number;
[0055] The data set division module divides the pig face data set into a training set and a test set, and performs data enhancement on the training set for model training; the test set is used to evaluate model performance;
[0056] Network model building module, building a pig face recognition network model based on dual-feature perception network;
[0057] The model training module uses the training set to train the pig face recognition network model based on the dual-feature perception network, and uses the Adam gradient descent method to update the loss function value of the model;
[0058] The model testing module verifies the network performance and calculates the performance index using the test set. If the performance index reaches the specified threshold, the model weight is saved;
[0059] The result output module inputs the pig face image to be identified into the verified pig face recognition network model based on the dual-feature perception network to obtain the pig face recognition result.
[0060] It can be seen from the above technical solutions that the present invention discloses a pig face recognition method and system based on a dual-feature perception network, which has the following beneficial effects compared with the prior art:
[0061] 1. The present invention adopts a dual-feature perception network model and introduces a dual-feature extraction mechanism to effectively enhance the model's ability to identify pig face features and significantly improve recognition accuracy. Compared with a single feature extraction model, the present invention can more comprehensively capture the subtle differences in pig faces and reduce the false recognition rate and missed recognition rate.
[0062] 2. By monitoring and adjusting the loss function during the training process, the present invention can timely identify and correct the overfitting or underfitting problems that may occur during the training process, ensuring that the trained model has high stability and robustness. In particular, when facing pig face images under different lighting, angles and backgrounds, the model can still maintain a high recognition accuracy.
[0063] 3. When designing the dual-feature perception network model, the present invention fully considers the structural volume of the model, and reduces the depth and width of the network by introducing lightweight convolutional layers and feature extraction modules, thereby reducing the number of parameters. This structural optimization not only reduces the computational burden of the model, but also enables the model to run more efficiently in a resource-constrained environment, thereby improving the efficiency of recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0065] Figure 1 A flow chart of the method provided by the present invention;
[0066] Figure 2 This is a structural diagram of the pig face recognition network model based on the dual-feature perception network provided by the present invention. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0068] On the one hand, the embodiment of the present invention discloses a pig face recognition method based on a dual-feature perception network, such as Figure 1 As shown, including:
[0069] Step 1: Collect the facial images of the pig faces to be detected and crop them to a uniform size, and establish a pig face dataset based on the individual identity number;
[0070] Specifically, it is necessary to detect the identities of 30 individual pigs, set a camera facing the entrance of each pig pen, or arrange a camera on the pig drinking device, and take facial images of pigs from multiple angles, multiple light sources and different environments; first screen the collected images to remove blurry images or images that do not capture the pig's face, then uniformly crop the images to a size of 640×640 pixels, and number the collected pig face images as {pig1, pig2, pig3, ..., pig30}.
[0071] Step 2: Divide the pig face dataset into a training set and a test set in a ratio of 8:2. Perform data enhancement on the training set for model training; the test set is used to evaluate model performance.
[0072] Specifically, the data enhancement methods used are: random rotation, random occlusion, darkening, brightening, mirroring and adding noise.
[0073] Step 3: Construct a pig face recognition network model based on a dual-feature perception network, such as Figure 2 As shown, the specific steps are as follows:
[0074] Step 3.1, build the backbone network of the pig face recognition model: use the DLA deep aggregation backbone network, and connect the following structures in series along the input-output direction: the initial convolution layer, whose convolution kernel size is 7×7, the stride is 1, the padding is 3, and the number of channels is 64; the normalization layer, normalizes the output of the initial convolution layer 1; the activation layer, uses the ReLU activation function to introduce nonlinear features; the layer-by-layer aggregation module, which contains multiple convolution layers, each of which has a convolution kernel size of 3×3, a stride of 1, a padding of 1, and a number of channels of 64, and the outputs of each convolution layer are fused by addition operations; convolution block 1, which contains a combination of multiple convolution layers and normalization layers, where the convolution kernel size of the convolution layer is 3×3, the stride is 1, the padding is 1, and the number of channels is 128, and a ReLU activation layer is placed after each batch normalization layer; the last is an SPPF structure, which outputs 3 layers of feature maps with different resolutions;
[0075] Step 3.2: Transfer the three-layer feature map to the FPN feature pyramid network, use bilinear interpolation to gradually upsample the lower-resolution feature map of the deeper layer to the size of the adjacent high-resolution layer, and connect the upsampled feature map to the feature map of the same resolution from the backbone network horizontally. After each horizontal connection, follow a 1×1 convolution layer to fuse the upsampled features with the features of the backbone network. After the horizontal connection and upsampled feature map, pass through a convolution layer with a convolution kernel size of 3×3, a stride of 2, and a padding of 1 to obtain three different scale feature maps as the output of the feature pyramid network;
[0076] Step 3.3, establish an MFA multi-layer feature aggregation module to extract local features;
[0077] Use the minimum size feature map: Let F n As the input feature map, the dilated convolution and SiLU activation function are used to obtain the intermediate feature F' n , and then perform context-aware attention operations on it to obtain a new feature map F″ n , finally, F″ n Connect the original features on the channel axis and then reduce the dimension to get F″′ n, the final aggregation of local features of different receptive fields is calculated as:
[0078]
[0079] in For the connection operation, For each channel, element multiplication is performed, φ represents a 1×1 convolution operation, and after aggregation, a corresponding local feature vector is obtained. W c is the weight of the channel direction; is the feature dimension, C p is the number of local feature channels, C g is the number of global feature channels, C v =C g / m, m is the number of attention heads;
[0080] Step 3.4: Establish a global extraction head to extract global features:
[0081] The three-layer feature map output by the feature pyramid network is cropped to 30×30 to reduce memory overhead, and the deformable attention is used to construct the global extraction head: is the input feature map layer level, where H g and W g is the height and width in the global extraction head; assign K reference points to each layer, and for each reference point q of the feature map, determine its initial normalized coordinate p in the input feature map q ∈[0,1] 2 , the sampling offset of each reference point in each layer of the feature mapping layer is dynamically calculated through the deformable attention mechanism, and the formula is as follows:
[0082] d=(R l (p q )+Δp mlqk );
[0083] Where R l (p q ) is the physical coordinate of the initial reference point q, Δp mlqk is the offset of the kth sampling point of the lth feature layer and the mth attention head, and then the input feature map is bilinearly interpolated to obtain the corresponding sampling feature A mlqk , the formula is as follows:
[0084] A mlqk =W m ·φ(x l ; d);
[0085] Where W m is the learnable weight matrix, φ(xl ; d) is the characteristic value obtained through sampling point d.
[0086] Then the features of all sampling points are weighted and summed, and fused and activated through a fully connected layer to obtain the final global feature matrix A glob , the formula is as follows:
[0087]
[0088] in and is a learnable weight matrix, and φ represents a bilinear interpolation to calculate the interpolated features of each reference point of the sampling offset d. Represents a fully connected layer, used to activate the information obtained by sampling, by transforming the matrix A glob Perform pooling operation to obtain the global feature vector
[0089] In this case, H g =10,W g =25, K=4.
[0090] Step 3.5: Concatenate local features extracted from the network and global features Get fusion features
[0091] Step 3.6: Combine the fused features Input into the FFN feedforward neural network, which includes four fully connected layers, and the output dimensions are: 256, 128, 64, N, where N is the predetermined number of pig identity categories; the sizes of the weight matrix W are: 256×512, 128×256, 64×128, N×64, and the sizes of the bias vector b are 256, 128, 64, N, respectively. The first three layers all use the ReLU activation function, and the output layer does not use the activation function and directly outputs the prediction result vector z; Softmax layer: The Softmax layer converts the output of z into a category probability distribution The formula is as follows:
[0092]
[0093] where z j is the value of the jth output node in z, and N is the number of categories;
[0094] According to the category probability distribution output by the Softmax layer, the category with the largest probability value is selected as the final predicted category of the input sample. The specific calculation formula is as follows:
[0095]
[0096] in Represents the final predicted category of the i-th input sample.
[0097] Step 4: Use the training set to train the pig face recognition network model based on the dual-feature perception network, and use the Adam gradient descent method to update the loss function value of the model, including the following steps:
[0098] Step 4.1. At the end of each training cycle, calculate the loss function value L of the current cycle, and continuously monitor the change of the loss function value over multiple training cycles;
[0099] Step 4.2: Set the number of training cycles T1 and a continuous number of cycles T2. If the change in the value of the loss function L gradually decreases during these T2 cycles and meets the following conditions, the training is considered to have converged:
[0100]
[0101] Among them, L t is the loss function value of the tth training cycle, ∈ is the set change amplitude threshold;
[0102] In this embodiment, T1=100, T2=10, ∈=10 -4 .
[0103] Step 5: Use the test set to verify the network performance and calculate the performance indicators. The performance indicators use parameters such as accuracy P, recall rate R, and average precision mAP. If the performance indicators reach the specified threshold, the model weights are output and saved.
[0104] Step 6: Input the pig face image to be identified into the verified pig face recognition network model based on the dual-feature perception network to obtain the pig face recognition result, that is, the individual pig identity number.
[0105] In step 4, the Adam gradient descent method updates the model parameter θ using the following formula:
[0106]
[0107] Where η is the learning rate, is the bias-corrected estimate of the first-order momentum, is the bias-corrected estimate of the second-order momentum, ∈ is a constant set to prevent division by zero errors;
[0108] Furthermore, the loss function L in step 4 is the classification loss L cls With the regression loss L reg The weighted sum of is calculated as follows:
[0109] L=α·L cls+β·L reg ;
[0110] Among them, α and β are weight coefficients used to balance the impact of classification loss and regression loss;
[0111] In this case, α=0.6 and β=0.4.
[0112] During the training process, the training set Input to the model, where x i is the input feature of the i-th training sample, y i For the corresponding true label, the classification loss uses focal loss, which is defined as follows:
[0113]
[0114] where p t For the model to sample x i The predicted probability, α t and γ are adjustment parameters
[0115] The regression loss uses smooth L1 loss, defined as follows:
[0116]
[0117] Among them, smooth L1 Loss function smoothing L1 is defined as:
[0118]
[0119] Furthermore, the accuracy P in step 4 is the proportion of correctly predicted results among all the prediction results given by the model, and the calculation formula is as follows:
[0120]
[0121] TP is a positive sample detected as positive by the model due to a correct detection result, and FP is a negative sample detected as positive by the model due to an incorrect detection result;
[0122] The recall rate R represents the proportion of correctly detected targets in the real frame, and the calculation formula is as follows:
[0123]
[0124] Where FN is the positive sample detected as negative by the model;
[0125] The average precision mAP calculation formula is as follows:
[0126]
[0127] Where i is the number of the pig category, i = 1, 2, 3...n, AP i It represents the AP value of the i-th type of pig. The AP value is the area under the PR curve drawn with precision P as the ordinate and recall R as the abscissa.
[0128] In this case, the backbone network structure DLA structure can be optimized as follows: the backbone network includes the following structures connected in series along the input-output direction of the backbone network: initial convolution layer 1, with a convolution kernel size of 7×7, a stride of 1, a padding of 3, and a number of channels of 64; a maximum pooling layer, with a pooling kernel size of 3×3, a stride of 2, and a padding of 1; a basic residual structure, including two convolution layers with a convolution kernel size of 3×3, a stride of 1, a padding of 1, and a number of channels of 64, and a shortcut Connection jump connection, adding the input directly to the output after two convolutions; convolution layer 2, the convolution kernel size is 3×3, the stride is 2, the padding is 1, and the number of channels is 128; the bottleneck residual structure, including three convolution layers with a convolution kernel size of 3×3, a stride of 1, a padding of 0, and a number of channels of 64, a convolution kernel size of 3×3, a stride of 1, a padding of 1, and a number of channels of 128, and a convolution kernel size of 3×3, a stride of 1, a padding of 0, and a number of channels of 128, and a jump connection, adding the input to the output after three convolutions; convolution layer 3, the convolution kernel size is 3×3, the stride is 2, the padding is 1, and the number of channels is 256; the segmentation attention residual structure, The input feature map is divided into multiple sub-feature maps. Each sub-feature map passes through a convolution layer with a convolution kernel size of 3×3, a stride of 2, a padding of 1, and a channel number of 256. The adjusted sub-feature maps are recombined and the input and the recombined features are added; convolution layer 4, the convolution kernel size is 3×3, the stride is 2, the padding is 1, and the channel number is 512; iterative deep aggregation structure, through the convolution operation of size 3×3, stride 2, and padding 1, the features from different layers are successively integrated. Finally, there is an SPPF structure, which uses pooling kernels of different sizes for multi-scale pooling, and then splices the feature maps after each pooling. The multi-scale feature map output by the SPPF layer is used as the output of the backbone network;
[0129] Furthermore, in the implementation process of the present invention, in order to ensure the training effect of the model, it is necessary to collect as much data as possible. It is recommended that the data set should be more than 30, and the photos collected for each pig should be more than 300. The images can be collected by recording a video and then captured from the video. In the training process of the model, the Adam gradient descent method with a learning rate of 1e-3 is used, and the cosine decay learning rate is set to 0.9.
[0130] Furthermore, in the implementation process of the present invention, in order to improve the output effect of the model, a PRN region proposal network can be added after the FFN network, and multiple candidate regions can be generated by sliding windows and anchor boxes. Each candidate region has a different confidence score and bounding box regression value, and all candidate detection frames are screened using the NMS non-maximum suppression algorithm. The steps to implement non-maximum suppression are as follows: first calculate the confidence score s of each detection frame and sort them according to these scores; then, select the detection frame with the highest confidence in turn and calculate its intersection over union (IoU) with other detection frames. For detection frames whose IoU exceeds a certain threshold, they are considered redundant and removed.
[0131] The present invention, through a dual-feature perception architecture, can capture the global correlation between features at different positions, significantly enhancing the model's ability to understand complex backgrounds and multi-target scenarios. In addition, combined with a multi-layer feature aggregation module, rich contextual information is integrated at different levels, making the model more accurate in identifying and locating targets of different scales. Furthermore, by introducing a deformable attention mechanism to weight features, the expressive power of feature maps is improved, and the contribution of important features in downstream tasks is significantly enhanced. In summary, the present invention has made innovative designs in feature extraction and aggregation, and has broad application prospects and significant practical value.
[0132] On the other hand, a pig face recognition system based on a dual-feature perception network is provided, comprising:
[0133] The data collection module collects the facial images of the pig faces to be detected and crops them into a uniform size, and establishes a pig face dataset based on the individual identification number;
[0134] The data set division module divides the pig face data set into a training set and a test set, and performs data enhancement on the training set for model training; the test set is used to evaluate model performance;
[0135] Network model building module, building a pig face recognition network model based on dual-feature perception network;
[0136] The model training module uses the training set to train the pig face recognition network model based on the dual-feature perception network, and uses the Adam gradient descent method to update the loss function value of the model;
[0137] The model testing module verifies the network performance and calculates the performance index using the test set. If the performance index reaches the specified threshold, the model weight is saved;
[0138] The result output module inputs the pig face image to be identified into the verified pig face recognition network model based on the dual-feature perception network to obtain the pig face recognition result.
[0139] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0140] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A pig face recognition method based on a dual-feature perception network, characterized in that: include: Step 1: Collect the facial images of the pig faces to be detected and crop them to a uniform size, and establish a pig face dataset based on the individual identity number; Step 2: Divide the pig face dataset into a training set and a test set. Perform data enhancement on the training set for model training; the test set is used to evaluate model performance. Step 3: Construct a pig face recognition network model based on a dual-feature perception network; Step 4: Use the training set to train the pig face recognition network model based on the dual-feature perception network, and use the Adam gradient descent method to update the loss function value of the model; Step 5: Use the test set to verify the network performance and calculate the performance index. If the performance index reaches the specified threshold, save the model weight; Step 6: Input the pig face image to be identified into the verified pig face recognition network model based on the dual-feature perception network to obtain the pig face recognition result.
2. A pig face recognition method based on a dual-feature perception network according to claim 1, characterized in that: Step 3: The specific process is as follows: Step 3.1, build the backbone network of the pig face recognition model, and output three layers of feature maps with different resolutions; Step 3.2, transfer the three layers of feature maps with different resolutions to the FPN feature pyramid network, and obtain three feature maps of different scales as the output of the feature pyramid network; Step 3.3, establish an MFA multi-layer feature aggregation module to extract local features of three different scale feature maps; Step 3.4, establish a global extraction head to extract global features of three feature maps of different scales; Step 3.5, the splicing network splices the extracted local features and global features to obtain fused features; Step 3.6: Input the concatenated fusion features into the FFN feedforward neural network to obtain the final predicted category of the input sample.
3. A pig face recognition method based on a dual-feature perception network according to claim 1, characterized in that: The step 3.1 specifically includes: Build the backbone network of the pig face recognition model: use the DLA deep aggregation backbone network, and connect the following structures in series along the input-output direction: the initial convolution layer, whose convolution kernel size is 7×7, the stride is 1, the padding is 3, and the number of channels is 64; the normalization layer, which normalizes the output of the initial convolution layer 1; the activation layer, which uses the ReLU activation function to introduce nonlinear features; the layer-by-layer aggregation module, which contains multiple convolution layers, each of which has a convolution kernel size of 3×3, a stride of 1, a padding of 1, and a number of channels of 64, and the outputs of each convolution layer are fused by addition operations; the convolution block, which contains a combination of multiple convolution layers and normalization layers, where the convolution kernel size of the convolution layer is 3×3, the stride is 1, the padding is 1, and the number of channels is 128, and a ReLU activation layer is placed after each batch normalization layer; the last is an SPPF structure, which outputs 3 layers of feature maps with different resolutions.
4. A pig face recognition method based on a dual-feature perception network according to claim 1, characterized in that: The specific operation process of the FPN feature pyramid network in step 3.2 is: When the three layers of feature maps with different resolutions are transmitted to the FPN feature pyramid network, bilinear interpolation is used to gradually upsample the deep low-resolution feature maps to the size of the adjacent high-resolution layer, and the upsampled feature maps are horizontally connected with the feature maps of the same resolution from the backbone network; after each horizontal connection, a 1×1 convolution layer is followed to fuse the upsampled features with the features of the backbone network. After the horizontal connection and upsampled feature maps, a convolution layer with a convolution kernel size of 3×3, a stride of 2, and a padding of 1 is passed to obtain three different scale feature maps as the output of the feature pyramid network.
5. A pig face recognition method based on a dual-feature perception network according to claim 1, characterized in that: The step 3.3 specifically includes: Use the minimum size feature map: Let F n As the input feature map, the dilated convolution and SiLU activation function are used to obtain the intermediate feature F′ n , and then perform context-aware attention operations on it to obtain a new feature map F″ n , finally, F″ n Connect the original features on the channel axis and then reduce the dimension to get F n , and finally the local features of different receptive fields are aggregated and calculated as: in For the connection operation, For each channel, element multiplication is performed, φ represents a 1×1 convolution operation, and after aggregation, a corresponding local feature vector is obtained. W c is the weight of the channel direction; is the feature dimension, C p is the number of local feature channels.
6. A pig face recognition method based on a dual-feature perception network according to claim 1, characterized in that: The step 3.4 specifically includes: The size of the three different scale feature maps output by the feature pyramid network is cropped to 30×30, and the global extraction head is constructed using deformable attention: is the input feature map layer level, where H g and W g Extract the height and width of the header globally. is the feature dimension, C g is the number of global feature channels, C v =C g / m, m is the number of attention heads; K reference points are assigned to each layer, and for each reference point q of the feature map, its initial normalized coordinate p in the input feature map is determined q ∈[0, 1] 2 , the sampling offset of each reference point in each layer of the feature mapping layer is dynamically calculated through the deformable attention mechanism, and the formula is as follows: d=(R l (p q )+Δp mlqk ); Where R l (p q ) is the physical coordinate of the initial reference point q, Δp mlqk is the offset of the kth sampling point of the lth feature layer and the mth attention head, and then the input feature map is bilinearly interpolated to obtain the corresponding sampling feature φ(x l ; d), the formula is as follows: A mlqk =W m ·φ(x l ;d) Where W m is the learnable weight matrix, φ(x l ; d) is the characteristic value obtained through sampling point d; Then the features of all sampling points are weighted and summed, and fused and activated through a fully connected layer to obtain the final global feature matrix A glob , the formula is as follows: in and is a learnable weight matrix, φ represents a bilinear interpolation to calculate the interpolation features of each reference point of the sampling offset d; Represents a fully connected layer, used to activate the information obtained by sampling, by transforming the matrix A glob Perform pooling operation to obtain the global feature vector 7. A pig face recognition method based on a dual-feature perception network according to claim 2, characterized in that: The specific structure of the FFN feedforward neural network is: The FFN feedforward neural network includes four fully connected layers, and its output dimensions are: 256, 128, 64, N, where N is the predetermined number of pig identity categories; the sizes of the weight matrix W are: 256×512, 128×256, 64×128, N×64, and the sizes of the bias vector b are 256, 128, 64, N, respectively. The first three layers all use the ReLU activation function, and the output layer does not use the activation function and directly outputs the prediction result vector z; Softmax layer: The Softmax layer converts the output of z into a category probability distribution The formula is as follows: where z j is the value of the jth output node in z, and N is the number of categories; According to the category probability distribution output by the Softmax layer, the category with the largest probability value is selected as the final predicted category of the input sample. The specific calculation formula is as follows: in Represents the final predicted category of the i-th input sample.
8. A pig face recognition method based on a dual-feature perception network according to claim 1, characterized in that: The step 4 specifically includes: Step 4.
1. At the end of each training cycle, calculate the loss function value L of the current cycle, and continuously monitor the change of the loss function value over multiple training cycles; Step 4.2: Set the number of training cycles T1 and a continuous number of cycles T2. If the change in the value of the loss function L gradually decreases during these T2 cycles and meets the following conditions, the training is considered to have converged: Among them, L t is the loss function value of the tth training cycle, and ∈ is the set change amplitude threshold.
9. A pig face recognition method based on a dual-feature perception network according to claim 8, characterized in that: The loss function L is the classification loss Lc ls With the regression loss L reg The weighted sum of is calculated as follows: L=α·L cls +β·L reg ; Among them, α and β are weight coefficients used to balance the impact of classification loss and regression loss.
10. A pig face recognition system based on a dual-feature perception network, characterized in that: A pig face recognition method based on a dual-feature perception network according to any one of claims 1 to 9 is applied, comprising: The data collection module collects the facial images of the pig faces to be detected and crops them into a uniform size, and establishes a pig face dataset based on the individual identification number; The data set division module divides the pig face data set into a training set and a test set, and performs data enhancement on the training set for model training; the test set is used to evaluate model performance; Network model building module, building a pig face recognition network model based on dual-feature perception network; The model training module uses the training set to train the pig face recognition network model based on the dual-feature perception network, and uses the Adam gradient descent method to update the loss function value of the model; The model testing module verifies the network performance and calculates the performance index using the test set. If the performance index reaches the specified threshold, the model weight is saved; The result output module inputs the pig face image to be identified into the verified pig face recognition network model based on the dual-feature perception network to obtain the pig face recognition result.
Citation Information
Patent Citations
Face anti-fraud method based on cross-domain feature alignment network
CN114120401A
Semantic segmentation method based on channel attention and pyramid convolution fusion
CN114155371A
Cross-view gait recognition method based on staged multistage pyramid
CN115050093A
Face detection method, apparatus, and device, and training method, apparatus, and device for image detection neural network
US20220262162A1