# McAW-YOLO: An Efficient Detection Model for Ceramic Tile Surface Defects
## 3 MCAW-YOLO Network Model
### IoU  
Intersection-over-union (IoU) is a metric used to measure the overlap between predicted and ground truth bounding boxes. In defect-detection models, intersection-over-union is often used as part of the bounding box regression loss function to improve the accuracy of the predicted boxes.  
The Complete-IOU bounding box regression loss function used in YOLOv5 and many of its variants introduced more geometric factors, leading to excessive penalties for low-quality samples and affecting samples with good overlap between predicted and target boxes, thereby reducing the robustness of the model. Additionally, Complete-IOU did not consider the issue of balancing hard-to-identify samples, causing the model to learn easy-to-classify samples while ignoring some complex samples to classify, which reduced the model's generalization ability. Therefore, this paper proposed using the Wise-IoU [23] bounding box regression loss function to address these issues, as shown in Equation (2).  
In this equation, \(\alpha\) and \(\delta\) control the shape of the focusing coefficient curve and adjust the weights of complex samples when the loss value stabilizes, and \({}^{*}\) indicates that the variable is detached from the computational graph. \(\sqrt[n]{0.05}\) is used to adjust the overall magnitude of the focusing coefficient. \(x\), \(y\), \(x_{gt}\), and \(y_{gt}\) represent the center coordinates of the predicted box and the ground truth box. \(W_{g}\) and \(H_{g}\) represent the width and height of the minimum enclosing rectangle of the predicted box and the ground truth box.  
\[\begin{split}\mathcal{L}_{WIoUt3}=r\mathcal{R}_{WIoU}\mathcal{L} _{IoU}\\ r=\frac{\beta}{\Delta\beta^{-\delta}},\alpha=1.9,\delta=3,\beta= \frac{\bar{L}_{IoU}}{\mathcal{L}_{IoU}}\\ \overline{\mathcal{L}_{IoU}}=(1-m)*\overline{\mathcal{L}_{IoU}}+m* \overline{\mathcal{L}_{IoU}}\\ m=1-\sqrt[n]{0.05},t=60,n=208\\ \mathcal{R}_{WIoU}=\exp(\frac{(x-x_{gt})^{2}+(y-y_{gt})^{2}}{(W_{ g}^{2}+H_{g}^{2})*})\end{split} \tag{2}\]  
Specifically, Wise-IoU constructs a dual-layer attention mechanism. It uses \(\mathcal{R}_{WIoU}\in[1,e]\) to amplify the error of regular predicted boxes and \(\mathcal{L}_{IoU}\in[0,1]\) to reduce the error of high-quality predicted boxes. At the same time, when there is a good overlap between the predicted boxes and the object boxes, it focuses on the distance between the centroids and the center point.  
Furthermore, \(\beta\) is introduced to increase the weight of difficult-to-classify defects in the loss function, focusing on challenging defects and reducing the model's classification errors. Then, based on \(\beta\), a non-monotonic focusing coefficient \(r\) is constructed to assign different gradient gains to better train the model. Predicted boxes with smaller \(\beta\) values have higher quality and are closer to the actual target boxes, so they are assigned smaller gradient gains, resulting in more minor corrections. This facilitates the model in quickly learning high-quality predicted boxes. Predicted boxes with larger \(\beta\) values typically have lower quality and overlap than target boxes. Smaller gradient gains are assigned to prevent the model from overly focusing on low-quality predicted boxes and reduce their harmful impact on bounding box regression. This allows the model to pay more attention to regular and higher-quality predicted boxes, reducing reliance on low-quality predicted boxes and thereby improving the model's robustness and generalization ability.  
By using the Wise-IoU loss function to address the issues of Complete-IOU, it is possible to obtain more accurate predicted bounding boxes, accelerate the training process, improve the training efficiency of the model, and enhance the network's performance.