# Airwave Noise Identification from Seismic Data Using YOLOv5
## 3 The Basic Principles of YOLOv5
### Output Layer and Loss Function
To address this, this study implements the Non-Maximum Suppression (NMS) algorithm [46] to remove redundant anchor boxes from multiple detections, retaining only the boxes that are most likely to contain objects (see Figure 3). The NMS process involves calculating the IoU between the highest-confidence predicted boxes. An IoU threshold is established to dictate the maximum allowable overlap between two boxes, typically set between 0.3 and 0.5. Any boxes with an IoU greater than the specified threshold are suppressed (i.e., removed from the list). For multiple anchor boxes with high IoU values, a weighted average based on confidence is computed to create a new bounding box, which is then preserved as the final predicted box. In this paper, the loss function is primarily composed of two components: confidence loss \(\mathrm{L_{conf}}\) and localization loss \(\mathrm{CIoU}\). Confidence loss is utilized to calculate the probability of an object being present within each predicted bounding box. This is achieved using the binary cross-entropy loss function [47]:  
\[\mathrm{L_{conf}}=-\sum_{n=1}^{2}y_{n}^{*}\mathrm{log(y_{n})}+(1-y_{n}^{*}) \mathrm{log(1-y_{n})} \tag{2}\]  
where N represents the total number of classes, \(\mathrm{y_{n}}\) is the predicted probability for the current class after applying the Sigmoid activation function, and \(y_{n}^{*}\) is the true label for that class, where 0 indicates background and 1 indicates the presence of an object. Localization loss measures the error between the predicted bounding box and the ground truth box. In YOLOv5m, commonly employed localization loss functions include Generalized Intersection over Union (GIoU) loss and Complete Intersection over Union (CIoU) loss. These loss functions enhance the original IoU loss to better accommodate  
Figure 3: The diagram illustrates the grid division (black grid lines), marked boxes or label (yellow bounding boxes), prior anchor boxes (red bounding boxes), and the non-maximum suppression process. Since only one class is predicted, each predicted unit greater than the IoU threshold (indicated in purple) corresponds to three anchor boxes, which are merged into one by the non-maximum suppression algorithm. (Modified form [[https://cloud.tencent.com/developer/article/11](https://cloud.tencent.com/developer/article/11)]([https://cloud.tencent.com/developer/article/11](https://cloud.tencent.com/developer/article/11)) 18040 (accessed on 1 January 2020)). cases of non-overlapping or partially overlapping boxes. The CIoU loss is defined by the following formula, which integrates IoU loss, center distance loss, and aspect ratio loss:  
\[\text{CIoU}=1-\text{IoU}+\frac{\rho^{2}(\text{b},\text{b}^{\text{g}})}{\text{c}^{ 2}}+\alpha\text{v} \tag{3}\]  
where IoU represents the Intersection over Union between the predicted and ground truth boxes, \(\rho^{2}(\text{b},\text{b}^{\text{g}})\) denotes the diagonal length of the smallest enclosing box that contains both the predicted and ground truth boxes, where b and b represent the center coordinates of the predicted box and the ground truth box, respectively. \(\alpha\) serves as a balancing parameter to weigh the IoU loss against the aspect ratio loss, and v quantifies the difference in aspect ratios between the predicted and ground truth boxes. To compute the Intersection over Union (IoU), it is essential to first derive the coordinates of the predicted bounding box, which are represented by offsets. These offsets indicate the displacement of the bounding box's center point relative to the top-left corner of the predicted grid, as well as the scaling of the bounding box's width and height in relation to the anchor box. Let the predicted offsets be denoted as \(\left(\text{t}_{\text{x}},\text{t}_{\text{y}}\right)\).