# Industrial Image Anomaly Detection via Self-Supervised Learning with Feature Enhancement Assistance
## 3 Materials and Methods
### Multi-Scale Feature Aggregation  
The core of anomaly detection lies in distinguishing between feature representations of normal and anomalous data. To tackle the complexity and diversity of the data, researchers often employ pre-trained ResNet-like networks [44] as feature extractors. The initial layers of a ResNet network typically capture low-level features such as edges and textures of an image, whereas deeper layers are able to learn more advanced semantic concepts such as shapes, object parts, and even representations of the whole object. In anomaly detection, these multi-layered features can provide comprehensive information about different aspects of a data point thus helping to distinguish between normal and abnormal patterns.  
However, the direct use of all the extracted intermediate layer features results in a large number of redundant features and computations, although sufficient semantic and resolution information are obtained. Therefore, we process the features using an attention mechanism to filter out critical features.  
Our overall feature extraction process is illustrated in Figure 3. Firstly, the intermediate layer features \(f_{e}^{j}(x_{i})\) are obtained for each image through the feature extractor ResNet18, where \(j\in\{1,2,3\}\) represents the features from the first three layers, and \(x_{i}\) denotes both the normal images and their generated pseudo-abnormal images. Subsequently, the multi-semantic low-resolution features from layers 2 and 3 are upsampled to match the resolution of layer 1, and then merged into a preliminary aggregated feature \(f_{pa}\) through channel concatenation as follows:  
\[f_{pa}=Concat(f_{e}^{1},UP_{S1}(f_{e}^{2}),UP_{S2}(f_{e}^{3})|(W,H)), \tag{5}\]  
where \(UP_{S1}\) and \(UP_{S2}\) in Equation (5) denote the upsampling of \(f_{e}^{2}\) and \(f_{e}^{3}\) to the same resolution as \(f_{e}^{1}\), respectively. \([W,H]\) denotes the resolution of the feature map \(f_{e}^{1}\). The resolutions of \(f_{e}^{2}\) and \(f_{e}^{3}\) are \([W/2,H/2]\) and \([W/4,H/4]\), respectively.  
Subsequently, a \(1\times 1\) point-wise convolution is applied to the concatenated preliminary aggregated feature \(f_{pa}\) to initially fuse the channel information. The resulting fused feature, enriched with semantic information, is further enhanced by utilizing Coordinate Attention [45] to boost the representational power of the feature map and highlight crucial spatial location information, resulting in the intermediate aggregated feature \(f_{ia}\) as follows:  
\[f_{ia}=CA(PWC(f_{pa})), \tag{6}\]  
where \(CA\) denotes Coordinate Attention module, \(PWC\) denotes \(1\times 1\) point-wise convolution.  
The preliminary aggregated feature \(f_{pa}\) in Equation (5) encapsulates some fundamental yet pivotal information, while the intermediate aggregated feature \(f_{ia}\) in Equation (6), after convolution and channel attention processing, places greater emphasis on the important parts and details in the image. Combining these two features can integrate the rich information from the original features with high-level representations from the processed features, enabling the model to utilize more comprehensive and effective feature information in subsequent processing. Finally, two 3 \(\times\) 3 convolutions are applied to further refine the features and reduce the channel dimension to the target dimension, resulting in the final multi-scale aggregated feature \(f_{agg}\) as follows:  
\[f_{agg}=CONV_{2}(CONV_{1}(f_{pa}\oplus f_{ia})). \tag{7}\]