# An Enhanced YOLOv5-Based Algorithm for Metal Surface Defect Detection
## 2 Methods
### FF-Slim-Neck Structure  
The depth of the network is increased with the introduction of GSConv, which increases the detection time significantly as shown in Figure 4. p1, p2, and p3 refer to the images whose sizes are \(128\times 80\times 80,256\times 40\times 40,512\times 20\times 20\) after the original images are processed by Backbone. Deeper networks can introduce more resistance to data flow, significantly increasing detection time. To address this issue, the design of the FedFusion Slim Neck (FF-Slim-Neck) structure is inspired by generalized approaches to CNN learning capabilities found in methods like DensNet [13], VoVNet [14], and CSPNet [15]. The FF-Slim-Neck structure incorporates GSConv, which may balance the trade-off between network depth and efficiency. This design allows the network to extract important features while keeping the computational cost and detection time at a reasonable level. The FF-Slim-Neck structure combines the advantages of GSConv with the principles of these  
Figure 4: Illustration of the Neck module with GSConv. Figure 3: Algorithm structure of GSConv. generalized CNN learning methods to achieve improved performance in detecting metal part defects. Local features pertain to data extracted from relatively compact or specific regions within the dataset. These features are generally employed to capture details and fluctuations in the data, focusing on local structures, and do not take into account the broader context of the entire dataset. In the case of images, local features might encompass small segments of an image, like edges, corners, or texture patterns. In contrast, global features encompass the information gathered from the entirety of the dataset or the entire data range. They are utilized to grasp the overarching context and global relationships within the data, facilitating a more comprehensive comprehension of the entire dataset. Incorporated into the FCConv model, as depicted in Figure 5, is the Federated Learning algorithm known as FedFusion [16], which is based on feature fusion techniques. The input image X undergoes transformation into two feature spaces, with the local feature extractor represented as \(E_{l}\) and the global feature extractor as \(E\). This transformation results in the generation of feature mappings, denoted as \(E_{l}(x)\), \(E_{g}(x)\in R^{C\times H\times W}\). Subsequently, \(E_{l}\) and \(E_{g}\) are embedded into the fusion feature space using a \(1\times 1\) convolution. The utilization of \(1\times 1\) convolutions serves as an effective strategy for dimensionality reduction within feature channels, imparting significant advantages in terms of computational complexity and model parameter count reduction. This approach effectively mitigates computational and storage requirements. \[F_{conv}\big{(}E_{l}(x),E_{g}(x)\big{)}=W_{conv}\big{(}E_{l}(x)\big{|}\big{|}E_ {g}(x)\big{)} \tag{1}\]  
\(W_{conv}\in R^{2C\times C}\) represents the learned weight matrix, and \(\mid\mid\) denotes the operation of concatenating feature maps along the channel axis. The GSConv and FedFusion are utilized in the Neck module to design the FF-Slim-Neck structure. The design of the cross-stage partial network FC module employs a one-step aggregation technique. This approach effectively lowers the computational complexity and reduces the inference time during the detection process. The FF-Slim-Neck architecture, depicted in Figure 6, streamlines the feature fusion process between local and global models at the feature extraction stage. The input feature map has the dimensions \(C_{1}\times H\times W\). It is processed through the Conv module, resulting in an output feature map of \(C_{1}/2\times H\times W\). Subsequently, the GSConv module generates another output feature map of \(C_{2}/4\times H\times W\). The feature fusion takes place through the FCConv module, resulting in an output feature map of \(C_{2}/2\times H\times W\).