# Surgical Instrument Recognition Based on Improved YOLOv5
## 2 Materials and Methods
### YOLOv5 and Improve Methods
#### 2.2.2 IoU, GIoU, and Wise-IoU  
Intersection over union (IoU) is a metric commonly used in the context of object detection and segmentation tasks in neural networks [21]. It serves as a measure of the overlap between two bounding boxes or regions, providing an evaluation of a model's ability to predict object locations within an image accurately. IoU is calculated as the  
Figure 4: The architecture of the improved YOLOv5. Figure 5: The SE module. ratio of the intersection area between two bounding boxes (or regions) to their union area. Mathematically, it can be expressed as:  
\[IoU=\frac{|A\cap B|}{|A\cup B|} \tag{1}\]  
Then, IoU loss can be expressed as:  
\[LossIoU=1-\frac{|A\cap B|}{|A\cup B|} \tag{2}\]  
IoU values range from 0 to 1, where 0 indicates no overlap between the bounding boxes, and 1 represents a perfect match. Higher IoU values indicate better performance of the model in localizing objects. In practical applications, a threshold is often set to determine whether a predicted bounding box is classified as a true positive or a false positive. For instance, if the IoU threshold is set to 0.5, any predicted bounding box with an IoU of 0.5 or higher is considered a true positive relative to the ground truth bounding box. Conversely, predicted bounding boxes with lower IoU values are classified as false positives. The original YOLOv5 incorporates the generalized intersection over union (GIoU) metric, which was introduced by [PERSON] et al. in 2019 [PERSON] et al. (2019). GIoU aims to overcome the limitations of IoU, especially when predicted and ground truth bounding boxes are non-overlapping. It is defined as the difference between the IoU and a shape-aware penalty term that considers the geometry of the bounding boxes. The penalty term is calculated based on the smallest enclosing bounding box that contains both the predicted and ground truth bounding boxes, called the \"smallest enclosing box\", denoted as C. Then, it can be expressed as:  
\[GIoU=\frac{|A\cap B|}{|A\cup B|}-\frac{|C\backslash(A\cup B)|}{|C|} \tag{3}\]  
GIoU values range from \(-1\) to 1, with \(-1\) indicating the poorest conceivable match and 1 representing a flawless match. GIoU is an advancement over the standard IoU measurement, as it takes into account the geometry of bounding boxes and offers superior gradient data for the neural network training of object detection tasks. Nonetheless, GIoU also presents several issues, such as its sensitivity to object size scaling. This implies that the model performance may differ depending on the dimensions of the recognized objects. Sometimes, the model may find it challenging to identify smaller items or may create less precise boxing for more significant entities. Furthermore, the optimization process can cause GIoU loss function to be trapped in local minima. Consequently, this can induce suboptimal model performance, as the model may not attain the most satisfactory outcome. The Wise-IoU loss function incorporates weight factors derived from GIoU to address the issues posed by GIoU [PERSON] et al. (2019). The function assigns varying weights to distinct parts of the bounding box based on their significance for object detection. The Wise-IoU loss function is defined as follows:  
\[WiseIoU=IoU-\frac{|\lambda*(C-(A\cup B))|}{|C|} \tag{4}\]  
Among them, \(\gamma\) is an adjustable parameter employed to regulate the weight factor's magnitude. The Wise-IoU loss function incorporates a weight factor \(\lambda\) to provide a more accurate reflection of the positional relationship between predicted and real bounding boxes. The weight factor \(\lambda\) increases in value when the overlap between predicted and actual bounding boxes is minimal, resulting in greater sensitivity to changes to the former. Conversely, if there is a significant overlap between the predicted and actual bounding boxes, the weight factor \(\lambda\) assumes smaller values, leading to a gradual adjustment of the loss value regarding the predicted bounding box.