A singular value decomposition-based YOLOv5 pig face recognition method

By performing singular value decomposition on the YOLOv5 backbone network, the main features of the pig face recognition model are extracted, which solves the problems of dirty environment, easy feature occlusion and difficulty in multi-angle recognition in traditional pig face recognition methods, and achieves high-precision pig face recognition results.

CN116740756BActive Publication Date: 2026-01-02HEFEI UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310531135.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-11
Publication Date
2026-01-02
Estimated Expiration
2043-05-11

AI Technical Summary

Technical Problem

Traditional pig face recognition methods struggle to achieve high-precision and multi-angle pig face recognition due to issues such as dirty and messy living environments for pigs, easily obscured facial features, minimal differences in pig faces, and difficulty in multi-angle recognition.

Method used

A YOLOv5 pig face recognition method based on singular value decomposition is adopted. By performing singular value decomposition on the output of the backbone network, the main features are extracted, and a YOLOv5 model based on singular value decomposition is built, including a backbone network, singular value decomposition fusion, feature fusion network and detection head, for training and recognition of pig face images.

Benefits of technology

It improves the classification ability of pig face recognition, achieves high-precision pig face recognition, especially performs well in pig side face and multi-angle recognition, and has good generalization performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116740756B_ABST
    Figure CN116740756B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of YOLOv5 pig face recognition method based on singular value decomposition, belong to computer vision field.The method is trained by the singular value decomposition YOLOv5 model built by training set multiple iterations training, then the highest accuracy of validation set is obtained Corresponding optimal pig face recognition model, then it is used to the pig face image to be identified for pig face recognition.The method of the present application considers that YOLOv5 main network is for the feature extraction of full image, directly applied to pig face fine-grained recognition, it is difficult to realize effective classification, the present application proposes to carry out singular value decomposition after YOLOv5 main network, extract important features in feature map, ignore secondary features, realize pig face high-precision classification.The method of the present application has good generalization performance, and has a better effect for pig side face and multi-angle recognition.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of image processing, in particular to a YOLOv5 pig face recognition method based on singular value decomposition. BACKGROUND

[0002] With the rapid development of large-scale pig farming, how to use pig face recognition technology to identify individual pigs has attracted more and more attention. Using pig face recognition technology can quickly find sick pigs, prevent the spread of swine fever and reduce property losses. In addition, combining pig face recognition technology with pig behavior detection methods can achieve precise feeding. Therefore, pig face recognition technology has important research significance for pig breeding and intelligent management.

[0003] Traditional pig individual identification methods mainly include wearing radio frequency identification ear tags and using pig body digital auxiliary tags. However, these methods have many problems that are difficult to solve in practical application. For example, although the pig body digital auxiliary tag is relatively intuitive, it is limited to the use of a small number of pigs and has the problem of fading. Radio frequency identification ear tags can cause stress reactions in pigs and are also easily disturbed by the frequency range.

[0004] In recent years, with the continuous development of deep learning technology in the field of computer vision, some research has begun to explore the application of deep learning technology to pig face recognition. However, due to the living environment of pigs and their unique characteristics, pig face recognition has the following difficulties.

[0005] 1. The living environment of pigs is usually dirty, which makes the pig face features easy to be blocked by other objects, increasing the difficulty of pig face recognition.

[0006] 2. Pig face recognition belongs to fine-grained recognition, and the differences between different pig faces are not big, so the extracted pig face features are similar and easy to misclassify.

[0007] 3. In real life, pig faces are usually presented at multiple angles, so the pig face recognition model is required to be able to recognize multiple angle pig faces, and the features contained in the side face are obviously less than those in the front face. Therefore, multi-angle pig face recognition is more stringent on the feature extraction ability of the model. SUMMARY

[0008] In order to overcome the shortcomings of the above technology, the present application provides a YOLOv5 pig face recognition method based on singular value decomposition, which obtains main features by singular value decomposition of the output of the main network, improves the feature extraction ability of the model, and further improves the classification ability of the model for pig faces.

[0009] The technical scheme adopted by the present application is:

[0010] A singular value decomposition-based YOLOv5 pig face recognition method, comprising training a singular value decomposition-based YOLOv5 model to obtain a pig face recognition model with optimal recognition effect through pig face images collected, and realizing pig face recognition by using the optimal pig face recognition model, specifically comprising the following steps:

