## 3 Instance Segmentation Framework Based on Improved YOLACT
### Improved Bounding Box Loss Function for Redundant Boxes  
The original YOLACT network uses Smooth L1 as the loss function for bounding boxes, which was proposed in Faster R-CNN. Smooth L1 can calculate the loss of the length and width of the prediction box and the offset of the horizontal and vertical coordinates of the center point, as shown in the following formulas:  
\[L_{smoothL1}=\sum_{i=\{x,y,w\}}SmoothL1\big{(}i^{st}-i^{p}\big{)} \tag{7}\]  
\[SmoothL1(\text{x})=\left\{ \begin{array}{ll}0.5x^{2},&if\ \ |x|<1\\ |x|-0.5,&otherwise\end{array} \right. \tag{8}\]  
In the above formulas, \(x^{p}\), \(y^{p}\), \(w^{p}\), and \(h^{p}\), respectively, represent the horizontal and vertical coordinates of the center point of the prediction box and the width and height of  
Figure 4: Structure of the improved FPN module combined with ECA. the prediction box, while \(x^{gt}\), \(y^{gt}\), \(w^{gt}\), and \(h^{gt}\), respectively, represent the horizontal and vertical coordinates of the center point of the ground truth box and the width and height of the ground truth box. This paper notes that, although YOLACT is a single-stage instance segmentation algorithm, its mask segmentation is not separated from object detection. In fact, although the prototype mask branch is independent from the Prediction module, the final instance mask segmentation quality of YOLACT still depends on the accuracy of the prediction boxes output by the Prediction module, so the quality of the prediction boxes also affects the segmentation quality. However, the Smooth L1 bounding box loss function ignores a lot of information, especially as it does not take into account three important pieces of information: area deviation, center deviation, and shape deviation. In the experiment, this paper found that the lack of this information in the Smooth L1 during training can lead to a low quality of the model's prediction box, thereby limiting the overall detection accuracy. For the insulator defect instance segmentation in this paper, due to the small size of the target instance, the detection of insulator defects is more sensitive to the area of the prediction box than a normal-sized target. It is likely for the instance segmentation algorithm to recognize the same target instance as multiple different instances, generating too many prediction boxes and leading to false detection and segmentation, ultimately reducing the accuracy of the model. As shown in Figure 5, this paper notes that the area of the redundant prediction box of these insulators is generally smaller than the area of the ground truth box, and it is very likely to appear inside the ground truth box. In response to the above situations, a new loss function, RIoU Loss (Restrained-IoU Loss), is designed, which includes factors such as the intersection over union, center deviation, and shape deviation between the generated box and the ground truth box in the bbox loss calculation range. Meanwhile, it increases the punishment for small prediction  
Figure 5: Redundant prediction boxes in insulator defect instance segmentation. boxes within the ground truth box and ultimately calculates the quality of the predicted box more accurately than the original loss function. According to the RIoU Loss function, the RIoU function is also obtained. The calculation process of RIoU Loss and RIoU is as follows:  
\[\text{RIoU Loss}=2(1-IoU)^{2}+\frac{x_{o}^{2}+y_{o}^{2}}{w_{c}^{2}+h_{c}^{2}}* IoU+arctan\bigg{(}\frac{w^{st}}{h^{st}}-\frac{w^{p}}{h^{p}}\bigg{)}^{2}*IoU^{2} \tag{9}\]  
\[\text{RIoU}=1-\text{RIoU Loss} \tag{10}\]  
In the above equations, \(x_{o}\) represents the difference between the ground truth box center abscissa and the predicted box center abscissa, while \(y_{o}\) represents the difference between the two vertical coordinates. Their sum represents the square of the distance between the two center points.