An object detection method based on IoU improved loss function
By introducing the cross-comparison weighted parameters and distance and width and height loss values in the object detection, a new loss function Lp-EIoU is formed, which solves the shortcomings of the existing IoU loss function without overlap and inclusion, and significantly improves the accuracy and convergence speed of the object detection.
Patent Information
- Application Number
- CN202210210383.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-03
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2042-03-03
AI Technical Summary
The existing IoU-based loss function has a loss value of 0 when the prediction box and the target box do not overlap, and the convergence speed is slow. When the prediction box and the target box appear inclusion phenomenon, it will degenerate into the IoU loss function, resulting in low detection accuracy.
A target detection method based on IoU is proposed. By introducing the cross-comparison weighted parameter α, the distance penalty term weighted parameter β and the aspect ratio penalty term weighted parameter γ, the distance loss value and the high-width loss value of the prediction box and the target box are calculated, and combined with the IoU value, a new loss function Lp-EIoU is formed.
It effectively improves the positioning performance of bounding box regression during the object detection process, improves the accuracy of object detection, solves the problems of loss value of 0 and slow convergence speed, and maintains high detection accuracy when inclusion phenomena.
Smart Images

Figure CN114782765B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of target detection, and in particular relates to a target detection method based on an IoU improved loss function. Background Art
[0002] Object detection mainly includes traditional object detection technology and object detection technology based on deep learning. In recent years, object detection technology based on deep learning has developed rapidly and has become the mainstream method in the field of current object detection technology. Bounding box regression is a key step in the object detection algorithm based on deep learning. The most commonly used positioning indicator for bounding box regression in the detection process is Intersection over Union (IoU), but the loss function based on IoU cannot correctly reflect the closeness between the target box and the predicted box. There is a problem that the loss value is 0 when the predicted box and the target box do not overlap, and the convergence speed is slow. In view of the shortcomings of the IoU loss function, the prior art introduces the GIoU loss function, which introduces the minimum bounding box based on the characteristics of IoU to solve the problem that the loss value is 0 when the predicted box and the target box do not overlap. However, this loss function has the problem that it will degenerate into the IoU loss function when the predicted box and the target box are included, which makes the detection accuracy low, and the problem of slow convergence when the two boxes intersect still exists. Summary of the invention
[0003] In order to overcome the shortcomings of the above-mentioned prior art, the purpose of the present invention is to provide a target detection method based on IoU improved loss function, which improves the accuracy of target detection by improving the positioning performance of bounding box regression in the target detection process, thereby solving the above-mentioned problems.
[0004] In order to achieve the above object, the technical solution adopted by the present invention is:
[0005] A target detection method based on IoU improved loss function, the steps are as follows:
[0006] Step 1: For the target detection network, preset the intersection-over-union weighting parameter α, the distance penalty weighting parameter β and the aspect ratio penalty weighting parameter γ, the preset constraints are {α, β, γ}>1, and the number of training times is epochs;
[0007] Step 2: Use multiple pictures of different categories as learning pictures to be trained, input them into the target detection network training, and obtain the prediction box b of the detected target; preferably, a data set in the field of target detection can be used, the data set consists of pictures containing multiple categories of targets, and all pictures in the data set are taken as learning pictures to be trained;
[0008] Step 3: Calculate the target box b of the image to be trained gtThe intersection over union (IoU) value of the predicted box b.
[0009] Step 4: Get the target frame b gt A minimum enclosing box G with the prediction box b, the minimum enclosing box G is a rectangular box;
[0010] Step 5: Calculate the prediction box b and target box b gt The distance loss value L dis ;
[0011] Step 6: Calculate the prediction box b and target box b gt The height and width loss value L asp ;
[0012] Step 7: Calculate the loss function L p-EIoU , the formula is as follows:
[0013]
[0014] Among them, (x1, y1) and (x2, y2) are the target box b respectively. gt The coordinates of the upper left corner and lower right corner of the prediction box b, (x1', y1') and (x2', y2') are the coordinates of the upper left corner and lower right corner of the prediction box b, l and w are the length and width of the minimum enclosing box G, respectively;
[0015] Step 8: Through the loss function L p-EIoU Calculate the loss value and use the back-propagation algorithm to update the weight parameters in the target detection network;
[0016] Step 9: Keep the training image unchanged, repeat steps 2 to 8 for a total of epochs-1 times, and obtain the weight parameters of the final target detection network and the detection accuracy of the network. The optimal detection accuracy corresponds to the optimal α, β, γ values and the optimal weight parameters;
[0017] Step 10: The target detection network uses the optimal α, β, γ values and optimal weight parameters to perform target detection based on the input.
[0018] Compared with the prior art, the present invention can effectively improve the positioning performance of bounding box regression in the target detection process, thereby improving the accuracy of target detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 It is a flow chart of the present invention.
[0020] Figure 2 It is the calculation graph of IoU. DETAILED DESCRIPTION
[0021] The embodiments of the present invention are described in detail below with reference to the accompanying drawings and examples.
[0022] like Figure 1 As shown, the present invention is a target detection method based on IoU improved loss function, comprising the following steps:
[0023] Step 1: For the target detection network, preset the intersection-over-union weighting parameter α, the distance penalty weighting parameter β, and the aspect ratio penalty weighting parameter γ, and preset the constraints as {α, β, γ}>1, and the number of training times is epochs.
[0024] Step 2, input the learning picture to be trained into the target detection network to obtain the prediction box b of the detection target. In the present invention, the learning pictures to be trained are pictures of multiple different categories. For example, a general data set in the current target detection field, such as a VOC data set or a COCO data set, can be directly downloaded. The general data set consists of pictures containing multiple categories of targets, and the category targets can be, for example, pedestrians, vehicles, ships, trains, etc. All pictures in the general data set are taken as learning pictures to be trained. By training the target detection network, the target detection network can detect targets of all categories or specific categories in the data set.
[0025] In the training process of the present invention, after the forward reasoning of each round of training is completed, the target detection network will obtain the bounding prediction box b of the detected target in the image and the coordinates of the box, and draw the prediction box b in the image to show the detected target. The coordinates of the prediction box b include the coordinates of the center point and the coordinates of the four corners.
[0026] Step 3: Calculate the target box b of the image to be trained gt The intersection over union (IoU) of the predicted box b is as follows:
[0027]
[0028] Among them, A and A gt are the predicted box b and the target box b respectively. gt The calculation principle can be found in the attached Figure 2 .
[0029] Target box b gt It is a bounding box that is manually annotated for the target area contained in the dataset image. It is a rectangular box, that is, a manual box is drawn to annotate the target to be detected, and the coordinates of the upper left corner, lower right corner and center point of the target box are saved in the corresponding label document. The coordinates are consistent with the target box b gt One-to-one correspondence. Get the target frame b gt Later, during the training process, its coordinates are used as prior knowledge of the target detection network model to train the network.
[0030] Step 4: Get the target frame b gt The minimum enclosing box G with the predicted box b is a rectangular box with a length of l and a width of w. It is calculated as follows:
[0031] l=max(x2',x2)-max(x1',x1)
[0032] w=max(y2',y2)-max(y1',y1)
[0033] Among them, (x1, y1) and (x2, y2) are the target box b respectively. gt The coordinates of the upper left corner and lower right corner of the prediction box b are (x1', y1') and (x2', y2') respectively.
[0034] Step 5: Calculate the prediction box b and target box b gt The distance loss value L dis , L dis According to the prediction box b and the target box b g The center point distance is used to increase the total loss value, thereby accelerating the regression of the prediction box to the target box. The calculation formula is as follows:
[0035]
[0036] Among them, b and b gt Represents the prediction box b and the target box b respectively gt The center point of gt ‖2 represents the Euclidean distance between the coordinates of the two center points, and c is the diagonal length of the minimum enclosing box G;
[0037] Right now:
[0038]
[0039] Step 6: Calculate the prediction box b and target box b gt The height and width loss value L asp , L asp According to the prediction box b and the target box b gt The difference between the width and height of the image is used to increase the total loss value, thereby accelerating the regression of the prediction box to the target box. The calculation formula is as follows:
[0040]
[0041] Among them C w is the width of the minimum enclosing box G, C h is the height of the minimum enclosing box G, w gt 、h gt is the target box b gtThe width and height of w and h are the width and height of the prediction box b;
[0042] Right now:
[0043]
[0044] Step 7: For the IoU-based loss function L IoU It cannot correctly reflect the closeness between the target box and the prediction box. When the prediction box and the target box do not overlap, the loss value is 0, and the convergence speed is slow. First, an improved version of the loss function L based on EIoU representation is proposed. EIoU , the calculation formula is as follows:
[0045]
[0046] From the above formula, we can see that L EIoU With L IoU Compared with the addition of L dis and L asp Two penalties, namely, adding distance, width and height difference to the IoU scale based on the only prediction box target box intersection and union ratio, so that L EIoU Directly minimize the distance, width, and height difference between the target box and the predicted box, which will lead to faster convergence and better positioning results.
[0047] On this basis, the present invention is based on L EIoU Optimize and propose the loss function L p-EIoU , the formula is as follows:
[0048]
[0049] From the above formula, we can see that L p-EIoU Keep L IoU The key properties of performance measurement include non-negativity, identity, symmetry and scale invariance. In addition, it also contains some important properties:
[0050] (1) Order maintenance: L p-EIoU and L IoU are all monotonically decreasing functions, that is, the optimal solution of loss value can be obtained by minimizing L p-EIo to obtain;
[0051] (2) Relative loss weight: When the parameters 0<{α, β, γ}<1 and {α, β, γ}>1, L p-EIo The weights will be adaptively reduced and increased according to the IoU and penalty terms of all objects respectively. And L with {α, β, γ}>1 p-EIoImproving the weighting scheme can help the target detection algorithm model pay more attention to objects with higher intersection-over-union ratios, thereby improving positioning and detection performance, that is, predicting more objects with higher intersection-over-union ratios and being more accurate at high precision thresholds;
[0052] (3) Relative gradient weight: L p-EIo The relative gradient of {α, β, γ} can be approximately expressed as:
[0053]
[0054] When {α, β, γ}>1, the relative gradient increases monotonically with the increase of IoU and penalty, while when 0<{α, β, γ}<1, the relative gradient decreases monotonically with the decrease of IoU and penalty. This relative gradient reweighting scheme allows the model to learn objects at an adaptive speed (i.e., different gradients) according to the characteristics of the object, such as when {α, β, γ}>1, it helps the detector learn high IoU targets faster.
[0055] Step 8: Through the loss function L p-EIoU The loss value is calculated and the weight parameters in the target detection network are updated using the back-propagation algorithm.
[0056] The back propagation algorithm is based on the gradient descent algorithm. It takes the difference between the network output value (prediction box) and the expected value (target box) as the objective function, that is, the loss function, and then enters the back propagation to find the partial derivative of the objective function with respect to the weight parameters of each neuron layer by layer, thus forming the gradient value of the objective function with respect to each weight parameter, and modifying the weight according to the gradient value.
[0057] Step 9: Continue to use the above training learning pictures, repeat steps 2 to 8 for epochs-1 times, and obtain the weight parameters of the final target detection network and the detection accuracy of the network. Among them, the detection accuracy is an evaluation index of the algorithm relied on by the target detection network, including the single class detection accuracy AP and the multi-class average detection accuracy mAP.
[0058] Step 10: The detection capability evaluation (i.e., accuracy) of the target detection network after learning is obtained through epochs rounds of training. The detection capability evaluation obtained through each cycle of learning can be compared through multiple epochs rounds of training. The optimal detection accuracy corresponds to the optimal α, β, γ values and the optimal weight parameters. The target detection network uses the optimal α, β, γ values and the optimal weight parameters to complete the target detection immediately according to the input.
[0059] In a specific embodiment of the present invention, a VOC dataset is used. The images in the VOC dataset have 20 categories, and the dataset is divided into a training set and a test set. The training set in the VOC dataset and the YOLOv5s target detection network are used to detect the target object using the L p-EIo The loss function is used to train YOLOv5s. By testing and comparing the models obtained through multiple trainings, the optimal detection accuracy and the corresponding optimal α, β, and γ values are finally obtained as shown in the following table:
[0060] α β γ mAP@50:95 mAP@75: 95.95 1 1 1 53.10 32.42 3 2 3 54.75 34.37
[0061] The detection accuracy corresponding to α=1、β=1、γ=1 represents the loss function L EIoU The detection accuracy when α=3、β=2、γ=3 is the detection accuracy, i.e. the loss function is L p-EIo The detection accuracy at this time is , and α, β, and γ are also optimal values at this time.
[0062] The detection accuracy is calculated every 0.5 in the IoU threshold of 0.5-0.95, and the average of the 10 calculated accuracy values is AP@50:95. The average of AP@50:95 for 20 types of targets is mAP@50:95. AP@75:95 is the average of 5 detection accuracy values calculated every 0.5 in the IoU threshold of 0.75-0.95. The average of AP@75:95 for 20 types of targets is mAP@75:95.
[0063] The calculation process of detection accuracy is as follows: the test set images in the data set are input into the target detection network to obtain the predicted box for each image, and then the IoU value between the predicted box and the target box in each image is calculated. The ratio of the number of targets with an IoU value greater than the threshold to the total number of targets is calculated, which is the detection accuracy under the current IoU threshold.
[0064] It can be seen from the table that L EIoU The loss function uses L p-EIoU The loss function effectively improves the detection accuracy, which means that the bounding box regression in the target detection network model training process achieves better positioning performance, thereby improving the detection accuracy of target detection.
Claims
1. A target detection method based on IoU improved loss function, characterized in that: The steps include: Step 1: For the target detection network, preset the intersection-over-union weighting parameter α, the distance penalty weighting parameter β and the aspect ratio penalty weighting parameter γ, the preset constraint condition is {α, β, γ}>1, and the number of training times is epochs; Step 2: Use multiple pictures of different categories as training learning pictures, input them into the target detection network training, and obtain the prediction box b of the detection target; Step 3: Calculate the target box b of the image to be trained gt The intersection over union (IoU) value of the predicted box b. Step 4: Get the target frame b gt A minimum enclosing box G with the prediction box b, the minimum enclosing box G is a rectangular box; Step 5: Calculate the prediction box b and target box b gt The distance loss value L dis ; Step 6: Calculate the prediction box b and target box b gt The height and width loss value L asp ; Step 7: Calculate the loss function L p-EIoU , the formula is as follows: Among them, (x1, y1) and (x2, y2) are the target box b respectively. gt The upper left corner and lower right corner coordinates of the predicted box b, (x1′, y1′) and (x2′, y2′) are the upper left corner and lower right corner coordinates of the predicted box b, respectively, l and w are the length and width of the minimum enclosing box G, respectively; Step 8: Through the loss function L p-EIoU Calculate the loss value and use the back-propagation algorithm to update the weight parameters in the target detection network; Step 9: Keep the training image unchanged, repeat steps 2 to 8 for a total of epochs-1 times, and obtain the weight parameters of the final target detection network and the detection accuracy of the network. The optimal detection accuracy corresponds to the optimal α, β, γ values and the optimal weight parameters; Step 10: The target detection network uses the optimal α, β, γ values and optimal weight parameters to perform target detection according to the input.
2. According to claim 1, the target detection method based on IoU improved loss function is characterized in that: In the step 2, a data set in the field of target detection is used, where the data set consists of pictures containing targets of various categories, and all pictures in the data set are taken as pictures to be trained and learned.
3. According to claim 1, the target detection method based on IoU improved loss function is characterized in that: In step 3, the calculation formula of the IoU value is as follows: Among them, A and A gt are the predicted box b and the target box b respectively. gt area.
4. According to claim 1, the target detection method based on IoU improved loss function is characterized in that: The calculation formulas for the length and width of the minimum enclosing frame G are as follows: l=max(x2′,x2)-max(x1′,x1) w=max(y2′,y2)-max(y1′,y1).
5. The target detection method based on IoU improved loss function according to claim 1 or 4, characterized in that: The L dis and L asp The calculation formula is as follows: 。 6. The target detection method based on IoU improved loss function according to claim 1, characterized in that: In step 9, the detection accuracy includes the single-class detection accuracy AP and the multi-class average detection accuracy mAP.