[0011] Step 1, constructing a training set and a validation set for pig face recognition

[0012] Collect N-class pig face images, where N represents the number of pig face image classes;

[0013] Randomly select K pig face images in each class of the N-class pig face images, obtain N×K pig face images, then perform image enhancement on the N×K pig face images by using D data enhancement methods, and retain the pig face images obtained by each data enhancement method, i.e., a total of N×K×(D+1) pig face images are obtained, and the N×K×(D+1) pig face images are combined to form a training set;

[0014] Randomly select S images in each class of the N-class pig face images, obtain N×S pig face images, then perform image enhancement on the N×S pig face images by using D data enhancement methods, and retain the pig face images obtained by each data enhancement method, i.e., a total of N×S×(D+1) pig face images are obtained, and the N×S×(D+1) pig face images are combined to form a validation set, K≠S;

[0015] Step 2, building a singular value decomposition-based YOLOv5 model

[0016] The singular value decomposition-based YOLOv5 model comprises a backbone network, singular value decomposition fusion, a feature fusion network, and a detection head, and the specific steps are as follows:

[0017] Step 2.1, building a backbone network of the singular value decomposition-based YOLOv5 model

[0018] The backbone network comprises the following structures connected in series along the input-output direction of the backbone network: a convolution layer α1 with a convolution kernel size of 6×6, a stride of 2, a padding of 2, and a channel number of 64, a convolution layer α2 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 128, a residual structure χ1 with a C3 module repeated 3 times, a convolution layer α3 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 256, a residual structure χ2 with a C3 module repeated 6 times, a convolution layer α4 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 512, a residual structure χ3 with a C3 module repeated 9 times, a convolution layer α5 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 1024, a residual structure χ4 with a C3 module repeated 3 times, and an SPPF structure;

[0019] The output of the backbone network is the output of the SPPF structure, denoted as χ of the backbone network;

[0020] Step 2.2, build singular value decomposition fusion of the singular value decomposition YOLOv5 model

[0021] The singular value decomposition of the output χ of the backbone network is χ = U1∑1V1 T , where U1 is the left singular eigenvector, ∑1 is the singular value matrix, V1 T is the right singular eigenvector;

[0022] The singular value matrix ∑1 is arranged in descending order according to the singular value size, and the left singular eigenvector U1 and the right singular eigenvector V1 T are arranged according to the arrangement order of the singular value matrix ∑1, to obtain a reordered singular value matrix ∑2, a reordered left singular eigenvector U2 and a reordered right singular eigenvector V2 T ;

[0023] The first L singular value components of the reordered singular value matrix ∑2 form a partial singular value matrix ∑3, the first L eigenvectors of the reordered left singular eigenvector U2 form a partial left singular eigenvector U3, and the first L eigenvectors of the reordered right singular eigenvector V2 T form a partial right singular eigenvector V3 T , and η = U3∑3V3 T , η is the feature map after singular value decomposition;

[0024] The output χ of the backbone network of the YOLOv5 model and the feature map η after singular value decomposition are additively fused, and the expression is φ = χ + η, where φ is the output of the singular value decomposition fusion;

[0025] Step 2.3, build feature fusion network of singular value decomposition YOLOv5 model

[0026] The feature fusion network comprises the following structures connected in series along the input-output direction of the feature fusion network: a convolution layer a6 with a convolution kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 512, an up-sampling layer t1, a residual structure x5 of a C3 module repeated for 3 times, a convolution layer a7 with a convolution kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 256, an up-sampling layer t2, a residual structure x6 of a C3 module repeated for 3 times, a convolution layer a8 with a convolution kernel size of 3*3, a stride of 2, padding of 0 and a channel number of 256, a residual structure x7 of a C3 module repeated for 3 times, a convolution layer a9 with a convolution kernel size of 3*3, a stride of 2, padding of 0 and a channel number of 512 and a residual structure x8 of a C3 module repeated for 3 times;

[0027] Step 2.4, building a detection head of the singular value decomposition YOLOv5 model

[0028] The detection head comprises the following structures: a convolution layer a 10 with a kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 3*(N+5), a convolution layer a 11 with a kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 3*(N+5), a convolution layer a 12 with a kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 3*(N+5), wherein the input of the convolution layer a 10 connects the output of the residual structure x6, the input of the convolution layer a 11 connects the output of the residual structure x7, and the input of the convolution layer a 12 connects the output of the residual structure x8.

