A pig face recognition method and system based on a double-feature perception network
By constructing a pig face recognition method based on a dual-feature perception network and combining global and local feature extraction, the problem of poor pig face recognition in complex environments is solved, and efficient and accurate pig face recognition results are achieved.
Patent Information
- Application Number
- CN202411358063.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2044-09-27
AI Technical Summary
Existing pig face recognition technology struggles to effectively integrate global and local information in complex environments, resulting in poor recognition results and failing to meet the requirements for efficient and accurate recognition.
A pig face recognition method based on a dual-feature perception network is adopted. By constructing a dual-feature perception network model, combining global and local feature extraction, and using the FPN feature pyramid network and the MFA multi-layer feature aggregation module, local and global features are spliced together to improve recognition accuracy and efficiency.
It significantly improves the accuracy and efficiency of pig face recognition, reduces the false recognition rate and the missed recognition rate, and maintains high recognition accuracy, especially under different lighting and background conditions. Furthermore, the optimized model structure reduces the computational burden and is suitable for resource-constrained environments.
Smart Images

Figure CN119314203B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision, and more particularly to a pig face recognition method and system based on a dual-feature perception network. BACKGROUND
[0002] At present, with the progress 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 aspect of pig death claims. Among them, the accurate confirmation of pig identity is crucial. At present, common pig identification methods include ear tags, RFID tags and manual marking, etc. These methods have certain application value, but as the scale of breeding expands, traditional identification methods are difficult to meet the needs of efficiency and accuracy. Therefore, insurance companies have begun to gradually introduce facial recognition technology to improve the accuracy and efficiency of the claims process.
[0003] There are still some technical problems in the existing computer vision technology in the field of pig face recognition. First, the normal breeding cycle of live pigs is 150-180 days, and the growth is rapid and the fattening period is short, with significant changes in facial features. Secondly, since pigs are polytocous animals, the facial features of piglets in the same litter are similar and the individual characteristics are small. Finally, the lighting conditions in the pig house change greatly, the pig face is dirty and the occlusion phenomenon will cause difficulties in the recognition performance of the model. Traditional neural network recognition models are difficult to effectively integrate global and local information when the facial features of the detected objects change greatly in complex environmental conditions, resulting in poor recognition results. These technical problems limit the popularization and promotion of pig facial recognition technology in practical applications.
[0004] Therefore, how to effectively improve the precision and efficiency of pig face recognition is a problem that needs to be solved by those skilled in the art. SUMMARY
[0005] Therefore, in order to overcome the shortcomings of the prior art, the present application provides a pig face recognition method and system based on a dual-feature perception network, which simultaneously focuses on global and local features at different depth levels and efficiently splices them together, thereby effectively improving the precision and efficiency of the pig face recognition model.
[0006] In order to achieve the above purpose, the present application adopts the following technical solutions:
[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 pig face image to be detected and crop it to a uniform size, and based on the individual identity number, establish a pig face dataset;
[0009] Step 2, divide the pig face dataset into a training set and a test set, perform data augmentation on the training set for model training; the test set is used to evaluate the performance of the model;
[0010] Step 3, construct a pig face recognition network model based on a dual feature perception network;
[0011] Step 4, train the pig face recognition network model based on the dual feature perception network using the training set, and update the loss function value of the model using the Adam gradient descent method;
[0012] Step 5, verify the network performance using the test set and calculate the performance indicators, and save the model weight if the performance indicators reach the specified threshold;
[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 a pig face recognition model backbone network, and the output is 3 layers of different resolution feature maps;
[0016] Step 3.2, transmit the 3 layers of different resolution feature maps to the FPN feature pyramid network to obtain 3 kinds of different scale feature maps as the output of the feature pyramid network;
[0017] Step 3.3, establish a MFA multi-layer feature aggregation module to extract local features of the 3 kinds of different scale feature maps;
[0018] Step 3.4, establish a global feature extraction head to extract global features of the 3 kinds of different scale feature maps;
[0019] Step 3.5, splice the local features and global features extracted to obtain fused features;
[0020] Step 3.6, input the fused features after splicing into the FFN feedforward neural network to obtain the final prediction class of the input sample.
[0021] Optionally, the step 3.1 specifically includes:
[0022] The pig face recognition model backbone network is built: a DLA deep aggregation backbone network is adopted, and the following structures are sequentially connected in the input-output direction: an initial convolution layer with a convolution kernel size of 7*7, a step of 1, padding of 3, and a channel number of 64; a normalization layer for normalizing the output of the initial convolution layer 1; an activation layer using a ReLU activation function to introduce nonlinear features; a layer-by-layer aggregation module containing multiple convolution layers, each convolution layer having a convolution kernel size of 3*3, a step of 1, padding of 1, and a channel number of 64, and the outputs of the convolution layers are fused through an addition operation; a convolution block containing a combination of multiple convolution layers and normalization layers, wherein the convolution layers have a convolution kernel size of 3*3, a step of 1, padding of 1, and a channel number of 128, and a ReLU activation layer is placed after each batch normalization layer; and finally, an SPPF structure with an output of 3 layers of feature maps of different resolutions.
[0023] Optionally, the specific operation process of the FPN feature pyramid network in step 3.2 is as follows:
[0024] When the three layers of feature maps of different resolutions are transmitted to the FPN feature pyramid network, bilinear interpolation is used to gradually upsample the low-resolution feature maps in the deep layer 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 used to fuse the upsampled features and the features of the backbone network. After the horizontal connection and up-sampling, the feature maps are passed through a convolution layer with a convolution kernel size of 3*3, a step of 2, and padding of 1 to obtain three different scale feature maps as the output of the feature pyramid network.
[0025] Optionally, step 3.3 specifically includes:
[0026] Using the smallest feature map: let F n be the input feature map, and use dilated convolution and SiLU activation function to obtain the intermediate feature F' n , then perform context-aware attention operation on it to obtain a new feature map F" n , finally, F" n is connected with the original feature on the channel axis, and then reduced to obtain F" n , and finally, the local features of different receptive fields are aggregated as follows:
[0027]
[0028] wherein is a connection operation, is an element multiplication on each channel, and φ represents a 1*1 convolution operation, and a corresponding local feature vector W c is the weight in the channel direction.
[0029] Optionally, the step 3.4 specifically comprises:
[0030] The sizes of the three different scale feature maps output by the feature pyramid network are cropped to 30x30, and a deformable attention is used to build a global extraction head: let be the input feature mapping level, where K reference points are allocated for each layer, and for each reference point q of each feature map, its initial normalized coordinates p in the input feature map are 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 coordinates of the initial reference point q, and Δp mlqk is the offset of the k-th sampling point of the l-th feature layer and the m-th attention head, and then the input feature map is bilinearly interpolated to obtain the corresponding sampling feature φ(x l ; d), and the formula is as follows:
[0033] A mlqk =W m ·φ(x l ; d)
[0034] Where W m is a learnable weight matrix, and φ(x l ; d) is a feature value obtained through the sampling point d;
[0035] Then the features of all sampling points are weighted and summed, and a fully connected layer is used for fusion and activation to obtain the final global feature matrix A glob , and the formula is as follows:
[0036]
[0037] Where and are learnable weight matrices, and φ represents a bilinear interpolation to calculate the interpolation feature of each reference point of the sampling offset d; represents a fully connected layer for activating the information obtained through sampling, and the global feature vector glob is obtained by pooling the matrix A
[0038] Optionally, the specific structure of the FFN feedforward neural network is as follows:
[0039] The FFN feedforward neural network comprises four fully connected layers, and the output dimensions of the four fully connected layers are 256, 128, 64 and N respectively, wherein N is a predetermined number of pig identity categories; the sizes of the weight matrices W are 256*512, 128*256, 64*128 and N*64 respectively, the sizes of the bias vectors b are 256, 128, 64 and N respectively, the first three layers use ReLU activation functions, and the output layer does not use an activation function and directly outputs a prediction result vector z; and the Softmax layer converts the output of z into a category probability distribution. The formula is as follows:
[0040]
[0041] wherein 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 maximum probability value is selected as the final prediction category of the input sample, and the specific calculation formula is as follows:
[0043]
[0044] wherein represents the final prediction category of the ith input sample.
[0045] Optionally, the step 4 specifically comprises the following steps.
[0046] Step 4.1, at the end of each training period, the loss function value L of the current period is calculated, and the change of the loss function value in multiple training periods is continuously supervised.
[0047] Step 4.2, a training period number T1 and a continuous period number T2 are set, if the change amplitude of the loss function L gradually decreases in the T2 periods and meets the following conditions, it is determined that the training has converged:
[0048]
[0049] wherein L t is the loss function value of the tth training period, and ∈ is a set change amplitude threshold.
[0050] Optionally, the loss function L is a weighted sum of a classification loss L cls and a regression loss L reg , and the calculation formula is as follows:
[0051] L=α*·Lcls + β · L reg ;
[0052] wherein a and β are weight coefficients for balancing the influence of the classification loss and the regression loss.
[0053] In another aspect, a pig face recognition system based on a dual feature perception network is provided, comprising:
[0054] A data acquisition module acquires pig face images to be detected and crops them to a uniform size, and establishes a pig face dataset based on individual identity numbers.
[0055] A dataset division module divides the pig face dataset into a training set and a test set, and performs data augmentation on the training set for model training; the test set is used to evaluate the performance of the model.
[0056] A network model construction module constructs a pig face recognition network model based on a dual feature perception network.
[0057] A model training module trains the pig face recognition network model based on the dual feature perception network using the training set, and updates the loss function value of the model using the Adam gradient descent method.
[0058] A model testing module verifies the network performance and calculates performance indicators using the test set, and saves the model weights if the performance indicators reach a specified threshold.
[0059] A result output module inputs the pig face image to be recognized into the verified pig face recognition network model based on the dual feature perception network to obtain a pig face recognition result.
[0060] According to the above technical solution, the present disclosure provides a pig face recognition method and system based on a dual feature perception network, which has the following advantages compared to the prior art:
[0061] 1. The present disclosure uses a dual feature perception network model, which effectively enhances the recognition ability of the model for pig face features by introducing a dual feature extraction mechanism, significantly improving the recognition accuracy. Compared to a single feature extraction model, the present disclosure can more comprehensively capture the subtle differences in pig faces, reducing the misidentification rate and the missed identification rate.
[0062] 2. By monitoring and adjusting the loss function during the training process, the present disclosure can identify and correct possible overfitting or underfitting problems during the training process in a timely manner, ensuring that the trained model has high stability and robustness. Especially when facing pig face images under different lighting, angles and backgrounds, the model can still maintain high recognition accuracy.
[0063] 3、The application fully considers the structural volume of the model when designing the double-feature perception network model, reduces the depth and width of the network by introducing a lightweight convolutional layer and a feature extraction module, thereby reducing the number of parameters. This structure optimization not only reduces the computational burden of the model, but also enables the model to run more efficiently in a resource-limited environment, thereby improving the recognition efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0064] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of the provided drawings.
[0065] Figure 1 A method flowchart is provided for the present application.
[0066] Figure 2 A pig face recognition network model structure diagram based on a double-feature perception network is provided for the present application. DETAILED DESCRIPTION
[0067] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0068] The present application discloses a pig face recognition method based on a double-feature perception network, as shown in Figure 1 The method comprises the following steps:
[0069] Step 1, collect the pig face images to be detected and crop them to a uniform size, and establish a pig face dataset based on individual identity numbers.
[0070] Specifically, 30 pig individual identities need to be detected, a camera facing the entrance of the pigpen is arranged in each pigpen, or a camera is arranged on a pig drinking device, and pig face images are shot under multiple angles, multiple light sources and different environments. First, the collected images are screened to exclude images that are unclear or do not show pig faces, and then the size of the images is uniformly cropped to 640x640 pixels, and the collected pig face images are numbered as {pig1, pig2, pig3,..., pig30}.
[0071] Step 2, the pig face dataset is divided into training set and test set according to the ratio of 8:2, and the training set is used for model training after data enhancement; The test set is used to evaluate the performance of the model;
[0072] Specifically, the data enhancement methods used are: random rotation, random occlusion, darkening, brightening, mirroring and adding noise.
[0073] Step 3, build a pig face recognition network model based on a double feature perception network, as shown in Figure 2 , the specific steps are as follows:
[0074] Step 3.1, build a pig face recognition model backbone network: adopt DLA deep aggregation backbone network, and sequentially connect the following structures along the input-output direction: initial convolution layer, whose convolution kernel size is 7x7, step is 1, padding is 3, and channel number is 64; Normalization layer, which normalizes the output of initial convolution layer 1; Activation layer, using ReLU activation function to introduce nonlinear features; Layer-by-layer aggregation module, containing multiple convolution layers, each convolution layer has a convolution kernel size of 3x3, a step of 1, a padding of 1, and a channel number of 64, and the outputs of each convolution layer are fused through addition operation; Convolution block 1, containing a combination of multiple convolution layers and normalization layers, wherein the convolution layer has a convolution kernel size of 3x3, a step of 1, a padding of 1, and a channel number of 128, and a ReLU activation layer is placed after each batch normalization layer; Finally, a SPPF structure, outputting 3 layers of feature maps with different resolutions;
[0075] Step 3.2, transmit the three-layer feature map to the FPN feature pyramid network, use bilinear interpolation to gradually upsample the low-resolution feature map in the deeper layer to the size of the adjacent high-resolution layer, and horizontally connect the upsampled feature map with the feature map of the same resolution from the backbone network. After each horizontal connection, a 1x1 convolution layer is used to fuse the upsampled feature and the feature of the backbone network. After horizontal connection and upsampling, the feature map is passed through a convolution layer with a convolution kernel size of 3x3, a step of 2, and a padding of 1, to obtain 3 feature maps with different scales as the output of the feature pyramid network;
[0076] Step 3.3, establish MFA multi-layer feature aggregation module to extract local features;
[0077] Use the smallest feature map: let F n be the input feature map, use dilated convolution and SiLU activation function to obtain the intermediate feature F' n , then perform context-aware attention operation on it to obtain a new feature map F" n , finally, F" n is connected with the original feature on the channel axis, and then reduced to obtain F" nThe final calculation of the local features from different receptive fields is as follows:
[0078]
[0079] in For connection operations, Element-wise multiplication on each channel, where φ represents a 1×1 convolution operation, results in a corresponding local feature vector after aggregation. W c It is the weight of the channel direction; C is the feature dimension. p C represents the number of local feature channels. g C represents the number of global feature channels. v =C g / m, where m is the number of attention heads;
[0080] Step 3.4: Establish a global extraction head to extract global features:
[0081] To reduce memory overhead, the three-layer feature map output of the feature pyramid network is cropped to 30×30 pixels. A global extraction head is constructed using deformable attention: Let... For the input feature mapping layer level, where H g and W g To extract the height and width of the global header; assign K reference points for each layer, and for each reference point q in the feature map, determine its initial normalized coordinates 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 using a deformable attention mechanism, as shown in the following formula:
[0082] d=(R l (p q )+Δp mlqk );
[0083] Where R l (p q Let q be the physical coordinate of the initial reference point, and Δp be the physical coordinate of the reference point. mlqk Let A be the offset between the l-th feature layer and the k-th sampling point of the m-th attention head. Then, bilinear interpolation is performed on the input feature map to obtain the corresponding sampling feature A. mlqk The formula is as follows:
[0084] A mlqk =W m ·φ(x l ;d);
[0085] Among them W m Let φ(x) be a learnable weight matrix.l ; d) is the feature value obtained at the sampling point d.
[0086] Then the features of all sampling points are weighted and summed up, and fused and activated through a fully connected layer to obtain the final global feature matrix A glob , as follows:
[0087]
[0088] where and are learnable weight matrices, and φ represents a bilinear interpolation to calculate the interpolated features of each reference point with sampling offset d. represents a fully connected layer for activating the information obtained by sampling, and the global feature vector glob is obtained by pooling operation on the matrix A
[0089] In this case, H g = 10, W g = 25, and K = 4.
[0090] Step 3.5, splicing the local features and global features to obtain the fused features
[0091] Step 3.6, input the spliced fused features into the FFN feedforward neural network, which includes four fully connected layers with output dimensions of 256, 128, 64, and N, respectively, where N is the predetermined number of pig identity categories; the dimensions of the weight matrix W are 256x512, 128x256, 64x128, and Nx64, respectively, and the dimensions of the bias vector b are 256, 128, 64, and N, respectively; the first three layers use ReLU activation function, and the output layer does not use activation function, directly outputting the prediction result vector z; Softmax layer: the Softmax layer converts the output of z into a category probability distribution 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 maximum probability value is selected as the final prediction category of the input sample, and the specific calculation formula is as follows:
[0095]
[0096] wherein represents the final prediction class of the i-th input sample.
[0097] Step 4, training the pig face recognition network model based on the dual feature perception network using the training set, updating the loss function value of the model by using the Adam gradient descent method, including the following steps:
[0098] Step 4.1, at the end of each training period, calculate the loss function value L of the current period, and continuously monitor the change of the loss function value in multiple training periods;
[0099] Step 4.2, set the number of training periods T1 and a continuous period number T2, if the change amplitude of the loss function L gradually decreases in these T2 periods and meets the following conditions, it is determined that the training has converged:
[0100]
[0101] wherein, L t is the loss function value of the t-th training period, and ∈ is the set change amplitude threshold;
[0102] In this embodiment, T1 = 100, T2 = 10, ∈ = 10 -4 .
[0103] Step 5, verifying the network performance and calculating the performance index by using the test set, the performance index adopts the accuracy P, the recall rate R and the average precision mAP and other parameters, and if the performance index reaches the specified threshold, the model weight is output and saved;
[0104] Step 6, inputting the pig face image to be identified into the pig face recognition network model based on the dual feature perception network verified to obtain the pig face recognition result, that is, the individual identity number of the pig.
[0105] The Adam gradient descent method in step 4 updates the model parameters θ by the following formula:
[0106]
[0107] wherein, η is the learning rate, is the bias correction estimate of the first order momentum, is the bias correction estimate of the second order momentum, and ∈ is a constant set to prevent division by zero error;
[0108] Further, the loss function L of step 4 is the weighted sum of the classification loss L cls and the regression loss L reg , and the calculation formula is as follows:
[0109] L = a · L cls+ β · L reg ;
[0110] wherein a and β are weight coefficients for balancing the influence of classification loss and regression loss;
[0111] In this case, a = 0.6, β = 0.4.
[0112] In the training process, the training set is input into the model, wherein x i is the input feature of the i-th training sample, y i is its corresponding true label, the classification loss adopts focal loss, which is defined as follows:
[0113]
[0114] wherein p t is the prediction probability of the model for the sample x i , a t and γ are adjustment parameters
[0115] The regression loss adopts smooth L1 loss, which is defined as follows:
[0116]
[0117] wherein the definition of the smooth L1 loss function smooth L1 is as follows:
[0118]
[0119] Further, the accuracy P of step 4 is the proportion of correct prediction results in all prediction results given by the model, and the calculation formula is as follows:
[0120]
[0121] wherein TP is the positive sample that the correct detection result is detected as positive by the model, and FP is the negative sample that the false detection result is detected as positive by the model;
[0122] The recall rate R represents the proportion of the correctly detected targets in the real frame, and the calculation formula is as follows:
[0123]
[0124] wherein FN is the positive sample detected as negative by the model;
[0125] The average precision mAP is calculated as follows:
[0126]
[0127] where i is the number of pig category, i = 1, 2, 3…n, AP i represents the AP value of the i-th pig, and the AP value is the area under the PR curve with precision P as the ordinate and recall R as the abscissa.
[0128] In the present 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: an initial convolution layer 1 with a convolution kernel size of 7x7, a step of 1, a padding of 3, and a channel number of 64; a maximum pooling layer with a pooling kernel size of 3x3, a step of 2, a padding of 1; a basic residual structure including two convolution layers with a convolution kernel size of 3x3, a step of 1, a padding of 1, and a channel number of 64, and a Shortcut Connection jump connection that directly adds the input to the output after two convolutions; a convolution layer 2 with a convolution kernel size of 3x3, a step of 2, a padding of 1, and a channel number of 128; a bottleneck residual structure including three convolution layers with a convolution kernel size of 3x3, a step of 1, a padding of 0, a channel number of 64, a convolution kernel size of 3x3, a step of 1, a padding of 1, a channel number of 128, a convolution kernel size of 3x3, a step of 1, a padding of 0, and a channel number of 128, and a jump connection that adds the input to the output after three convolutions; a convolution layer 3 with a convolution kernel size of 3x3, a step of 2, a padding of 1, and a channel number of 256; a split attention residual structure that divides the input feature map into multiple sub-feature maps, each of which is processed by a convolution layer with a convolution kernel size of 3x3, a step of 2, a padding of 1, and a channel number of 256, adjusts the sub-feature maps, recombines them, and adds the input to the recombined features; a convolution layer 4 with a convolution kernel size of 3x3, a step of 2, a padding of 1, and a channel number of 512; an iterative deep aggregation structure that integrates features from different layers by convolution operations with a size of 3x3, a step of 2, and a padding of 1, and finally an SPPF structure that uses different size pooling kernels for multi-scale pooling, then splices the feature maps after each pooling, and the multi-scale feature maps output by the SPPF layer are used as the output of the backbone network.
[0129] Further, in the implementation process of the present application, in order to ensure the training effect of the model, as much data as possible needs to be collected, and it is recommended that the data set be more than 30 pigs, and more than 300 photos per pig, and videos can be recorded to collect images from the videos. 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] Further, in the implementation process of the present application, in order to improve the output effect of the model, a PRN region proposal network can be added after the FFN network to generate multiple candidate regions through a sliding window and an anchor box. Each candidate region has different confidence scores and boundary box regression values, and all candidate detection boxes are filtered using the NMS non-maximum suppression algorithm. The steps of realizing non-maximum suppression are as follows: first, calculate the confidence score s of each detection box, and sort according to these scores; then, select the detection box with the highest confidence in turn and calculate its intersection over union (IoU) with other detection boxes. For the detection boxes with IoU exceeding a certain threshold, they are regarded as redundant and removed.
[0131] The present application can capture the global association between different position features through the dual feature perception architecture, significantly enhancing the model's understanding ability in complex background and multi-target scenarios. In addition, combined with the multi-layer feature aggregation module, rich context information is fused at different levels, making the model more accurate in identifying and locating different scale targets. Further, by introducing a deformable attention mechanism to weight the features, the expression ability of the feature map is improved, significantly enhancing the contribution of important features in downstream tasks. In summary, the present application innovatively designs the feature extraction and aggregation, and has wide 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] A data acquisition module acquires pig face images to be detected and crops them to a uniform size, and establishes a pig face dataset based on individual identity numbers;
[0134] A dataset division module divides the pig face dataset into a training set and a test set, and performs data augmentation on the training set for model training; the test set is used to evaluate the model performance;
[0135] A network model construction module constructs a pig face recognition network model based on a dual feature perception network;
[0136] A model training module trains the pig face recognition network model based on the dual feature perception network using the training set, and updates the loss function value of the model using the Adam gradient descent method;
[0137] A model testing module verifies the network performance and calculates performance indicators using the test set, and saves the model weights if the performance indicators reach a specified threshold;
[0138] A result output module inputs the pig face image to be recognized into the verified pig face recognition network model based on the dual feature perception network to obtain the pig face recognition result.
[0139] The various embodiments described in this specification are implemented in a progressive manner, each embodiment focusing on the differences from other embodiments, and the same or similar parts between embodiments can be mutually referred to. For the apparatus disclosed by the embodiments, since it corresponds to the method disclosed by the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method part.
[0140] The above description of disclosed embodiments enables one of ordinary skill in the art to make or use the application. Various modifications to these embodiments will be readily apparent to those of ordinary skill in the art, and the generic principles defined herein can be applied to other embodiments without departing from the spirit or scope of the application. Therefore, the application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A pig face recognition method based on a dual-feature perceptual network, characterized in that, include: Step 1: Collect images of pig faces to be detected and crop them to a uniform size. Based on individual identification numbers, establish a pig face dataset. Step 2: Divide the pig face dataset into a training set and a test set. Perform data augmentation on the training set for model training; use the test set to evaluate model performance. Step 3: Construct a pig face recognition network model based on a dual-feature perception network; Step 4: Train the pig face recognition network model based on the dual-feature perception network using the training set, and update the loss function value of the model using the Adam gradient descent method. Step 5: Verify network performance using the test set and calculate performance metrics. If the performance metrics reach the specified threshold, save the model weights. Step 6: Input the pig face image to be identified into the validated pig face recognition network model based on dual-feature perception network to obtain the pig face recognition result; Step 3 is as follows: Step 3.1: Build the backbone network of the pig face recognition model, and output it as 3 layers of feature maps with different resolutions; Step 3.2: Transmit the three layers of feature maps with different resolutions to the FPN feature pyramid network to obtain three different scale feature maps as the output of the feature pyramid network; Step 3.3: Establish an MFA multi-layer feature aggregation module to extract local features from feature maps at three different scales; Step 3.4: Use deformable attention to build a global extraction head to extract global features from feature maps of three different scales; Step 3.5: The concatenation network concatenates the extracted local and global features to obtain fused features; Step 3.6: Input the concatenated fused features into the FFN feedforward neural network to obtain the final predicted category of the input sample; Step 3.1 specifically includes: The backbone network for the pig face recognition model is constructed as follows: A Deep Aggregation Network (DLA) is used, with the following structures sequentially connected along the input-output direction: An initial convolutional layer 1 with a 7×7 kernel, a stride of 1, 3 padding, and 64 channels; a normalization layer that normalizes the output of the initial convolutional layer 1; an activation layer that introduces non-linear features using the ReLU activation function; a layer-by-layer aggregation module containing multiple convolutional layers, each with a 3×3 kernel, a stride of 1, 1 padding, and 64 channels, fusing the outputs of each convolutional layer through addition; a convolutional block containing a combination of multiple convolutional layers and normalization layers, where the convolutional layers have a 3×3 kernel, a stride of 1, 1 padding, and 128 channels, with a ReLU activation layer placed after each batch normalization layer; and finally, an SPPF structure that outputs three layers of feature maps at different resolutions. Step 3.3 specifically includes: Using the feature map with the smallest size: Let For input feature mapping, dilated convolution and Activation functions obtain intermediate features Then, a context-aware attention operation is performed on it to obtain a new feature map. ,at last, Connect the original features along the channel axis, then reduce the dimensionality to obtain Finally, the local features from different receptive fields are aggregated and calculated as follows: in For connection operations, Multiply the elements on each channel. This represents a 1×1 convolution operation, which aggregates to obtain a corresponding local feature vector. , It is the weight of the channel direction; For feature dimension, This represents the number of local feature channels; Step 4 specifically includes: Step 4.1: At the end of each training cycle, calculate the loss function value for the current cycle. Continuously monitor the changes in the loss function value over multiple training cycles; Step 4.2: Set the number of training cycles. And a consecutive number of cycles If in this If, within a given period, the value of the loss function L gradually decreases and the following condition is met, then the training is considered to have converged: ; in, For the first The loss function value for each training epoch. The threshold value for the set change range.
2. The pig face recognition method based on a dual-feature perceptual network according to claim 1, characterized in that, The specific operation process of the FPN feature pyramid network in step 3.2 is as follows: When the feature maps of three different resolutions are transmitted to the FPN feature pyramid network, bilinear interpolation is used to progressively upsample the low-resolution feature maps of the deeper layers to the size of the adjacent high-resolution layers. The upsampled feature maps are then horizontally connected with the feature maps of the same resolution from the backbone network. After each horizontal connection, a 1×1 convolutional layer is used to fuse the upsampled features with the features of the backbone network. The feature maps after horizontal connections and upsampling are then passed through a convolutional layer with a kernel size of 3×3, a stride of 2, and padding of 1 to obtain three feature maps of different scales as the output of the feature pyramid network.
3. The pig face recognition method based on a dual-feature perceptual network according to claim 1, characterized in that, Step 3.4 specifically includes: The feature maps output by the feature pyramid network at three different scales are cropped to 30×30 pixels, and a global extraction head is constructed using deformable attention: Let For the input feature mapping layer level, where , and To extract the height and width of the header globally, For feature dimension, This represents the number of global feature channels. , To account for the number of heads; K reference points are assigned to each layer, and for each feature map reference point... Determine its initial normalized coordinates in the input feature map. The sampling offset of each reference point in each layer of the feature mapping layer is dynamically calculated using a deformable attention mechanism, as shown in the following formula: ; in As the initial reference point physical coordinates For the first The first feature layer and the first The first thing to note The offset of each sampling point is then used to perform bilinear interpolation on the input feature map to obtain the corresponding sampling features. The formula is as follows: in The weight matrix is a learnable matrix. For sampling points The obtained eigenvalues; The features of all sampling points are then weighted and summed, and then fused and activated through a fully connected layer to obtain the final global feature matrix. The formula is as follows: ; in and For learnable weight matrix, Represents a bilinear interpolation to calculate the sampling offset. Interpolation features for each reference point; This represents a fully connected layer used to activate information obtained through sampling, by applying a matrix... Pooling operation is performed to obtain the global feature vector. .
4. The pig face recognition method based on a dual-feature perceptual network according to claim 1, characterized in that, The specific structure of the FFN feedforward neural network is as follows: The FFN feedforward neural network consists of four fully connected layers with output dimensions of 256, 128, 64, and N, respectively, where N is the predetermined number of pig identity categories; the weight matrix... The dimensions are: 256×512, 128×256, 64×128, and N×64, respectively, with bias vectors. The dimensions are 256, 128, 64, and N, respectively. The first three layers all use the ReLU activation function, while the output layer does not use an activation function and directly outputs the prediction result vector. ; Softmax layer: The Softmax layer will The output is transformed into a class probability distribution. The formula is as follows: ; in for The Middle The value of each output node, Number of categories; Based on the class probability distribution output by the Softmax layer, the class with the highest probability value is selected as the final predicted class for the input sample. The specific calculation formula is as follows: ; in Indicates the first The final predicted category for each input sample.
5. The pig face recognition method based on a dual-feature perceptual network according to claim 1, characterized in that, The loss function L Classification loss Regression loss The weighted sum is calculated using the following formula: ; in and is the weighting coefficient, used to balance the effects of classification loss and regression loss.
6. A pig face recognition system based on a dual-feature perceptual network, characterized in that, The pig face recognition method based on a dual-feature perceptual network according to any one of claims 1-5 includes: The data acquisition module collects images of pig faces to be detected and crops them to a uniform size. Based on individual identification numbers, a pig face dataset is established. The dataset partitioning module divides the pig face dataset into a training set and a test set. Data augmentation is performed on the training set for model training, while the test set is used to evaluate model performance. The network model construction module constructs a pig face recognition network model based on a 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 uses a test set to verify network performance and calculate performance metrics. If the performance metrics reach a specified threshold, the model weights are saved. The output module takes the pig face image to be recognized and inputs it into the validated pig face recognition network model based on a 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