# Improved Lightweight YOLOv4 Foreign Object Detection Method for Conveyor Belts Combined with CBAM
## 1 Introduction
Compared with the latest YOLOv7 algorithm, the precision of this study was the same as YOLOv7: the detection speed was better than YOLOv7, and the parameters and model complexity were far less than YOLOv7. This enabled our solution to be deployed on devices with limited resources, such as embedded systems. The improved method in this paper could be applied to other algorithms for the real-time detection of foreign objects. Our dataset contained seven foreign objects: gangue, screw, nut, angle iron, wooden stick, U-shaped iron, quadruped, etc. The size and shape of the foreign objects varied, and there were more small target objects. In the complex background environment, foreign objects were easily confused with the background as especially the shape, size, and color of gangue and coal are similar, which makes it difficult to detect. In transportation, detecting foreign objects moving at a high speed in an underground conveyor belt is challenging. The detection accuracy is low, and the speed is slow. We should suppress irrelevant information in the background, enhance the feature extraction ability of foreign objects, and adopt the detection method of a lightweight model to improve detection accuracy and speed. The conveyor belt is in a complex environment; therefore, we had to design a lightweight, high-precision, real-time foreign object detection model. By combining YOLOv4 [29; 30; 31; 32; 33] and GhostNet, we designed a YOLOv4 lightweight conveyor belt foreign object detection method incorporating CBAM. Under the condition of ensuring the high accuracy of YOLOv4, we used GhosNet to reduce the calculation and parameters of the model to improve the detection speed. In a complex background environment, foreign objects are easily confused with the background, and it is difficult to extract their feature information through feature extraction. We introduced the CBAM attention module to suppress irrelevant backgrounds and improve the ability of feature extraction in complex environments. The foreign objects on the conveyor belt had the characteristics of a significant size difference, and small target objects could easily miss detection. We used the kmeans++ clustering algorithm to optimize the dataset and obtain the suitable anchor box for foreign object target size, which could obtain better training results. In addition, our solution used GhostNet and depth-separable convolution to reduce the computational burden of YOLOv4, which enabled our solution to be deployed on devices with limited resources, such as embedded systems. The following points summarize the main contributions of the research and provide an efficient and accurate real-time foreign object detection method:  
1. Based on the YOLOv4 model, we proposed a lightweight and high-precision foreign object detection model;Under the condition of ensuring the high accuracy of YOLOv4, we used GhostNet to reduce the calculation and parameters of the model and improve the detection speed;
3. We integrated the CBAM module into the YOLOv4 network to improve the feature extraction capability and detection accuracy in complex environments;
4. We used the kmeans++ clustering algorithm to optimize the dataset and obtain the suitable anchor box for a foreign object target size;
5. We introduced deep separable convolution instead of a 3 \(\times\) 3 ordinary convolution in the model, which reduced the model's parameters and improved the detection speed. The structure of this paper consists of five main parts. In the first section, the critical problems and challenges in foreign object detection, especially in underground conveyor belt detection, and the great significance of solving these problems are expounded in detail. The second part introduces the principles of YOLOv4 and GhostNet, and the proposed model technology can be deeply discussed. The third section puts forward the methods to improve each module in detail, including Convolutional Block Attention Module, Deeply separable convolution, and the Anchor Frame Optimization Method.