[0029] Step 3, training the singular value decomposition YOLOv5 model to obtain an optimal pig face recognition model

[0030] Suppose G rounds of training are performed, and any one of them is recorded as the E round, E = 1, 2,..., G, and the specific steps of the E round of training are as follows:

[0031] Step 3.1, feeding the pig face images in the training set into the singular value decomposition YOLOv5 model for iterative training by batches;

[0032] Step 3.1.1, randomly selecting A pig face images in the training set and feeding them into the singular value decomposition YOLOv5 model to obtain the bounding box information bbox, the class information c and the target confidence information obj predicted by the singular value decomposition YOLOv5 model, bbox = {bbox1, bbox2,..., bbox A}, c = {c1, c2,..., c A}, obj = {obj1, obj2,..., obj A};

[0033] Let the real boundary box information corresponding to the A pig face image be bbox GT = {bbox1 GT , bbox2 GT ,..., bbox A GT}, the real class information be c t = {c1 t , c2 t ,..., c A t}, and the real target confidence information be obj t = {l1, l2,..., l A};

[0034] Step 3.1.2, calculate the boundary box information loss lbox, the class information loss lcls, and the target confidence information loss lobj, whose calculation formulas are respectively:

[0035] lbox = CIoU(bbox, bbox GT )

[0036] lcls = BCE(c, c t )

[0037] lobj = BCE(obj, obj t )

[0038] Where CIoU() is a loss function, and BCE() is a binary cross-entropy loss function.

[0039] Step 3.1.3, optimize the boundary box information loss lbox, the class information loss lcls, and the target confidence information loss lobj through the stochastic gradient descent algorithm, and update the singular value decomposition YOLOv5 model weight through backpropagation, to complete the training of the A pig face image.

[0040] Step 3.1.4, repeat steps 3.1.1 to 3.1.3 until all pig face images in the training set are trained, then the E round of training is completed.

[0041] The singular value decomposition YOLOv5 model trained through steps 3.1.1 to 3.1.4 is called the singular value decomposition YOLOv5 model of the E round, and is denoted as model M E .

[0042] Step 3.2, calculate the mAP index of the validation set using the model M E trained in step 3.1.

[0043] Step 3.3, G times repeat step 3.1 and step 3.2, to obtain a model set M and a set of mAP indicators O, M = [M1, M2,..., M E ,...M G ], O = [mAP1, Map2,..., mAP E ,...mAP G ], the maximum mAP indicator value in the set of mAP indicators O is recorded as mAP max , and the model corresponding to the position of mAP max is the optimal pig face recognition model;

[0044] Step 4, using the optimal pig face recognition model to recognize pig face

[0045] Step 4.1, sending the pig face image to be recognized into the optimal pig face recognition model, and the optimal pig face recognition model outputs the predicted bounding box information, the predicted class information and the predicted target confidence information;

[0046] Step 4.2, using the non-maximum suppression technique to filter the predicted bounding box information, the predicted class information and the predicted target confidence information output by the optimal pig face recognition model in step 4.1, and removing the redundant bounding box information;

[0047] Step 4.3, using the remaining predicted bounding box information in step 4.2 to mark the pig face position in the pig face image to be recognized, and using the predicted class information and the predicted target confidence information to mark the pig face class and the target confidence.

[0048] Preferably, the calculation formula of the mAP indicator in step 3.2 is as follows:

[0049]

[0050] Wherein, z is the serial number of pig face class, z = 1, 2,..., N, AP z represents the value of AP of the zth pig, and the AP is the area under the p-r curve with precision p as the ordinate and recall r as the abscissa, p(r) is the precision value of the p-r curve when the recall is r, wherein the definitions of the precision p and the recall r are as follows:

[0051]

[0052]

[0053] In the formula, TP is the number of correctly classified predicted bounding boxes of the model M E , FP is the number of false predicted bounding boxes of the model M EThe number of prediction bounding boxes that are misclassified, FN for model M E The number of bounding boxes that are not predicted.

[0054] Compared with the prior art, the present application has the following advantages:

