# Study of Surface Defect Detection Techniques in Grinding of SiCp/Al Composites
## 2 Detection Process of Surface Defects in SiCp/Al Composites
### Detection Model for SiC/Al Composite Surface Defects  
As shown in Figure 4, YOLOv4 consists of a backbone network (CSPDarknet53), a neck network (SPP and PANet), and a predictive network (YOLOHead). The CSPDarknet53 network consists of a CBM module and a CSP module. The CSP module consists of down sampling and n residual blocks with values of 1, 2, 8, and 4 in the backbone network, respectively. The advantage of adding the CSP module is that it ensures that the amount of computation does not increase much while still obtaining a comparable network depth, and the use of skip connections mitigates the vanishing gradient problem caused by increasing network depth.  
Figure 3: The images of several samples.  
Figure 2: Workpiece after grinding machining.  
The neck network consists of an SPP structure and a PANet structure. The output of CSPDarknet53 is processed with three convolutions as input to the SPP structure, and then the four pooling kernels of different sizes included in the SPP structure are used for max pooling and the pooled feature maps are concatenated as the output. The use of the SPP module increases the reception of backbone features more effectively than simply using a single-size pooling kernel for max pooling, significantly separating the most important contextual features. PANet is a combination of FPN and PAN structures. The FPN layer is able to capture strong semantic features from the top to bottom, while PAF conveys strong localization features from the bottom to top. By combining these two modules, more accurate target location information can be obtained.  
YOLO-Head uses multi-scale features obtained from the PANet structure for regression and classification prediction. The scales of output feature maps in YOLO-Head are (19, 19, 18), (38, 38, 18), and (76, 76, 18), respectively. Each grid cell in the YOLOv4 output feature map contains three anchors, and each anchor contains five basic parameters (x, y, w, h, confidence) and i category parameters. Since there is only one defect category (pits), the value of i is 1. Thus, the third dimension of the feature map of YOLO-Head is 18 (3 \(\times\) (5 + 1)).  
YOLOv4 has an initial nine anchors, each of which contains two parameters: the length and width of the anchor. In order for the detection model to learn the target locations quicker during training and thus speed up the training process, K-means clustering is employed to compute the appropriate anchor size for the defect dataset. Nine labeled boxes are randomly selected as the clustering centers of the K-means, and then the similarity between all labeled boxes and these nine clustering centers is calculated. Based on the similarity calculation, labeled boxes are assigned to different cluster centers, which are then  
Figure 4: Structure of YOLOv4 algorithm.  
updated based on the average of the samples contained in each cluster center. The above steps are repeated until the clustering is complete. The values of the anchors under the different feature maps obtained through clustering are given in Table 3.  
In addition, in order for the neural network to pay different levels of attention to the input data and perform feature extraction more effectively on the target identified, the Efficient Channel Attention (ECA) module is introduced into the defect detection model. In general, the addition of the attention module increases the complexity of the neural network and the amount of computation. The ECA module is lightweight and thus results in little increase in the number of network parameters and does not have a large impact on the complexity of the neural network. Compared with CBAM, SENet, and other modules, the ECA module can achieve better performance with a smaller number of parameters.