# Enhanced YOLOv8 with BiFPN-SimAM for Precise Defect Detection in Miniature Capacitors
## 3 Materials and Methods
### WISE-IoU Loss Function  
In the field of machine vision, the YOLOv8 model uses the complete intersection over union (CIoU) method for bounding box regression loss computation, which is particularly useful in the complex task of detecting faults in microscopic capacitors. A highly regarded metric for object detection accuracy, the CIoU measures how well anticipated and real bounding boxes match. This is accomplished by calculating the Euclidean distance and taking the detection frame's aspect ratio into account, providing a thorough similarity measurement [33]. This method is essential for improving object localization and size estimation accuracy in a variety of settings.  
Nevertheless, the application of CIoU encounters notable challenges within datasets of tiny capacitor defects, which are characterized by their diminutive size and intricate defect patterns. These datasets frequently include samples of subpar quality due to the inherent complexity of such small-scale defects. In this context, CIoU's reliance on distance and aspect ratio metrics can disproportionately penalize these lower-quality examples. This bias may lead to a decline in the model's generalization capability, as it tends to overfit to these outlier samples, diminishing its efficacy in more typical scenarios.  
The weighted intersection over union (WIoU) technique, which includes a dynamic and non-monotonic focusing mechanism, was developed as a solution to this problem. It  
Figure 4: Neck feature network design: (**a**) FPN, (**b**) PANet, and (**c**) BiFPN.  
uses the dataset's \"outliers\" in a novel way to assess the anchor frame's quality [34]. This innovative strategy marks a notable stride forward in object detection, particularly in the challenging milieu of minuscule objects or complex backdrops. The WIoU methodology adeptly modulates its focus across different samples, mitigating the disproportionate impact of low-quality or extreme cases. By integrating the concept of \"outliers,\" WIoU offers a refined and effective means of assessing prediction quality, which is especially beneficial in datasets characterized by high variability or inconsistent quality. The formula for WIoU is outlined below:  
\[L_{WIoU}=R_{WIoU}L_{IoU} \tag{7}\]  
\[R_{WIoU}=\exp\left(\frac{\left(x-x_{gt}\right)^{2}+\left(y-y_{gt}\right)^{2} }{\left(W_{g}^{2}+H_{g}^{2}\right)}\right) \tag{8}\]  
\[L_{IoU}=1-IoU \tag{9}\]  
In the modified loss function \(L_{WIoU}\) used in YOLOv8, the \(R_{WIoU}\) term scales the \(IoU\) loss to focus on sample quality. The variables within \(R_{WIoU}\) are defined as follows:  
\(x\) and \(y\): The expected bounding box's center coordinates.  
\(x_{gt}\) and \(y_{gt}\): The coordinates of the ground truth bounding box's center.  
\(w_{g}\) and \(w_{g}\): The ground truth bounding box's height and width.  
The term \(R_{WIoU}\) is calculated using the exponential function to emphasize the influence of anchor frames closer to the ground truth by reducing the impact of those further away. The \(IoU\) loss \(L_{IoU}\) is the complement of the \(IoU\) between the predicted and ground truth bounding boxes, which inherently focuses on the overlap quality. In Equation (9), the loss function is modified to give priority to anchor frames of average quality and reduce the impact of extreme samples, improving the generalization capacity and overall performance of the model. By making this modification, the model is guaranteed to focus more on normal, high-probability samples and less on outliers, resulting in a more stable and efficient gradient throughout training.