## 3 Methodology
### MPDIoI Loss  
Intersection Over Union (IoU) is a simple metric that measures positional loss and the overlap between two bounding boxes by dividing the area of intersection by the area of union. In the original YOLOv7 algorithm, the CIoU loss function computes the coordinate regression loss using the following formula.  
\[CIoU=IoU-\frac{\rho^{2}(b,b^{8})}{c^{2}}-\alpha\cdot v \tag{5}\]  
Here, \(p(b,b^{8})\) represents the Euclidean distance between the center points of the predicted box \(b\) and the ground truth box \(b^{8}\), which measures the predicted box's spatial proximity to the ground truth box. \(c\) denotes the diagonal length of the smallest enclosing box. \(\alpha\) and \(v\) are the evaluation parameter and the aspect ratio balance factor, respectively.  
While CIoU considers factors such as intersection area, center point distance, and aspect ratio to evaluate bounding box overlap, its approach to calculating aspect ratio needs to be revised to represent the true disparities in width and height between the predicted and ground truth boxes. More attention must be paid to the problem of uneven sample quality, which might lead to a diminished convergence rate for the model. Therefore, to more effectively tackle the regression problem related to overlapping and non-overlapping bounding boxes while accounting for centroid distances and variances in width and height, we choose the MPDIoU loss function rather than CIoU. MPDIoU relies on the similarity metric of the lowest point distance between bounding boxes and immediately minimizes the distance between the upper-left and lower-right corners of the predicted and ground truth boxes, thus streamlining the computational process. The formula for its computation is as follows.  
\[d_{1}^{2}=\left(x_{1}^{B}-x_{1}^{A}\right)^{2}+\left(y_{1}^{B}-y_{1}^{A}\right) ^{2}, \tag{6}\]  
\[d_{2}^{2}=\left(x_{2}^{B}-x_{2}^{A}\right)^{2}+\left(y_{2}^{B}-y_{2}^{A}\right) ^{2}, \tag{7}\]  
\[MPDIoU=\frac{A\cap B}{A\cup B}-\frac{d_{1}^{2}}{w^{2}+h^{2}}-\frac{d_{2}^{2}} {w^{2}+h^{2}}, \tag{8}\]  
\[IoU=\frac{A\cap B}{A\cup B}, \tag{9}\]  
Figure 7: Detection head reconstruction.  
\[MPDIoU=IoU-\frac{d_{1}^{2}}{w^{2}+h^{2}}-\frac{d_{2}^{2}}{w^{2}+h^{2}}, \tag{10}\]  
\[LOSS_{MPDIoU}=1-MPDIoU, \tag{11}\]  
Here, \(w\) and \(h\) are the width and height of the predicted box, respectively. \(A\) and \(B\) are the predicted box and ground truth box, respectively. \(\left(x_{1}^{A},y_{1}^{A}\right)\) and \(\left(x_{2}^{A},y_{2}^{A}\right)\) represent the upper-left and lower-right t coordinates of bounding box \(A\), respectively.\(\left(x_{1}^{B},y_{1}^{B}\right)\) and \(\left(x_{2}^{B},y_{2}^{B}\right)\) represent the upper-left and lower-right coordinates of bounding box \(B\), respectively.  
MPDIoU effectively promotes the predicted box to align more closely with the ground truth box, whether their centroids overlap or not, thereby preventing loss function failure. In addition, the detection task of cigarette and phone objects considers attributes such as shape and size. By incorporating factors like diagonal length, MPDIoU allows the model to detect and localize objects more accurately, enhancing both convergence speed and regression accuracy.