# Optimization Algorithm for Surface Defect Detection of Aircraft Engine Components Based on YOLOv5
## 3 Improvement Methods and Improved Models
### Addition of Lightweight Upsampling Operator CARAFE  
In object recognition algorithms, upsampling is a commonly used operation that expands low-resolution object feature maps to higher resolutions. In convolutional neural networks, target features in higher-level feature maps are more abstract and have lower resolutions compared to lower-level feature maps. On the other hand, object features in lower-level feature maps are finer and have higher resolutions. By performing upsampling on the lower-level feature maps, their size can be expanded to match the size of the higher-level feature maps. This allows for the combination of fine-grained features from the lower-level feature maps with abstract features from the higher-level feature maps, enabling the transfer of detailed information from the lower-level feature maps to the higher-level feature maps. This integration of bottom-up and top-down features provides a  
Figure 4: The structure of NWD. more comprehensive representation of the target objects, thereby improving the accuracy and robustness of the object recognition algorithm in complex scenes. To achieve efficient feature map upsampling in deep neural networks, a Content-aware ReAssembly of Features (CARAFE) module was proposed by [PERSON] et al. [30]. This module is characterized by its versatility, lightweight design, and high efficiency. Compared to traditional upsampling modules, the CARAFE module utilizes local information to reassemble features instead of relying on simple interpolation or convolution operations. By introducing specialized resampling methods, it can expand the receptive field while preserving detailed features. Additionally, CARAFE does not depend on sub-pixel neighborhood operations but integrates information in a larger receptive field, enabling better content awareness. The CARAFE module can also dynamically generate adaptive kernels based on specific content, thereby improving the quality and accuracy of the feature map and demonstrating superior performance when handling different types of features. During the runtime of the CARAFE module, a predefined region is defined around each position as the center, and feature reassembly is performed using weighted combinations. This is achieved by generating weights in a content-aware manner. Multiple sets of generated upsampling weights are present at each position, and these weights are then rearranged to form a complete spatial block for feature upsampling. Specifically, given a feature map \(X\) of size \(C\times H\times W\) and an upsampling rate \(\sigma\) (assuming \(\sigma\) is an integer), a new feature map \(X^{\prime}\) of size \(C\times\sigma H\times\sigma W\) is generated as shown in Equations (1) and (2):  
\[W_{l^{\prime}}=\psi(N(X_{l},K_{encoder})) \tag{1}\]  
\[X^{\prime}_{l^{\prime}}=\phi(N(X_{l},K_{up}),W_{l^{\prime}}) \tag{2}\]  
For the \(X^{\prime}\) output above, a source position \(l=(i,j)\) in \(X\) can be found for any selected target position \(l^{\prime}=(i^{\prime},j^{\prime})\). Here, \(N(X_{l},k)\) is a \(k\times k\) subregion of feature map \(X\) centered at \(l\), and \(K_{up}\) is the size of the reassembly kernel, used to define the spatial range of each kernel. For performance and efficiency considerations, the convolution layer \(K_{encoder}\) with a kernel size of \(K_{up}-2\) is usually used. In Equation (1), \(\psi\) is the kernel prediction module that predicts the kernel \(W_{l^{\prime}}\) for each \(l^{\prime}\) based on the subregion of \(X_{l}\). The output is a reassembly kernel of size \(C_{up}\times H\times W\), where \(C_{up}\) refers to the number of channels in the reassembly kernel, which is used to specify the dimensionality of the reassembly kernel.