# NGIoU Loss: Generalized Intersection over Union Loss Based on a New Bounding Box Regression
## 2 Related Work
### Analysis to IoU and GIoU Losses  
Algorithm 1 provides the pseudocode of IoU Loss and GIoU Loss. IoU is a common indicator for evaluating the regression box detection. As a distance measure, IoU has the characteristics of non-negative, scale invariance, identity, symmetry, triangle inequality and so on. \(l_{1}\) and \(l_{2}\) losses are designed to calculate and add the losses of the four coordinates of the regression box, respectively, which may ignore their associativity and is hard to adapt to the evaluation indicator, IoU. Therefore, for two-dimensional object detection tasks, it is best to use IoU as the objective function. Between optimizing the indicator itself and replacing the loss function, the former is the best choice. Nevertheless, if IoU is directly used as the loss function, the training may not converge. As observed by line 6 of Algorithm 1, when the predicted regression box _bboxes_p_ and the ground truth regression box _bboxes_g_ have no intersection, that is, \(A_{c}=0\), and IoU is 0, there is no moving gradient to carry out learning and training. Meanwhile, the scale invariance of IoU will make the IoU Loss unable to accurately describe the overlap ratio of the predicted regression box _bboxes_p_ and the ground truth regression box _bboxes_g_. In view of the aforementioned shortcomings of the IoU Loss, [PERSON] et al. [16] proposed GIoU Loss. GIoU introduces the minimum closed convex shape _bboxes_q_ that surrounds the predicted regression box and the ground truth regression box when there is no overlap. From line 7 of Algorithm 1, GIoU adds a penalty term \(\frac{A_{b}-A_{D}}{A_{q}}\) on the basis of IoU. When the intersection of the two boxes is 0, GIoU still accurately measures the distance between them. It is observed by line 8 of Algorithm 1 that when the intersection is 0, \(L_{IoU}\) will fall into a platform area and no moving gradient is provided, while the penalty term of \(L_{GIoU}\) will make the predicted box move to the ground truth box and speed up the regression. ```
1:The predicted regression box \(bboxes\_p\) and the ground truth regression box \(bboxes\_g\). \(bboxes\_p=(x_{1p},y_{1p},x_{2p},y_{2p})\), \(bboxes\_g=(x_{1g},y_{1g},x_{2g},y_{2g})\). 2:IoU Loss, GIoU Loss. 3:Condition: Guarantee \(x_{2g}>x_{1g},y_{2g}>y_{1g}\)\(x_{2p}>x_{1p},y_{2p}>y_{1p}\). 4:The area of the predicted regression box and the ground truth regression box is as follows: \(A_{p}=(x_{2p}-x_{1p})*(y_{2p}-y_{1p})\)\(A_{g}=(x_{2g}-x_{1g})*(y_{2g}-y_{1g})\). 5:The intersection C of the predicted regression box and the ground truth regression box: The upper left coordinate of C: \((x_{1c},y_{1c})\), \(x_{1c}=\max(x_{1p},x_{1g})\), \(y_{1c}=\max(y_{1p},y_{1g})\). The lower right coordinate of C: \((x_{2c},y_{2c})\), \(x_{2c}=\min(x_{2p},x_{2g})\), \(y_{2c}=\max(y_{2p},y_{2g})\). Area: \(A_{c}=(x_{2c}-x_{1c})*(y_{2c}-y_{1c})\). 6:The union D of the predicted regression box and the ground truth regression box: Area: \(A_{D}=A_{p}+A_{g}-A_{c}\). 7:The minimum closed convex shape surrounding the predicted regression box and the ground truth regression box \(bboxes\_q\): The upper left coordinate of \(bboxes\_q\): \(x_{1q}=\min(x_{1p},x_{1g})\), \(y_{1q}=\min(y_{1p},y_{1g})\). The lower right coordinate of \(bboxes\_q\): \((x_{2q},y_{2q})\), \(x_{2q}=\max(x_{2p},x_{2g})\), \(y_{2q}=\max(y_{2p},y_{2g})\). Area: \(A_{q}=(x_{2q}-x_{1q})*(y_{2q}-y_{1q})\). 8:\(IoU=\frac{A_{c}}{A_{D}}\). 9:\(GIoU=IoU-\frac{A_{q}-A_{D}}{A_{q}}=\frac{A_{c}}{A_{D}}-\frac{A_{q}-A_{D}}{A_{q}}\). 10:\(L_{IoU}=1-IOU\), \(L_{GIoU}=1-GIoU\). ```  
**Algorithm 1** IoU and GIoU Loss function  
Although GIoU alleviates the non-overlapping problem of IoU, when the predicted regression box and the ground truth regression box completely overlap, the minimum closed convex shape \(bboxes\_q\) surrounding the predicted regression box, and the ground truth regression box is equal to the larger regression box. Then, the penalty term is 0, the GIoU Loss will degenerate into IoU Loss.