# Few-Shot Steel Defect Detection Based on a Fine-Tuned Network with Serial Multi-Scale Attention
## 3 Methodology
### Proposed Serial Multi-Scale Attention Mechanism  
In this work, we introduced an innovative attention mechanism termed SMSANet, which operates within a hybrid domain. As depicted in Figure 3, the structure of this attention mechanism is divided into two core modules. The first module, named 'Split', initially partitioned the feature map into multiple groups. Within each of these divisions, 'Shuffle' units integrated channel and spatial attentions. Sub-features were aggregated, and the exchange of information across these sub-features was facilitated through the utilization of a 'channel shuffle [36]' operator. The technique known as 'Channel shuffle' is employed within convolutional neural networks (CNNs) with the aim of enhancing the network's non-linear capacity and representation ability. Its fundamental principle involves rearranging split input channels (or feature maps) to introduce randomness and mixing, thereby augmenting feature diversity and inter-channel correlations. This approach involves grouping input channels, followed by reordering and convolution operations, culminating in the concatenation of convolutional results to form the output.  
Figure 3: Structure of the proposed SMSANet.  
Figure 2: Structure of the proposed few-shot defect detection network.  
Progressing to the second module, the serial multi-scale attention module, we refined the approach from parallelism to a serial configuration. This involved channel attention being sequentially followed by spatial attention. Finally, it outputs a feature map that incorporates both channel and spatial information.  
In considering the order of channel and spatial attention mechanisms, we built the model upon the serial attention mechanism proposed by [PERSON] et al. [37]. Their comparative experiments demonstrate that positioning the channel attention mechanism before the spatial attention mechanism can optimize model performance. Consequently, this research adopts their sequence of attention mechanisms.  
For channel attention, the feature map was divided into four branches: A, B, S, and D. After reshaping branches A and B to C \(\times\) N dimensions, a product of branch B and the transposed branch A was obtained. Following a softmax operation, a C \(\times\) C feature map M was acquired. Matrix multiplication, in essence, establishes connections between each pixel point. When the similarity between two positions is higher, the corresponding \(M_{ij}\) also increases accordingly. This interconnection among different parts of the image enhances their mutual interaction, leading to a more effective capture of the correlations between various positions.  
\[M_{ji}=\frac{\exp\bigl{(}A_{i}\cdot B_{j}\bigr{)}}{\sum_{i=1}^{C}\exp\bigl{(}A _{i}\cdot B_{j}\bigr{)}} \tag{1}\]  
This map was then transposed and multiplied with the reshaped branch S and subsequently resized to C \(\times\) H \(\times\) W dimensions after scaling by a factor \(\beta\). Then, the result was added to the original branch D, providing a final feature map L that combines channel information.  
\[L_{j}=\beta\sum_{i=1}^{C}\bigl{(}m_{ji}C_{i}\bigr{)}+D_{j} \tag{2}\]  
Similarly, within the spatial attention module, three new feature maps were generated through convolutions, termed A, B, and C. The subsequent operations follow the same steps as those within the channel attention mechanism, but with an \(\alpha\) scaling factor in the spatial domain. After the sequential execution of these two modules, the final output was a fused feature map that integrates both channel and spatial information.