A target recognition and detection method based on improved YOLOv5
By improving YOLOv5's target recognition detection method, the K-Means clustering algorithm and BiFPN feature fusion is used to solve the problem of insufficient recognition accuracy in pig individuals, and the recognition performance in dense and long-distance small target recognition environments is improved.
Patent Information
- Application Number
- CN202210240265.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-10
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-03-10
AI Technical Summary
The existing pig individual recognition technology needs to improve its accuracy, especially in the identification of pig dense and long-distance small targets. Traditional methods have problems with mark shedding, infection and high costs.
Based on the improved YOLOv5 target recognition detection method, the K-Means clustering algorithm is used to improve the target anchor box, and a coordinated attention mechanism and BiFPN are introduced for feature fusion to improve the model's recognition performance in small-objective and multi-interference environments.
It improves the accuracy of pig individual recognition, especially in dense and long-distance small-object recognition environments, and improves the adaptability and multi-scale learning capabilities of the model.
Smart Images

Figure CN114627502B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of target detection, and in particular relates to a target recognition and detection method based on improved YOLOv5. Background Art
[0002] With the development of modern breeding industry, pig production management is becoming more welfare-oriented, systematic and intelligent, and accurate identification of individual pigs is an important part of it. Traditional methods of individual pig identification mainly include painting, branding, ear tags, radio frequency identification (RFID) and so on. Among them, painting, branding and ear tags have problems such as tag shedding and infection, which are not conducive to pig production management. Radio frequency identification is costly and the signal is easily interfered by metal substances.
[0003] With the development of machine learning in recent years, the contemporary breeding industry has gradually adopted neural networks for non-invasive identification of individual pigs. Among them, the neural networks applied to pig face recognition are mainly: Marsort et al. built an adaptive pig face recognition method based on convolutional neural networks, with an accuracy rate of 83%; He Yutong et al. proposed pig face recognition based on improved YOLOv3, with an accuracy rate of 90.12%; Hansen et al. proposed a CNN model based on convolution, maximum pooling and dense connection structures, which improved the pig face recognition effect. Yan Hongwen et al. proposed a pig face posture recognition method based on the improved Tiny-YOLO model, with an accuracy rate of 82.38%; Eric T.Psota et al. built a fully convolutional neural network for instance segmentation of pigs, with an accuracy rate of 91%. These non-invasive methods reflect the welfare of pig production, but the recognition accuracy needs to be further improved.
[0004] Therefore, the present invention proposes a target recognition and detection method based on improved YOLOv5. Summary of the invention
[0005] In order to overcome the above-mentioned shortcomings of the prior art, the present invention provides a target recognition and detection method based on improved YOLOv5.
[0006] In order to achieve the above object, the present invention provides the following technical solutions:
[0007] A target recognition and detection method based on improved YOLOv5 includes the following steps:
[0008] Collect target image sample data and build a sample data set;
[0009] Expand the sample data set to obtain the data set to be identified;
[0010] The target detection algorithm YOLOv5 is improved to obtain the improved target detection algorithm YOLOv5, which specifically includes:
[0011] The Euclidean distance of the K-Means dimensional clustering algorithm K-Means was changed to 1-IOU, the K-Means algorithm was used to determine the prior anchor box, and the target anchor box of the target detection algorithm YOLOv5 was optimized;
[0012] Introducing the coordinated attention mechanism CA into the backbone network of the target detection algorithm YOLOv5;
[0013] BiFPN is used to improve the bidirectional cross-scale connection of the target detection algorithm YOLOv5, and weighted feature fusion is performed to obtain the improved target detection algorithm YOLOv5;
[0014] The improved target detection algorithm YOLOv5 is used to identify the image information in the dataset to be identified and obtain the recognition result.
[0015] Preferably, the collecting target image sample data specifically includes: controlling the camera to rotate through a remote control system to achieve time-sharing collection and obtain image sample data containing different features.
[0016] Preferably, the expansion process of the sample data set includes the following steps:
[0017] The sample data set is randomly cropped, randomly offset, and Mosaic data augmented. The image is manually labeled and labeled using the image annotation tool labelImg and saved. The saved XML file contains the target frame coordinates and category information of the target image.
[0018] Divide the target labeled dataset into training set and test set samples;
[0019] The Mosaic data enhancement is to piece together multiple experimental images in the training set into one image for training the improved target detection algorithm YOLOv5.
[0020] Preferably, before the sample data set is expanded, the sample data set is screened and integrated.
[0021] Preferably, when the coordinated attention mechanism CA is introduced into the backbone network of the target detection algorithm YOLOv5, the global pooling method is decomposed and converted into two one-dimensional feature codes, specifically including:
[0022] First, given an input image X, use average pooling of size (H, 1) and (1, W) to encode each channel along the horizontal and vertical coordinates respectively, where H is the coordinate height and W is the coordinate width;
[0023] The output of the cth channel with height h and width w is expressed as follows:
[0024]
[0025]
[0026] Where i and w are the changes in width and height respectively. The above two transformations aggregate features along two spatial directions respectively to obtain a pair of direction-aware feature maps;
[0027] After the transformation in information embedding, the output height z h , and width z w Perform the splicing operation and generate the feature maps of the spatial information in the vertical and horizontal directions through the 1×1 convolution F1 operation. The formula is as follows:
[0028] f=δ(F1([z h ,z w ]))
[0029] Then f is decomposed into tensor f along the spatial information h ∈R C / r×H and the tensor f w ∈R C / r×W ; where δ is the coefficient, r is used to control the reduction rate of the sampling size, and then h and F w Perform 1×1 convolution transformation to transform f h and f w Transformed into a tensor with the same number of channels, the formula is as follows:
[0030]
[0031]
[0032] In the above formula is the sigmoid activation function, and reduces the number of channels of f by an appropriate reduction ratio r.
[0033] Finally, g h and g w Perform the expansion operation and use them as attention weights respectively, and the following formula is used as output:
[0034]
[0035] Preferably, the bidirectional cross-scale connection of the target detection algorithm YOLOv5 is improved by using BiFPN, and weighted feature fusion is performed, specifically including:
[0036] Delete nodes whose contributions do not meet the standard in two non-adjacent fusion feature networks, that is, nodes with only one input edge but no feature fusion;
[0037] Adding an additional edge from the original input to the output node between the two non-adjacent fusion feature networks;
[0038] A pair of paths is regarded as a feature layer, and then repeated multiple times to obtain more high-level feature fusion.
[0039] Preferably, additional weights are added in the high-level feature fusion by fast normalization fusion.
[0040] Preferably, the method of using the improved target detection algorithm YOLOv5 to identify the image information in the to-be-identified data set specifically includes:
[0041] Input the test set samples into the improved target detection algorithm YOLOv5, detect the target image through the target anchor frame, and obtain the target frame;
[0042] Extract feature information in the target frame through the backbone network;
[0043] The feature information is weighted and fused to obtain the recognition result.
[0044] Preferably, before using the improved target detection algorithm YOLOv5 to identify the data to be identified, the improved target detection algorithm YOLOv5 is evaluated, and the evaluation indicators include: recall rate Recall, referred to as R; precision Precision, referred to as P; average precision AP and average precision MAP of AP values of all categories;
[0045] Among them, TP is the number of correct target detections, FN is the number of missed targets, and FP is the number of falsely detected targets. The specific formula is as follows:
[0046]
[0047]
[0048]
[0049] The target recognition and detection method based on improved YOLOv5 provided by the present invention has the following beneficial effects:
[0050] The method first changes the Euclidean distance of K-Means clustering to 1-IOU to improve the adaptability of the model target box; then introduces the coordinate attention mechanism in the backbone network to more effectively learn the features of small targets and target positions; finally, the feature fusion method is improved in the neck by introducing BiFPN feature fusion to expand the model receptive field and enhance the multi-scale learning of multiple interference targets. This not only improves the accuracy of individual pig recognition in general situations, but also improves the detection performance in situations where pigs are densely packed and small targets are far away. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiment of the present invention and its design scheme, the following briefly introduces the drawings required for this embodiment. The drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0052] Figure 1 This is a flow chart of a target recognition and detection method based on improved YOLOv5 according to Embodiment 1 of the present invention;
[0053] Figure 2 This is the YOLOv5s network structure diagram;
[0054] Figure 3 This is the structure diagram of the coordinate attention mechanism;
[0055] Figure 4 Schematic diagram of the introduction of CA attention module;
[0056] Figure 5 This is the feature fusion diagram of PANET and BiFPN;
[0057] Figure 6 This is the BiFPN feature fusion module process;
[0058] Figure 7 To improve the BiFPN feature fusion module;
[0059] Figure 8 Label the interface for the pig face dataset;
[0060] Fig. 9 To compare the detection effects before and after the introduction of the CA module;
[0061] Fig.10 To improve the detection effect comparison of BiFPN feature fusion module before and after;
[0062] Fig.11 It is the Loss curve diagram;
[0063] Fig.12 A comparison chart is provided for visualizing the results. DETAILED DESCRIPTION
[0064] In order to enable those skilled in the art to better understand the technical solution of the present invention and implement it, the present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the scope of protection of the present invention.
[0065] Example 1
[0066] The present invention provides a target recognition and detection method based on improved YOLOv5. In this embodiment, pigs from the Jinghuimeng pig farm in Mengcheng, Anhui Province are used as detection objects, and their facial information is recognized and detected. Specifically, Figure 1 As shown, the following steps are included:
[0067] Step 1: Collect target image sample data and construct a sample data set;
[0068] The acquisition tool is the Logitech C920Pro camera. In order to better collect the facial information of pigs, this experiment established a system for remotely controlling the acquisition device. The control system can remotely control the camera of the acquisition device to rotate, and can collect in time under sufficient light, so as to obtain the facial information of pigs with different features and obtain image sample data containing different features. A total of 2126 sample images were collected with a resolution of 1920 pixels × 1080 pixels.
[0069] Step 2: Screen and integrate the sample data to obtain a sample data set;
[0070] In order to ensure that a good data set is obtained, the present invention first screens and integrates the collected data to obtain a sample data set.
[0071] Step 3: Expand the sample data set to obtain the data to be identified, specifically:
[0072] The sample data set was randomly cropped, randomly offset, and Mosaic data enhancement was performed to expand the experimental sample size to 6378. Mosaic data enhancement was used to combine four experimental images into one for training, which improved the model's ability to detect small targets to a certain extent. The pig data set in the experiment contains a total of 5 pig individuals, which were manually marked and labeled using labelImg. They were numbered pig1, pig2, and pig5. The ratio of the training set to the test set samples was about 9:1. The saved XML file contains the target frame coordinates and category information of the sample image. The annotation interface is as follows: Figure 8 shown.
[0073] Step 4, improving the target detection algorithm YOLOv5 to obtain an improved target detection algorithm YOLOv5;
[0074] First, the principle of YOLOv5 algorithm is introduced as follows:
[0075] The YOLOv5 target detection algorithm is a new generation algorithm that inherits the essence of the YOLO series of algorithms. It has different degrees of improvement in weight files, reasoning time, and training time compared to YOLOv3 and YOLOv4. In the Yolov5 official code, there are a total of 4 versions of the target detection network given, namely Yolov5s, Yolov5m, Yolov5l, and Yolov5x. The four models are deepened and widened on the basis of Yolov5s. Considering that pig face recognition is applied to the project, the present invention selects the lightweight network Yolov5s, whose structure is mainly divided into four parts, Input input end, Backbone backbone network, Neck network, and Prediction output end.
[0076] The input end mainly processes the images of the input model in a unified manner through three methods: Mosaic data enhancement, adaptive anchor box calculation, and adaptive image size.
[0077] The main function of the Backbone network is to extract features, and it mainly includes three modules: Focus, BottleneckCSP, and Spatial Pyramid Pooling SPP. The Focus module periodically extracts pixels from the input image and reconstructs them into a low-resolution image, that is, stacking four adjacent positions of the image to improve the receptive field of each point, reduce the loss of original information, reduce the amount of calculation and speed up. The BottleneckCSP module mainly includes Bottleneck and CSP, which effectively reduce the amount of calculation and improve the speed. The SPP module uses the maximum pooling of 5 / 9 / 13, and then performs Concat fusion to improve the receptive field.
[0078] PANET in the Neck network is based on the Mask R-CNN and FPN frameworks, which strengthens information propagation and has the ability to accurately retain spatial information, which helps to properly locate pixels to form masks.
[0079] The output of Prediction is mainly the detection part, which applies the anchor box on the feature map and generates the classification probability, confidence and the final vector of the target anchor box. The complete YOLOv5 model diagram is as follows: Figure 2 shown.
[0080] The improvement of the target detection algorithm YOLOv5 includes the following improvement steps:
[0081] Step 4.1: Optimize the target anchor box
[0082] The size of the prior anchor box for target detection plays a great role in target detection. If a suitable prior anchor box is selected, the detector learned by the network will be accurate. There are two main ways to determine the prior anchor box: empirical determination and clustering determination. YOLOv5 uses K-means dimensional clustering (K-Means) to determine the prior anchor box. The present invention changes the Euclidean distance used in the K-Means clustering algorithm to 1-IOU (bboxes, anchors) as the method for determining the prior anchor box. In order to prove the feasibility of the improved model, the present invention introduces Avg IOU as an evaluation index, that is, the average of the maximum IOU of the prior box and the actual target box. The larger the Avg IOU, the better the prior box obtained.
[0083] The experimental hardware of the present invention uses 16G memory, NVIDIA GeForce RTX 2080Ti graphics card, Inteli79700F 3.0GHz, 16G memory processor, Pytorch 1.7.1, CUDA11.1 software, and the experimental samples all use a self-made pig face data set, with a total of 2126 pictures, and the number of prior frames is 9, etc. The manually designed prior frames are recorded as AnchorBoxes, the original K-Means clustering is recorded as Cluster SSE, and the improved clustering is recorded as Cluster IOU.
[0084] Table 1 Avg IOU comparison
[0085]
[0086] The experimental results in Table 1 show that in terms of determining the prior frame, the original clustering algorithm is better than the manual design method, and the improved clustering algorithm is better than the original clustering algorithm and the manual design method, with Avg IOU increased by 6.1% and 2.1% respectively. This shows that the improved K-Means algorithm is better than the above prior frame determination method, has a higher fitness, and improves the effect of the model's multi-scale pig face image detection.
[0087] Step 4.2: Introduce coordinate attention mechanism CA
[0088] In order to select the feature information that is more critical to the current task from the input image information, the present invention introduces an attention mechanism. Currently, the attention mechanism mainly includes three categories: spatial attention, channel attention, and self-attention. Most attention mechanisms can be used in deep neural networks to improve performance, but the computational overhead brought about is difficult for mobile networks with relatively small models to bear. Therefore, the present invention mainly introduces SE (Squeeze-and-Excitation), CBAM (Convolutional Block Attention Module), and CA (Coordinate Attention) attention mechanisms for experiments. Finally, a novel and efficient attention mechanism CA is adopted to encode channel relationships and long-term dependencies through precise location information, which ensures efficiency while bringing almost no additional calculations. The specific process is as follows: Figure 3 shown.
[0089] In order to enable the attention module to capture feature information with precise location, the traditional global pooling method is decomposed and converted into two one-dimensional feature encodings. Specifically, given the input X, each channel is encoded along the horizontal coordinate and vertical coordinate respectively using average pooling of size (H, 1) and (1, W), where H is the coordinate height and W is the coordinate width. Therefore, the output of the cth channel with height h and width w can be expressed as follows:
[0090]
[0091]
[0092] Where i and w are the changes in width and height respectively. The above two transformations aggregate features along two spatial directions respectively to obtain a pair of direction-aware feature maps. At the same time, it also allows the attention module to capture long-term dependencies along one spatial direction and save precise position information along another spatial direction, which helps the network eliminate interference from the background of the image and locate the target of interest more accurately.
[0093] After the transformation in information embedding, the output height and width z h ,z w Perform a splicing operation and generate feature maps of spatial information in the vertical and horizontal directions through a 1×1 convolution F1 operation. The formula is as follows:
[0094] f=δ(F1([z h ,z w ])) (3)
[0095] Then f is decomposed into tensor f along the spatial information h ∈RC / r×H and the tensor f w ∈R C / r×W . Among them, δ is the coefficient, and r is used to control the reduction rate of the sampling size. h and F w Perform 1×1 convolution transformation to transform f h and f w Transformed into a tensor with the same number of channels, the formula is as follows:
[0096]
[0097]
[0098] In the above formula is the sigmoid activation function. At the same time, the number of channels of f is reduced by an appropriate reduction ratio r, which reduces the amount of calculation and complexity of the model. h and g w Perform the expansion operation and use them as attention weights respectively, and the following formula is used as output:
[0099]
[0100] The network process of the present invention before and after the CA attention mechanism is introduced into the backbone network is as follows Figure 4 shown.
[0101] Step 4.3: Feature fusion BiFPN
[0102] After the neural network extracts features through the backbone network, the use of high-level features and low-level features is critical to improving the model in pig face detection. The original Yolov5 uses PANET (as shown in Figure 5(a)) for feature fusion. Although it improves the use and fusion of features overall, it fails to learn and fuse features with large contributions in a targeted manner, and brings a large amount of parameters and calculations.
[0103] Therefore, the present invention introduces lightweight universal upsampling operator (CARAFE) feature fusion, adaptive spatial feature fusion (ASFF) and BiFPN feature fusion for experiments, and finally selects BiFPN with better effect (such as Figure 5 (b) Improve the bidirectional cross-scale connection and perform weighted feature fusion. The specific process is as follows Figure 6As shown. First, delete the nodes with smaller contributions in the fusion feature network in P3 and P5, that is, the nodes with only one input edge but no feature fusion; then add additional edges from the original input to the output node in P4 to fuse more features without increasing too much cost; finally, regard a pair of paths as a feature layer, and then repeat multiple times to obtain more high-level feature fusion. Since different input features have different resolutions, and different resolutions contain different semantic information, that is, the contribution of features is different, the present invention adds additional weights through fast normalized fusion (as shown in Formula 7 below), so that the network can learn the importance of each feature layer through weights. Thereby, the model has better performance in pig face detection. The network diagram before and after the improvement of BiFPN feature fusion is shown in Figure 7 shown.
[0104]
[0105] In the above formula, w i ≥0 is achieved by i Relu is applied later to ensure that ∈ = 0.0001 is a small value to avoid numerical instability.
[0106] The experiment of the present invention adopts a graphics card with 16G memory, NVIDIA GeForce RTX 2080Ti, an Intel i7 9700F3.0GHz processor with 16G memory, and is implemented in the environment of Pytorch 1.7.1 and CUDA11.1.
[0107] The present invention obtains the initialization weights of the pre-trained model by training on the large dataset COCO, uses the SGD optimizer to optimize the overall goal, the training batch is 16, the learning rate is set to 0.01, and the model is iterated 100 times. The image size used by the model is 640×640.
[0108] Before using the improved target detection algorithm YOLOv5 to identify the data to be identified, the improved target detection algorithm YOLOv5 is evaluated. The present invention uses the evaluation indicators commonly used in deep learning: Recall, referred to as R; Precision, referred to as P; Average Precision AP (Average Precision) and the average AP value of all categories MAP (MeanAverage Precision). Among them, TP (True Positives) is the number of correct pig face detections, FN (False Negatives) is the number of missed pig faces, and FP (False Positives) is the number of falsely detected pig faces. The specific formula is as follows:
[0109]
[0110]
[0111]
[0112] Step 5, using the improved target detection algorithm YOLOv5 to identify the data to be identified and obtain the identification result, including: inputting the test set samples into the improved target detection algorithm YOLOv5, detecting the target image through the target anchor frame to obtain the target frame; extracting the feature information in the target frame through the backbone network; performing weighted feature fusion on the feature information to obtain the recognition result.
[0113] Experimental results and analysis
[0114] First, experimental comparison of improved target anchor boxes
[0115] In order to further measure the performance of the optimized target anchor frame for pig face recognition detection, the same experimental device and parameters were used to conduct experiments under the self-made pig face dataset. As shown in Table 2, "+" indicates that the model has added this module (the following tables all have this meaning). The experimental results show that the improved model 1 for determining the target anchor frame by K-Means clustering has been improved to varying degrees in terms of accuracy, recall rate and average precision compared with the original YOLOv5 model. At the same time, it also provides support for the improvement of the improved YOLOv5 model in multi-scale pig face detection.
[0116] Table 2 Performance comparison of target anchor box before and after optimization
[0117]
[0118] Second, the experimental results of introducing the attention mechanism are compared with the test results
[0119] In order to better analyze the effect of introducing the attention mechanism on pig face detection, under the self-made pig face data set, the models that introduced CA, SE, and CBAM attention mechanisms in YOLOv5 were compared with the original YOLOv5 model under the same experimental conditions, as shown in Table 3. The experimental results show that the model that introduced the attention mechanism is superior to the original model in accuracy, recall rate and average precision rate to varying degrees, among which the model that introduced CA is superior to the model using SE and CBAM in average precision and recall rate. It further illustrates that CA is better than SE, which only considers the internal channel information and ignores the importance of position information, and is also better than CBAM, which introduces position information by global pooling on the channel, but can only capture local information, and cannot obtain globally dependent information. Therefore, the present invention introduces the CA attention mechanism to improve the model's anti-interference ability and the ability to extract target features, so as to achieve better pig face detection effect.
[0120] Table 3 Performance comparison of introducing different attention mechanisms
[0121]
[0122] Comparison of detection results before and after adding the CA attention module Fig. 9 As shown, the left side shows the original YOLOv5 detection effect Fig. 9 (a) shows that there are some missed detections for the slightly blurred pig face recognition. The right side shows the detection effect of introducing the CA attention module. Fig. 9 (b) It effectively improves the model’s ability to learn location information, increases the model’s anti-interference ability, reduces the missed detection rate compared to the original model, and improves the classification confidence to a certain extent.
[0123] Third, the experimental results of improved feature fusion are compared with the detection results
[0124] In order to observe the effect of the improved feature fusion model on pig face detection in more depth, a consistent pig face data set and the same experimental conditions are used to compare the lightweight universal upsampling operator (CARAFE) feature fusion, adaptive spatial feature fusion (ASFF) and BiFPN feature fusion with the original YOLOv5 model, as shown in Table 4 below. The experimental results show that compared with the original YOLOv5 model, the model using the lightweight universal upsampling operator CARAFE, the model using the adaptive spatial feature fusion ASFF and the model using the BiFPN feature fusion have improved accuracy, average precision and recall, but the model using the BiFPN feature fusion is significantly better than the first two improvements in average precision and accuracy. Therefore, the present invention adopts the BiFPN feature fusion model, and the backbone network extracts high-level and low-level features for biased use, improves the receptive field, and provides a good data basis for the model to improve the pig face detection effect.
[0125] Table 4 Performance comparison of improved feature fusion algorithm
[0126]
[0127] Comparison of detection results before and after adding the BiFPN feature fusion module Fig.10 Shown: The left side shows the original YOLOv5 detection effect Fig.10 (a), and the right side is the detection effect of introducing the BiFPN feature fusion module in Figure 10(b). The BiFPN feature fusion module can correctly detect the pig face target before and after the improvement, but the improved model uses the high-level and low-level information more specifically, increases the receptive field of the model, and makes the model's predicted border more accurate and the classification confidence higher.
[0128] Fourth, ablation experiment
[0129] In order to verify the effect of mixed use of the improved modules of the present invention on the model detection of pig faces, an ablation experiment was conducted, and the results are shown in Table 5. The experiments all used the same pig face data set, and the experimental conditions were consistent. The experimental results show that the model that introduces improved K-Means clustering, CA coordinate attention mechanism and BiFPN feature fusion has different degrees of improvement in accuracy, recall rate and average precision compared with the original model. It shows that the prior box determined by the improved K-Means clustering can effectively improve the learning efficiency of the model for the target detection box; secondly, because CA has a long-term dependence on position information and channel relationship, it effectively improves the efficiency of the model for learning position information and improves the prediction effect; finally, BiFPN feature fusion is used to streamline the nodes with smaller contribution to feature fusion, and the use of nodes with larger contribution is strengthened by assigning weights, etc., so as to more effectively fuse the feature maps of low and high layers, improve the efficiency of the model in using features, and achieve better detection effects.
[0130] From the longitudinal comparison of the improvements in Table 5, it can be seen that the model 11 (the improved target detection algorithm YOLOv5 of the present invention) adopted by the present invention is slightly lower than the model 4 that introduces CA alone and the model 10 that introduces CA and BiFPN in a mixed manner in terms of recall rate, but it is in the lead in all other aspects. In terms of average precision mAP, the improvement of the original YOLOv5 model by introducing one improvement point alone (models 1, 4, 7), introducing two improvement points (models 8, 9, 10) and introducing three improvement points (model 11 of the present invention) increases successively, which more effectively illustrates that the three improved methods of the present invention are not only effective for the original model alone, but also positively correlated to the model detection effect when used in combination. In general, the model 11 with three improvements is still the best. Although the recall rate is lower than that of individual solutions, it has achieved the best average precision rate of 95.5% and accuracy rate of 92.6% among all solutions, which are 2.2% and 13.2% higher than the original YOLOv5, respectively, further illustrating the feasibility of the improved algorithm. (“√” and “×” in the table below respectively indicate whether the improvement method is adopted or not.)
[0131] Table 5. Ablation experiment comparison table
[0132]
[0133] Fifth, the training results of model 11
[0134] The loss of the model 11 finally adopted by the present invention changes during training as follows: Fig.11 As shown in the figure, the horizontal axis Epoch is the number of training times, and the vertical axis Loss is the loss value. Fig.11It can be seen that the loss value decreases rapidly when Epoch is 0-15, and the loss value decreases slowly when Epoch is 15-75. Finally, when Epoch is 75-99, the algorithm loss drops to a basically stable state, and the loss value converges to around 0.01. No overfitting or underfitting occurs during the training process.
[0135] 6. Model 11 test results
[0136] Fig.12 This is a visualization of the detection results of the original YOLOv5 model before and after the three improvements of K-Means, CA, and BiFPN. The left side is the detection effect of the original YOLOv5 Fig.12 (a) The right side shows the detection effect of model 11 after introducing three improvements. Fig.12 (b). It can be seen that the original YOLOv5 has missed detections in dense and occluded pig face detection. The improved model 11 can detect pig4, which is occluded and small in a dense pig sample environment, effectively reducing the model's missed detection rate and improving the classification confidence. This shows that the improved model has a strong generalization ability in scenes with small, dense, and occluded targets.
[0137] In order to better analyze the advantages and disadvantages of the improved algorithm of the present invention, experiments were conducted on other improved algorithms introduced under the same data set and experimental conditions, as shown in Table 6. The experimental results show that the model 11 adopted by the present invention is slightly lower than the model 5 in accuracy and slightly lower than the model 3 in recall, but is in the lead in other aspects. Among them, the average precision is significantly better than other improved models, which is 2% higher than the lowest performance model 2 and 1.7% higher than the highest performance model 6. It further illustrates the feasibility of the algorithm of the present invention in pig face recognition detection.
[0138] Table 6 Performance comparison with other pig face detection algorithms
[0139]
[0140] The present invention is based on the improvement of YOLOv5 algorithm. The method specifically adopts the K-Means clustering algorithm with the distance changed to 1-IOU to determine the prior frame, introduces the attention mechanism CA to the Backbone module of the model, and proposes a new feature fusion BiFPN on the Neck module of the model, and applies it to pig face recognition detection. In the experimental environment of the present invention and the pig face data set, not only the single improvement point is compared and tested, but also the algorithms of multiple improvement points are compared and tested. Among them, the improved model 11 is the best, and the mAP reaches 0.955, which is 2.2% higher than the original algorithm. Therefore, the improved model 11 in this experiment has a certain improvement in the accuracy of pig face recognition, and provides a feasible technical solution for individual pig management.
[0141] The embodiments described above are only preferred specific implementation modes of the present invention, and the protection scope of the present invention is not limited thereto. Any simple changes or equivalent replacements of the technical solutions that can be obviously obtained by any technician familiar with the field within the technical scope disclosed in the present invention belong to the protection scope of the present invention.
Claims
1. A target recognition and detection method based on improved YOLOv5, characterized in that: The following steps are involved: Collect target image sample data and build a sample data set; Expand the sample data set to obtain the data set to be identified; The target detection algorithm YOLOv5 is improved to obtain the improved target detection algorithm YOLOv5, which specifically includes: The Euclidean distance of the K-Means dimensional clustering algorithm K-Means is changed to 1-IOU, the K-Means algorithm is used to determine the prior anchor box, and the target anchor box of the target detection algorithm YOLOv5 is optimized; Introducing the coordinated attention mechanism CA into the backbone network of the target detection algorithm YOLOv5; BiFPN is used to improve the bidirectional cross-scale connection of the target detection algorithm YOLOv5, and weighted feature fusion is performed to obtain the improved target detection algorithm YOLOv5; The improved target detection algorithm YOLOv5 is used to identify the image information in the dataset to be identified and obtain the identification result; The BiFPN is used to improve the bidirectional cross-scale connection of the target detection algorithm YOLOv5, and weighted feature fusion is performed, specifically including: Delete nodes whose contributions do not meet the standard in two non-adjacent fusion feature networks, that is, nodes with only one input edge but no feature fusion; Adding an additional edge from the original input to the output node between the two non-adjacent fusion feature networks; A pair of paths is regarded as a feature layer, and then repeated multiple times to obtain more high-level feature fusion.
2. The target recognition detection method based on improved YOLOv5 according to claim 1, characterized in that: The collecting of target image sample data specifically includes: controlling the camera to rotate through a remote control system to achieve time-sharing collection and obtain image sample data containing different features.
3. The target recognition detection method based on improved YOLOv5 according to claim 1, characterized in that: The sample data set is expanded, comprising the following steps: The sample data set is randomly cropped, randomly offset, and Mosaic data augmented. The image is manually labeled and labeled using the image annotation tool labelImg and saved. The saved XML file contains the target frame coordinates and category information of the target image. Divide the target labeled dataset into training set and test set samples; The Mosaic data enhancement is to piece together multiple experimental images in the training set into one image for training the improved target detection algorithm YOLOv5.
4. The target recognition detection method based on improved YOLOv5 according to claim 3, characterized in that: Before expanding the sample data set, the sample data set is screened and integrated.
5. The target recognition detection method based on improved YOLOv5 according to claim 1, characterized in that: When the coordinated attention mechanism CA is introduced into the backbone network of the target detection algorithm YOLOv5, the global pooling method is decomposed and converted into two one-dimensional feature codes, specifically including: First, given an input image X, use average pooling of size (H, 1) and (1, W) to encode each channel along the horizontal and vertical coordinates respectively, where H is the coordinate height and W is the coordinate width; The output of the cth channel with height h and width w is expressed as follows: Where i and w are the changes in width and height respectively. The above two transformations aggregate features along two spatial directions respectively to obtain a pair of direction-aware feature maps; After the transformation in information embedding, the output height z h , and width z w Perform the splicing operation and generate the feature maps of the spatial information in the vertical and horizontal directions through the 1×1 convolution F1 operation. The formula is as follows: f=δ(F1([z h ,z w ])) Then f is decomposed into tensor f along the spatial information h and the tensor f w ; where δ is the coefficient for F h and F w Perform 1×1 convolution transformation to transform f h and f w Transformed into a tensor with the same number of channels, the formula is as follows: In the above formula is the sigmoid activation function, and reduces the number of channels of f by an appropriate reduction ratio r. Finally, g h and g w Perform the expansion operation and use them as attention weights respectively, and the following formula is used as output:
6. The target recognition detection method based on improved YOLOv5 according to claim 1, characterized in that: Additional weights are added in the high-level feature fusion through fast normalization fusion.
7. The target recognition detection method based on improved YOLOv5 according to claim 1, characterized in that: The improved target detection algorithm YOLOv5 is used to identify the image information in the identification data set, specifically including: Input the test set samples into the improved target detection algorithm YOLOv5, detect the target image through the target anchor frame, and obtain the target frame; Extract feature information in the target frame through the backbone network; The feature information is weighted and fused to obtain the recognition result.
8. The target recognition detection method based on improved YOLOv5 according to claim 7, characterized in that: Before using the improved target detection algorithm YOLOv5 to identify the data to be identified, the improved target detection algorithm YOLOv5 is evaluated. The evaluation indicators include: Recall, referred to as R; Precision, referred to as P; Average Precision AP and the average AP value of all categories MAP; Among them, TP is the number of correct target detections, FN is the number of missed targets, and FP is the number of falsely detected targets. The specific formula is as follows:
Citation Information
Patent Citations
Livestock face recognition method based on improved YOLOv3
CN111881803A
Same-color system target fruit detection method and system
CN113343750A
Method for detecting daily behaviors of group health-preserving pigs
CN113822185A