[0055] 1. The present application considers that the YOLOv5 backbone network is for feature extraction on the full image, and is directly applied to pig face fine-grained recognition, which is difficult to realize effective classification. The present application proposes to perform singular value decomposition after the YOLOv5 backbone network to extract important features in the feature map and ignore secondary features, thereby realizing high-precision classification of pig faces.

[0056] 2. The singular value decomposition YOLOv5 model proposed by the present application has good generalization performance, and not only has a good effect on pig front face recognition, but also has a good effect on pig side face and multi-angle recognition. BRIEF DESCRIPTION OF DRAWINGS

[0057] Figure 1 is a flowchart of the pig face recognition method of the present application;

[0058] Figure 2 is a model structure diagram of the pig face recognition method of the present application. DETAILED DESCRIPTION

[0059] The technical solutions of the present application will be described in detail below in combination with the drawings and specific embodiments.

[0060] Figure 1 is a flowchart of the pig face recognition method of the present application, Figure 2 is a model structure diagram of the pig face recognition method of the present application, which comprises Figure 1 and Figure 2 It can be seen that the present application provides a singular value decomposition-based YOLOv5 pig face recognition method, which comprises training a singular value decomposition YOLOv5 model from collected pig face images to obtain a pig face recognition model with optimal recognition effect, and using the optimal pig face recognition model to realize pig face recognition, and specifically comprising the following steps:

[0061] Step 1, constructing a training set and a validation set for pig face recognition

[0062] Collecting N-class pig face images, wherein N represents the number of pig face image classes;

[0063] Randomly selecting K pig face images in each class of the N-class pig face images, obtaining N×K pig face images, then performing image enhancement on the N×K pig face images using D kinds of data enhancement methods, and retaining the pig face images obtained by each kind of data enhancement method, i.e. obtaining a total of N×K×(D+1) pig face images, and grouping the N×K×(D+1) pig face images into a training set;

[0064] In each class of the N-class pig face image, S images are randomly selected again, N*S pig face images are obtained, and the N*S pig face images are enhanced by D data enhancement methods, and the pig face images obtained by each data enhancement method are retained, that is, N*S*(D+1) pig face images are obtained, and the N*S*(D+1) pig face images are used to form a verification set, K≠S.

[0065] In this example, N=30, K=20, D=9, and S=10.

[0066] In this example, the D data enhancement methods specifically include horizontal flipping, 10-degree rotation, 20-degree rotation, image sharpening, Gaussian blur, contrast enhancement, contrast reduction, brightness enhancement, and brightness reduction.

[0067] Step 2, build a singular value decomposition YOLOv5 model

[0068] The singular value decomposition YOLOv5 model includes a backbone network, singular value decomposition fusion, a feature fusion network, and a detection head, and the specific steps are as follows:

[0069] Step 2.1, build a backbone network of the singular value decomposition YOLOv5 model

[0070] The backbone network includes the following structures connected in series along the input-output direction of the backbone network: a convolution layer a1 with a convolution kernel size of 6*6, a stride of 2, a padding of 2, and a channel number of 64, a convolution layer a2 with a convolution kernel size of 3*3, a stride of 2, a padding of 0, and a channel number of 128, a residual structure x1 with a C3 module repeated 3 times, a convolution layer a3 with a convolution kernel size of 3*3, a stride of 2, a padding of 0, and a channel number of 256, a residual structure x2 with a C3 module repeated 6 times, a convolution layer a4 with a convolution kernel size of 3*3, a stride of 2, a padding of 0, and a channel number of 512, a residual structure x3 with a C3 module repeated 9 times, a convolution layer a5 with a convolution kernel size of 3*3, a stride of 2, a padding of 0, and a channel number of 1024, a residual structure x4 with a C3 module repeated 3 times, and an SPPF structure.

[0071] The output of the backbone network is the output of the SPPF structure, which is denoted as the output x of the backbone network.

[0072] In this embodiment, the C3 module includes convolution layers b1, b2, and b3 connected in series, wherein the input of the C3 module is denoted as g, the output of the convolution layer b2 is denoted as m, g passes through the convolution layers b1 and b2 in sequence, and then g and m are concatenated to form the input of the convolution layer b3.

