Boundary box regression loss calculation method based on inclusion relation
By introducing weights and penalties into the bounding box regression loss function, the impact of truth box geometry and inclusion relationship on the optimization of loss function is solved, and higher regression accuracy and detection performance are achieved.
Patent Information
- Application Number
- CN202411775578.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-03-14
AI Technical Summary
When the existing bounding box regression loss function handles the geometry of the truth box itself and the truth box and the prediction box are included with each other, it is difficult to distinguish different inclusion relationships, resulting in the loss function being unable to be effectively optimized.
A bounding box regression loss calculation method based on inclusion relationship is proposed. By introducing weights px and py along the horizontal and vertical directions, the regression direction of IoU is dynamically adjusted, and the penalty term related to the area of the non-overlapping area and the penalty term related to the distance between the center point of the two boxes and their left and right corner points is added in the loss function.
Improves regression accuracy, can effectively handle the inclusion of target boxes, speed up convergence speed, and improve detection recall and mAP value.
Smart Images

Figure CN119625444A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of deep learning and computer vision, and in particular to a method for calculating bounding box regression loss based on inclusion relationship. Background Art
[0002] As an important part of the detector's positioning branch, the bounding box regression loss function plays a core role in the target detection task. The commonly used evaluation index for position loss is IoU, which is the ratio of the intersection and union of the predicted box and the true value box. Subsequent research on the bounding box regression loss function focuses on the improvement of the IoU index. GIoU takes into account the non-overlapping parts that cannot be optimized. On the basis of IoU, an external minimum square box is added to constrain IoU to ensure that the loss still exists when the two boxes do not intersect; DIoU adds the ratio of the Euclidean distance between the center points of the predicted box and the true value box to the minimum closure diagonal on the basis of IoU, so that the two boxes can converge even when they do not overlap during training; CIoU iterates on the basis of DIoU and adds a factor related to the aspect ratio of the box to further improve the regression accuracy, but CIoU uses the aspect ratio of the true value box and the predicted box. When the aspect ratios of the two boxes are equal, the areas of the two boxes may differ greatly. EIoU uses a new calculation method to compare the width and height between the true value box and the predicted box respectively, overcoming the problems of CIoU.
[0003] Previous IoU loss function research usually focuses on optimizing the geometric positions of the prediction box and the true value box, ignoring the impact of the true value box's own geometric shape on the regression process. When the true value box is rectangular, its length and width are different. At this time, the prediction box moves along the short side or along the long side, which has completely different effects on the final result. In object detection, especially small object detection, inclusion often occurs, that is, the prediction box contains the true value box or the true value box contains the prediction box. When the true box and the prediction box have different inclusion relationships, the loss function may be unable to distinguish.
[0004] To address the impact of the geometric shape of the true value box on the regression process of the predicted box, weights px and py along the horizontal and vertical directions are proposed to dynamically adjust the regression direction of IoU. To address the problem that the loss is difficult to distinguish when the true value box and the predicted box contain each other, a penalty term related to the area of the non-overlapping region of the two boxes and a penalty term related to the distance between the center points of the two boxes and their left and right corner points are proposed to accelerate the convergence of the regression process and ensure the regression quality. Summary of the invention
[0005] The purpose of this invention is to design a bounding box regression loss calculation method based on inclusion relationship, aiming to solve the following problems:
[0006] (1) The impact of the geometric shape of the true value box on the prediction box regression process. When the shape of the true value box is a rectangle with a difference between its length and width, the predicted box moving along the short side or along the long side will affect the prediction result. For a true value box with a long side in the horizontal direction and a short side in the vertical direction, if it moves up or down along the short side in the vertical direction, the change in its corresponding IoU value is more significant than moving left or right along the long side in the horizontal direction. Therefore, moving along the short side or along the long side of the true value box has completely different effects on the final result. To address this impact, the weights px and py in the horizontal and vertical directions can be set to make the movement of the regression sample biased towards the direction with smaller IoU value changes.
[0007] (2) The problem of loss being difficult to distinguish when the true value box and the predicted box contain each other. Inclusion situations often occur in target detection, especially in small target detection, that is, the predicted box contains the true value box or the true box contains the predicted box. When the true box and the predicted box have different inclusion relationships, the loss function may be indistinguishable. To address the problem of loss being difficult to distinguish when the true value box and the predicted box contain each other, a penalty term related to the area of the non-overlapping region of the two boxes and a penalty term related to the distance between the center point of the two boxes and their left and right corners are proposed to accelerate the convergence of the regression process and ensure the regression quality.
[0008] The present invention proposes a method for calculating the bounding box regression loss based on the inclusion relationship:
[0009]
[0010] When the true value box and the predicted box are not contained, the loss function expression is L EEIoU1 :
[0011]
[0012] In the formula, (x, y) represents the coordinates of the center point of the predicted box, (xg, yg) represents the coordinates of the center point of the true value box, c represents the diagonal distance of the maximum circumscribed rectangle of the two boxes, and c w and c h Respectively represent the width and height of the maximum circumscribed rectangle of the two boxes, w and h represent the width and height of the predicted box, wg and hg represent the width and height of the true value box. In order to optimize the accuracy of bounding box regression, the weights px and py along the horizontal and vertical directions are introduced:
[0013]
[0014] Here scale calculates the average size of the annotation box in a data set, M represents the number of images in the data set, and N iIndicates the number of annotation boxes in the i-th image. By highlighting the proportion of a specific length or width, the anchor box has directionality in multiple regressions. ij ,hg ij Represents the width and height of the jth true value box in the i-th picture in the dataset.
[0015] When the true value box is included in the predicted box, the loss function expression is L EEIoU2 :
[0016]
[0017] S GT =wg×hg,S BB =w×h
[0018] d left =py×(x-xg1) 2 +px×(y-yg1) 2
[0019] d right =py×(xg-x2) 2 +px×(yg-y2) 2
[0020] The different inclusion situations of the two boxes are distinguished by calculating the area difference between the true value box and the predicted box and the distance between the center point and the left and right corner points. The area penalty item adjusts the loss by the area difference of the non-overlapping area, so that it has the ability to handle different inclusion relationships. When the area difference of the non-overlapping area increases, the difference between the true value box and the predicted box becomes larger, and the value of the penalty item should be increased to quickly adjust the impact of the area difference on position regression; when the area difference continues to increase, the penalty value should become a slow increase to avoid the problem of loss value explosion. If the area difference between the true value box and the predicted box is equal, it can be distinguished by the corner point distance penalty item of the second item, where d left The calculation is the square weighted value of the distance from the center point (x, y) of the prediction box to the upper left corner point (xg1, yg1) of the true value box, d right The calculated value is the square weighted value of the distance from the center point of the true value box (xg, yg) to the lower right corner point of the prediction box (x2, y2).
[0021] Due to the adoption of the above technical solution, the loss function calculation method designed by the present invention has the following advantages:
[0022] 1. The regression accuracy is greatly improved. With the help of horizontal weight px and vertical weight py, the direction of the IoU value can be adjusted during the regression process, effectively improving the detection accuracy and mAP value.
[0023] 2. It can handle the inclusion of the target box. Through the area difference and corner point distance penalty terms, the loss function can distinguish different inclusion situations, accelerate the convergence speed, and effectively improve the detection recall rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to make the purpose, technical solution and beneficial effects of the present invention clearer, the present invention provides the following drawings for illustration:
[0025] Figure 1 It is a schematic diagram of the execution flow of a method for calculating a bounding box regression loss based on a containment relationship of the present invention.
[0026] Figure 2 This is a schematic diagram when the true value box and the predicted box are not contained.
[0027] Figure 3 This is a schematic diagram when the prediction box contains the true value box.
[0028] Figure 4 This is a schematic diagram when the true value box contains the prediction box. Specific implementation plan
[0029] The present invention is further described in detail below in conjunction with the accompanying drawings in the embodiments of the present invention. The present invention proposes a bounding box regression loss calculation method based on the inclusion relationship, and the specific implementation includes the following contents:
[0030] 1. The loss calculation method proposed in this invention is applicable to single-stage target detection models such as the Yolo series, and is applicable to dense small and medium-sized target detection scenarios, such as the VisDrong dataset and the TinyPerson dataset.
[0031] 2. As attached Figure 1 As shown, the loss function handles the inclusion and non-inclusion of the true value box and the predicted box separately:
[0032]
[0033] Here, inclusion and non-inclusion are determined by the following expression:
[0034]
[0035] Here c w and c h They represent the width and height of the maximum circumscribed rectangle of the two boxes, w and h represent the width and height of the predicted box, and wg and hg represent the width and height of the true value box.
[0036] 3. When the true value box and the predicted box are not contained, as shown in the attached Figure 2 As shown, the loss function expression is L EEIoU1 :
[0037]
[0038] In the formula, (x, y) represents the coordinates of the center point of the predicted box, (xg, yg) represents the coordinates of the center point of the true value box, c represents the diagonal distance of the maximum circumscribed rectangle of the two boxes, and c w and c h Respectively represent the width and height of the maximum circumscribed rectangle of the two boxes, w and h represent the width and height of the predicted box, wg and hg represent the width and height of the true value box, px and py represent the weights along the horizontal and vertical directions, scale calculates the average size of the annotated box in a certain data set, M in scale represents the number of images in the data set, and N in scale i Indicates the number of annotation boxes in the i-th image. ij ,hg ij Represents the width and height of the jth true value box in the i-th picture in the dataset.
[0039] When the shape of the true value box is a square, its length and width are equal, and the weights px and py are both 1. At this time, the movement of the prediction box along the length and width tends to be consistent with the change in IoU; when the shape of the true value box is a rectangle, there is a difference in its length and width. At this time, the movement of the prediction box along the short side or along the long side will affect the final result. For a true value box with a long side in the horizontal direction and a short side in the vertical direction, if it moves up or down along the short side in the vertical direction, the change in the corresponding IoU value is more significant than moving left or right along the long side in the horizontal direction. Through the weights of the length and width in the true value box, the movement of the regression sample is biased towards the direction with smaller IoU value changes.
[0040] 4. When the predicted box contains the true value box, as shown in the attached Figure 3 When the true value box contains the predicted box, as shown in the attached Figure 4 As shown, the loss function expression is L EEIoU2 :
[0041]
[0042] S GT =wg×hg,S BB =w×h
[0043] d left =py×(x-xg1) 2 +px×(y-yg1) 2
[0044] d right =py×(xg-x2) 2 +px×(yg-y2) 2
[0045] In the formula, S GT Represents the area of the truth box, S BB Represents the area of the prediction box. The different inclusion situations of the two boxes are distinguished by calculating the area difference between the true value box and the prediction box and the distance between the center point and the left and right corner points. The area penalty item adjusts the loss through the area difference of the non-overlapping area, so that it has the ability to handle different inclusion relationships. When the area difference of the non-overlapping area increases, the difference between the true value box and the prediction box becomes larger, and the value of the penalty item should be increased to quickly adjust the impact of the area difference on position regression; when the area difference continues to increase, the penalty value should become a slow increase to avoid the problem of loss value explosion. If the area difference between the true value box and the prediction box is equal, it can be distinguished by the corner point distance penalty item of the second item, where d left The calculation is the square weighted value of the distance from the center point (x, y) of the prediction box to the upper left corner point (xg1, yg1) of the true value box, d right The calculated value is the square weighted value of the distance from the center point of the true value box (xg, yg) to the lower right corner point of the predicted box (x2, y2).
Claims
1. A bounding box regression loss calculation method based on inclusion relationship, characterized in that: It includes the following: (1) When the true value box and the predicted box are not contained, the regression loss function is constructed based on the EIoU function, and the weights px and py along the horizontal and vertical directions are added on this basis. (2) When the true value box and the predicted box are contained, that is, when the predicted box contains the true value box or the true box contains the predicted box, the regression loss function is constructed based on e -x +1, and on this basis add a penalty term related to the area of the non-overlapping region of the two boxes, and a penalty term related to the distance between the center points of the two boxes and their left and right corner points.
2. The method for calculating bounding box regression loss based on inclusion relationship according to claim 1, characterized in that: In content (1), the bounding box regression loss calculation expression is: In the formula, (x, y) represents the coordinates of the center point of the predicted box, (xg, yg) represents the coordinates of the center point of the true value box, c represents the diagonal distance of the maximum circumscribed rectangle of the two boxes, and c w and c h Respectively represent the width and height of the maximum circumscribed rectangle of the two boxes, w and h represent the width and height of the predicted box, wg and hg represent the width and height of the true value box, px and py represent the weights along the horizontal and vertical directions, and the calculation methods of px and py are as follows: Scale calculates the average size of the annotation box in a data set. The M in scale represents the number of images in the data set. i Indicates the number of annotation boxes in the i-th image. ij ,hg ij Represents the width and height of the jth true value box in the i-th picture in the dataset.
3. The method for calculating bounding box regression loss based on inclusion relationship according to claim 1, characterized in that: In content (2), the bounding box regression loss calculation expression is: S GT =wg×hg,S BB =w×h d left =py×(x-xg1) 2 +px×(y-yg1) 2 d right =py×(xg-x2) 2 +px×(yg-y2) 2 In the formula, S GT Represents the area of the truth box, S BB Represents the area of the prediction box, d left The calculation is the square weighted value of the distance from the center point (x, y) of the prediction box to the upper left corner point (xg1, yg1) of the true value box, d right The calculated value is the square weighted value of the distance from the center point of the true value box (xg, yg) to the lower right corner point of the predicted box (x2, y2).