# PRC-Light YOLO: An Efficient Lightweight Model for Fabric Defect Detection
## 3 Fabric Defect Detection Based on PRC-Light YOLO
### Wise-IOU v3 Bounding Box Loss  
The loss function of YOLOv7 comprises three parts: Bounding Box Loss (BoxLoss), Classification Loss (ClsLoss) and Object Confidence Loss (ObjLoss). Among them, the BoxLoss employs the Complete Intersection Over Union (CIOU) loss [37], and the ObjLoss and ClsLoss are calculated using the binary cross-entropy loss function. The YOLOv7 total loss expression is shown in Equation (7). \[Loss=Loss_{Obj}+Loss_{cls}+Loss_{Box} \tag{7}\]  
The CIOU loss in YOLOv7 considers three geometric factors: the overlap area between bounding boxes, the difference in aspect ratios and the distance between their center points. Given a target frame and a prediction frame, the CIOU loss is calculated as:  
\[L_{CIOU}=1-IOU+\frac{\sqrt{\left(i_{x}-j_{x}\right)^{2}+\left(i_{y}-j_{y} \right)^{2}}}{c^{2}}+\alpha\
u \tag{8}\]  
\[\alpha=\frac{\
u}{(1-IOU)+\
u} \tag{9}\]  
\[v=\frac{4}{\pi^{2}}(\arctan\frac{w^{gt}}{h^{gt}}-\arctan\frac{w}{h})^{2} \tag{10}\]  
The gradient of \(v\) with respect to \(w\) and \(h\) is calculated as follows:  
\[\left\{ \begin{array}{l}\frac{\partial v}{\partial w}=\frac{8}{\pi^{2}}( \arctan\frac{w^{gt}}{h^{gt}}-\arctan\frac{w}{h})*\frac{h}{w^{2}+h^{2}}\\ \frac{\partial v}{\partial h}=\frac{8}{\pi^{2}}(\arctan\frac{w^{gt}}{h^{gt}}- \arctan\frac{w}{h})*\frac{w}{h^{2}+h^{2}}\end{array} \right. \tag{11}\]  
\((i_{x},i_{y})\), \((j_{x},j_{y})\) are the center point coordinates of the real frame and the prediction frame, respectively, \(v\) measures the similarities in length ratios, \(\alpha\) represents the balancing parameter and the diagonal length of the smallest outer rectangle containing the true and predicted boxes is denoted by \(c\). Analysis of Equation (10) shows that when the aspect ratios of the predicted and real frame are equal, the penalty term related to the aspect ratio becomes 0. Thus, the aspect ratio penalty term loses its effect, which reduces the optimization performance of the model for similarity. From Equation (11), the relationship between \(\frac{\partial w}{\partial w}\) and \(\frac{\partial v}{\partial h}\) is inversely proportional, and during training, the simultaneous adjustment of both width and height dimensions in the prediction frame is not feasible. This constraint  
Figure 5: Activation function output curves. hinders the prediction frame from effectively approximating the dimensions of the real frame [38]. The CIOU employs a monotonic focus mechanism, which is predicated on the assumption that high-quality examples exist within the training data. Its primary objective is to enhance the fitting capability of bounding box loss. Nevertheless, when the target detection training dataset includes low-quality examples, indiscriminately emphasizing the regression of bounding boxes for these low-quality instances evidently leads to a deterioration in the model's detection performance [39]. Therefore, we employ Wise-IOU v3 as the bounding box loss, which incorporates a non-monotonic dynamic focusing mechanism. This mechanism relies on the outlier degree rather than IOU to assess the quality of anchor boxes, which diminishes the detrimental gradient caused by low-quality examples, mitigates the competitiveness of high-quality anchor boxes and improves the overall performance of the detector. The equations are as follows:  
\[R_{WIOU}=\exp(\frac{\left(i_{x}-i_{y}\right)^{2}+\left(j_{x}-j_{y}\right)^{2} }{\left(W^{2}+H^{2}\right)^{*}}) \tag{12}\]  
\[L_{w1}=R_{WIOU}*L_{IOU} \tag{13}\]  
\[r=\frac{\beta}{3\times 1.9^{\beta-3}} \tag{14}\]  
\[\beta=\frac{L_{IOU}^{*}}{L_{IOU}}\in[0,+\infty) \tag{15}\]  
\[L_{WIOU}=r*L_{w1} \tag{16}\]  
\(W\) and \(H\) represent the width and height, respectively, of the smallest outer rectangle of the real frame and the prediction frame and \(\left(W^{2}+H^{2}\right)^{*}\) denotes the separation of \(W\) and \(H\) from the Computational Graph to prevent \(R_{WIOU}\) from making gradients that impede convergence. \(L_{IOU}^{\gamma^{*}}\) is the monotonic focusing factor of \(L_{w1}\).