[0073] In the embodiment, the SPPF structure comprises a pooling layer θ1, a pooling layer θ2 and a pooling layer θ3 connected in series, the input of the SPPF structure is denoted as ε, the output of the pooling layer θ1 is denoted as the output of the pooling layer θ2 is denoted as the output of the pooling layer θ3 is denoted as the output of the SPPF structure is denoted as ε, concat fusion. The pooling layer θ1, the pooling layer θ2 and the pooling layer θ3 have the same structure, specifically, the pooling kernel size is 5x5, the stride is 1 and the padding is 2.

[0074] Step 2.2, building the singular value decomposition fusion of the singular value decomposition YOLOv5 model

[0075] The output χ of the backbone network is subjected to singular value decomposition, and the expression is χ = U1∑1V1 T , wherein U1 is a left singular feature vector, ∑1 is a singular value matrix, V1 T is a right singular feature vector;

[0076] The singular value matrix ∑1 is arranged in descending order of singular value, and the left singular feature vector U1 and the right singular feature vector V1 T are arranged in the order of the singular value matrix ∑1, to obtain a reordered singular value matrix ∑2, a reordered left singular feature vector U2 and a reordered right singular feature vector V2 T ;

[0077] The first L singular value components of the reordered singular value matrix ∑2 form a partial singular value matrix ∑3, the first L feature vectors of the reordered left singular feature vector U2 form a partial left singular feature vector U3, and the first L feature vectors of the reordered right singular feature vector V2 T form a partial right singular feature vector V3 T , and η = U3∑3V3 T , η is a feature map subjected to singular value decomposition;

[0078] The output χ of the backbone network of the YOLOv5 model is subjected to additive fusion with the feature map η subjected to singular value decomposition, and the expression is φ = χ + η, wherein φ is the output of the singular value decomposition fusion.

[0079] Step 2.3, building the feature fusion network of the singular value decomposition YOLOv5 model

[0080] The feature fusion network comprises the following structures connected in series along the input-output direction of the feature fusion network: a convolution layer a6 with a convolution kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 512, an up-sampling layer t1, a residual structure x5 repeated 3 times C3 module, a convolution layer a7 with a convolution kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 256, an up-sampling layer t2, a residual structure x6 repeated 3 times C3 module, a convolution layer a8 with a convolution kernel size of 3*3, a stride of 2, padding of 0 and a channel number of 256, a residual structure x7 repeated 3 times C3 module, a convolution layer a9 with a convolution kernel size of 3*3, a stride of 2, padding of 0 and a channel number of 512 and a residual structure x8 repeated 3 times C3 module.

[0081] Step 2.4, building the detection head of the singular value decomposition YOLOv5 model

[0082] The detection head comprises the following structures: a convolution layer a 10 with a kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 3*(N+5), a convolution layer a 11 with a kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 3*(N+5), and a convolution layer with a kernel size of 1*1, a stride of 1, padding of 0 and a channel number of 3*(N+5), wherein the input of the convolution layer a 10 connects the output of the residual structure x6, the input of the convolution layer a 11 connects the output of the residual structure x7, and the input of the convolution layer a 12 connects the output of the residual structure x8.

[0083] The output of the convolution layer a 10 , the output of the convolution layer a 11 and the output of the convolution layer a 12 are the outputs of the detection head, that is, the outputs of the singular value decomposition YOLOv5 model. Figure 2 It can be seen that the three outputs are information boxes, categories and confidence levels respectively.

[0084] Step 3, training the singular value decomposition YOLOv5 model to obtain an optimal pig face recognition model

[0085] Suppose G rounds of training are performed, and any one of them is recorded as the E round, E = 1, 2,..., G, and the specific steps of the E round of training are as follows:

[0086] Step 3.1, feeding the pig face images in the training set into the singular value decomposition YOLOv5 model for iterative training by batches;

[0087] Step 3.1.1, randomly select A pig face images in the training set and input them into the singular value decomposition YOLOv5 model to obtain the bounding box information bbox, class information c and target confidence information obj predicted by the singular value decomposition YOLOv5 model, bbox = {bbox1, bbox2, …, bbox A}, c = {c1, c2, …, c A}, obj = {obj1, obj2, …, obj A};

[0088] Let the real bounding box information corresponding to the A pig face images be bbox GT = {bbox1 GT , bbox2 GT , …, bbox A GT}, the real class information be c t = {c1 t , c2 t , …, c A t}, and the real target confidence information be obj t = {l1, l2, …, l A}.

