# Improved Lightweight YOLOv4 Foreign Object Detection Method for Conveyor Belts Combined with CBAM
## 4 Experiments
### Analysis of Experimental Results
Ghostnet-CBAM-YOLOv4 had a detection accuracy of 99.13% and a detection speed of 53.4 fps, which could meet foreign object detection under conveyor belt working conditions. The Intersection over Union (IoU) indicates the degree of overlap between the predicted bounding box and the real bounding box, and the larger the value, the better the performance of the detector. The visualization results in the test set could determine the degree of overlap between the predicted frame and the real frame, and the larger the value of the predicted frame in the visualization results, the higher the degree of overlap between the predicted frame and the real frame so as to accurately evaluate the performance of the bounding box generated by the proposed method. \[IoU=\frac{Area\ of\ Overlap}{Area\ of\ Union} \tag{17}\]  
Our model was initially evaluated using CIoU (Complete IoU). CIoU Loss considers the overlapping area, the center distance, and the aspect ratio of the predicted frame and the real frame. CIoU adds the loss of the detection frame scale and the loss of length and width on the basis of DIoU so that the prediction frame can be more in line with the real frame. However, the aspect ratio of CIoU describes the relative value; therefore, it is impossible to obtain more accurate results. The calculation formula for this is as follows. \[CIoU=IoU-\frac{p2\big{(}b,b^{gt}\big{)}}{c^{2}} \tag{18}\]  
where \(p2\big{(}b,b^{gt}\big{)}\) represents the Euclidean distance of the center point of the prediction box and the real box, respectively. \(c\) represents the diagonal distance of the smallest closure region that can contain both the prediction frame and the real frame. \[\alpha=\frac{v}{1-IoU+v} \tag{19}\]  
\[v=\frac{4}{\pi}\bigg{(}arctan\frac{w^{gt}}{h^{gt}}-arctan\frac{w}{h}\bigg{)} \tag{20}\]  
\[L_{CIoU}=1-IoU+\frac{p2\big{(}b,b^{gt}\big{)}}{c^{2}}+\alpha v \tag{21}\]  
MIOU (mean intersection over union) is the average of the intersection and union ratios for each class in the dataset. The calculation formula is as follows. In order to accurately evaluate the performance of the bounding box, we used MIoU as the evaluation index. Adding MIoU to the evaluation framework provided a more comprehensive and informative analysis of the performance of the proposed method. By measuring the overlap between the predicted bounding boxes and ground truth, MIoU provided a more reliable indication of the accuracy of the detections. The test results of this algorithm are shown in Table 4 and Figure 9.  
\[MIoU=\frac{1}{k+1}\sum_{i=0}^{k}\frac{P_{ii}}{\sum_{i=0}^{k}P_{ij}+\sum_{i=0}^ {k}P_{ij}-P_{ii}} \tag{22}\]  
\(i\) stands for true value, \(j\) stands for predicted value, and \(p_{\bar{\eta}}\) indicates that \(i\) is predicted as \(j\). It can be seen from Table 4 that under the same environment and experimental conditions, the average precision of our model improved by 0.19%, and 1.3 fps increased the detection speed using the MIOU evaluation standard. The precision of the model was 99.6%, and the recall was 98.7%. From Figure 9, it can be concluded that the average coincidence degree between the predicted frame and the real frame of various foreign objects was above 90%, indicating that the predicted frame and the real frame were basically coincident. The prediction frame generated by our algorithm showed good performance under the evaluation index of MIOU, which could solve various problems in complex environments and realize the real-time detection of foreign objects. In order to verify the performance of the model and show the superiority of our algorithm in complex environments, we used YOLOv4 and this algorithm to train on the conveyor belt gangue dataset under the same environment and experimental conditions; the test results are shown in Table 5 below. The GhostNet-CBAM-YOLOv4 model improved the average accuracy by 6.1%, the precision and recall by 5.2% and 4.3%, respectively, and the detection speed by 6.1 fps compared with the original model.