[0089] Step 3.1.2, calculate the bounding box information loss lbox, the class information loss lcls and the target confidence information loss lobj, whose calculation formulas are respectively:

[0090] lbox = CIoU(bbox, bbox GT )

[0091] lcls = BCE(c, c t )

[0092] lobj = BCE(obj, obj t )

[0093] Where CIoU() is a loss function, and BCE() is a binary cross-entropy loss function.

[0094] Step 3.1.3, optimize the bounding box information loss lbox, the class information loss lcls and the target confidence information loss lobj through the stochastic gradient descent algorithm, and update the singular value decomposition YOLOv5 model weight through back propagation, and complete the training of the A pig face images.

[0095] Step 3.1.4, repeat steps 3.1.1 to 3.1.3 until all pig face images in the training set are trained, then the Eth training is completed.

[0096] The YOLOv5 model trained through steps 3.1.1 to 3.1.4 is referred to as a singular value decomposed YOLOv5 model of the E-th round, and is denoted as model M E .

[0097] Step 3.2, using the model M trained in step 3.1 E The mAP index is calculated for the validation set.

[0098] In this embodiment, the calculation formula of the mAP index is as follows:

[0099]

[0100] wherein z is the serial number of the pig face class, z = 1, 2,..., N, AP z represents the value of the AP of the z-th pig, the AP is the area under the p-r curve with precision p as the ordinate and recall r as the abscissa, p(r) is the precision value on the p-r curve when the recall is r, wherein the definitions of the precision p and the recall r are as follows:

[0101]

[0102]

[0103] wherein TP is the number of prediction bounding boxes correctly classified by the model M E , FP is the number of prediction bounding boxes incorrectly classified by the model M E , FN is the number of prediction bounding boxes not predicted by the model M E .

[0104] Step 3.3, repeating steps 3.1 and 3.2 G times to obtain a model set M and a set O of mAP indexes, M = [M1, M2,..., ME,..., M G ], O = [mAP1, Map2,..., mAP E ,... mAP G ], the maximum mAP index value in the set O of mAP indexes is denoted as mAP max , and the model corresponding to the position of mAP max is the optimal pig face recognition model.

[0105] In this example, G = 150.

[0106] Step 4, using the optimal pig face recognition model to recognize pig faces

[0107] Step 4.1, sending the pig face image to be identified into the optimal pig face recognition model, and the optimal pig face recognition model outputs prediction bounding box information, prediction class information and prediction target confidence information;

[0108] Step 4.2, filtering the prediction bounding box information, prediction class information and prediction target confidence information output by the optimal pig face recognition model in step 4.1 by using the non-maximum suppression technique, and removing redundant bounding box information;

[0109] Step 4.3, marking the pig face position in the pig face image to be identified by using the remaining prediction bounding box information in step 4.2, and marking the pig face class and target confidence by using the prediction class information and prediction target confidence information.

[0110] The following table is the precision comparison result of the model of the present application and the improved YOLOv5 model, and the pig face recognition belongs to fine-grained recognition, which is difficult to recognize. The results show that the accuracy, recall rate and mAP indicators of the model of the present application are still significantly improved, which shows that the pig face recognition method proposed in the present application is effective.

[0111] Model Precision (%) Recall (%) mAP (%) YOLOv5 91.342 86.682 92.558 Inventive model 92.578 87.451 93.265

Claims

1. A YOLOv5 pig face recognition method based on singular value decomposition, characterized in that, The pig face recognition model with the optimal recognition effect is obtained by training the collected pig face images through the singular value decomposition YOLOv5 model, and the pig face recognition is realized by using the optimal pig face recognition model, which specifically includes the following steps. Step 1, constructing a training set and a validation set for pig face recognition Collect N pig face images, where N represents the number of pig face image categories; Randomly select K pig face images in each category of the N pig face images, obtain N×K pig face images, then perform image enhancement on the N×K pig face images using D data enhancement methods, and retain the pig face images obtained by each data enhancement method, that is, a total of N×K×(D+1) pig face images are obtained, and the N×K×(D+1) pig face images are combined to form a training set; Randomly select S images in each category of the N pig face images, obtain N×S pig face images, then perform image enhancement on the N×S pig face images using D data enhancement methods, and retain the pig face images obtained by each data enhancement method, that is, a total of N×S×(D+1) pig face images are obtained, and the N×S×(D+1) pig face images are combined to form a validation set, K≠S; Step 2, building a singular value decomposition-based YOLOv5 model The singular value decomposition-based YOLOv5 model includes a backbone network, a singular value decomposition fusion, a feature fusion network, and a detection head, and the specific steps are as follows: Step 2.1, building a singular value decomposition-based YOLOv5 model backbone network The backbone network includes the following structures connected in series along the input-output direction of the backbone network: a convolution layer α1 with a convolution kernel size of 6×6, a stride of 2, a padding of 2, and a channel number of 64, a convolution layer α2 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 128, a residual structure χ1 with a C3 module repeated 3 times, a convolution layer α3 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 256, a residual structure χ2 with a C3 module repeated 6 times, a convolution layer α4 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 512, a residual structure χ3 with a C3 module repeated 9 times, a convolution layer α5 with a convolution kernel size of 3×3, a stride of 2, a padding of 0, and a channel number of 1024, a residual structure χ4 with a C3 module repeated 3 times, and an SPPF structure; The output of the backbone network is the output of the SPPF structure, which is denoted as the output χ of the backbone network; Step 2.2, building a singular value decomposition fusion of the singular value decomposition-based YOLOv5 model The output χ of the backbone network is singular value decomposed, expressed as χ = U1∑1V1 T where U1is the left singular eigenvector, ∑1is the singular value matrix, and V1 T is the right singular eigenvector. The singular value matrix ∑1 is arranged in descending order of singular value, and the left singular characteristic vector U1 and the right singular characteristic vector V1 T The singular value matrix ∑1 is arranged in descending order of singular value, and the left singular characteristic vector U1 and the right singular characteristic vector V1 T ; The first L singular values of the reordered singular value matrix ∑2 are selected to form a partial singular value matrix ∑3, the first L eigenvectors of the reordered left singular eigenvector U2 are selected to form a partial left singular eigenvector U3, and the first L eigenvectors of the reordered right singular eigenvector V2 are selected to form a partial right singular eigenvector V3 T The first L singular values of the reordered singular value matrix ∑2 are selected to form a partial singular value matrix ∑3, the first L eigenvectors of the reordered left singular eigenvector U2 are selected to form a partial left singular eigenvector U3, and the first L eigenvectors of the reordered right singular eigenvector V2 are selected to form a partial right singular eigenvector V3 T , and η = U3∑3V3 T η is a feature map after singular value decomposition; The output χ of the backbone network of the YOLOv5 model is added to the feature map η obtained by singular value decomposition, and the expression is φ=χ+η, where φ is the output of the singular value decomposition fusion; Step 2.3, building a feature fusion network of the singular value decomposition-based YOLOv5 model The feature fusion network comprises the following structures connected in series along the input-output direction of the feature fusion network: a convolution layer α6 with a convolution kernel size of 1*1, a step distance of 1, a padding of 0 and a channel number of 512, an upsampling layer τ1, a residual structure χ5 of a C3 module repeated for 3 times, a convolution layer α7 with a convolution kernel size of 1*1, a step distance of 1, a padding of 0 and a channel number of 256, an upsampling layer τ2, a residual structure χ6 of a C3 module repeated for 3 times, a convolution layer α8 with a convolution kernel size of 3*3, a step distance of 2, a padding of 0 and a channel number of 256, a residual structure χ7 of a C3 module repeated for 3 times, a convolution layer α9 with a convolution kernel size of 3*3, a step distance of 2, a padding of 0 and a channel number of 512, and a residual structure χ8 of a C3 module repeated for 3 times; Step 2.4, building a detection head of the singular value decomposition YOLOv5 model The detection head comprises the following structures: a convolution layer α with a kernel size of 1*1, a step distance of 1, padding of 0, and a channel number of 3*(N+5) 10 , a convolution layer α with a kernel size of 1*1, a step distance of 1, padding of 0, and a channel number of 3*(N+5) 10 , a convolution layer α with a kernel size of 1*1, a step distance of 1, padding of 0, and a channel number of 3*(N+5) 12 , wherein the input of the convolution layer α 10 connects the output of the residual structure χ6, the input of the convolution layer α 11 connects the output of the residual structure χ7, and the input of the convolution layer α 12 connects the output of the residual structure χ8. Step 3, training the singular value decomposition YOLOv5 model to obtain an optimal pig face recognition model Suppose that G rounds of training are performed, and any one of them is recorded as the E round, E = 1, 2,..., G, and the specific steps of the E round of training are as follows: Step 3.1, feeding the pig face images in the training set into the singular value decomposition YOLOv5 model for iterative training by batches; Step 3.1.1: Randomly select A pig face images from the training set and input them into the YOLOv5 model with singular value decomposition to obtain the bounding box information bbox, class information c, and target confidence information obj predicted by the YOLOv5 model with singular value decomposition, where bbox = {bbox1, bbox2, ..., bbox}. A }, c = {c1, c2, ..., c A }, obj={obj1, obj2,..., obj A }; The real boundary box information corresponding to the A recorded pig face image is bbox GT ={bbox1 GT ,bbox2 GT ,...,bbox A GT}, the real category information is c t ={c1 t ,c2 t ,...,c A t}, and the real target confidence information is obj t ={l1,l2,...,l A}. Step 3.1.2, calculating the bounding box information loss lbox, the class information loss lcls and the target confidence information loss lobj, and the calculation formulas are as follows: lbox = CIoU ( bbox, bbox GT ) lcls = BCE(c, c t ) lobj = BCE (obj, obj t ) Where CIoU() is a loss function, and BCE() is a binary cross-entropy loss function; Step 3.1.3, optimizing the bounding box information loss lbox, the class information loss lcls and the target confidence information loss lobj by a stochastic gradient descent algorithm, and updating the singular value decomposition YOLOv5 model weight through back propagation to complete the training of the A pig face images; Step 3.1.4, repeating steps 3.1.1 to 3.1.3 until all pig face images in the training set are trained, and then the E round of training is completed; The YOLOv5 model trained by steps 3.1.1 to 3.1.4 is referred to as the singular value decomposed YOLOv5 model of the E-th round, and is denoted as model M E ; Step 3.2, calculate the mAP index of the validation set by using the trained model M in step 3.1 E calculate the mAP index of the validation set. Step 3.3, G times repeat step 3.1 and step 3.2, to obtain a model set M and a set O of mAP indicators, M = [M1, M2,..., M E ] G , O = [mAP1, mAP2,..., mAP E ] G , the maximum mAP indicator value in the set O of mAP indicators is recorded as mAP max , and the model corresponding to the position of mAP max is the optimal pig face recognition model; Step 4, recognizing pig faces by using the optimal pig face recognition model Step 4.1, feeding the pig face image to be recognized into the optimal pig face recognition model, and the optimal pig face recognition model outputs the predicted bounding box information, the predicted class information and the predicted target confidence information; Step 4.2, filtering the predicted bounding box information, the predicted class information and the predicted target confidence information output by the optimal pig face recognition model in step 4.1 by using a non-maximum suppression technique to remove redundant bounding box information; Step 4.3, marking the pig face position in the pig face image to be recognized by using the remaining predicted bounding box information in step 4.2, and marking the pig face class and the target confidence by using the predicted class information and the predicted target confidence information.

2. The singular value decomposition-based YOLOv5 pig face recognition method according to claim 1, characterized in that, The calculation formula of the mAP index in step 3.2 is as follows: where z is the serial number of the pig face category, z = 1, 2,..., N, AP z represents the value of the AP of the zth category of pigs, the AP being the area under the p-r curve plotted with the precision p as the ordinate and the recall r as the abscissa, p(r) is the precision value on the p-r curve when the recall is r, where the precision p and the recall r are defined as follows, respectively: where TP is the number of correctly classified prediction bounding boxes for model M E the number of prediction bounding boxes that are correctly classified, FP is the number of prediction bounding boxes that are incorrectly classified for model M E the number of prediction bounding boxes that are incorrectly classified, FN is the number of prediction bounding boxes that are not predicted for model M E the number of prediction bounding boxes that are not predicted.

Citation Information

Patent Citations

  • Few-sample target detection method based on singular value decomposition feature enhancement

    CN113971815A

  • Object pose detection method and apparatus, computer device, and storage medium

    WO2023015409A1