## 3 Correlation Algorithm
### Swin Transformer  
To overcome these limitations, the Microsoft Research Asia team proposed Swin Transformer (Swin) as an improvement over ViT. Swin introduces a hierarchical window mechanism that better captures local information and details in images through local window-level attention. Swin has achieved remarkable performance in image classification tasks and further advanced the development of transformer-based computer vision research. The structure of the Swin Transformer is illustrated in Figure 5.  
Swin consists of four stages, and the specific process is as follows:  
1. Image Patch Division and Linear Embedding: The original image is divided into uniform image patches with dimensions of \((H/4)\times(W/4)\), where H and W represent the height and width of the input image, respectively. Each image patch's feature dimension is then converted to C dimensions through linear embedding, where C corresponds to the number of channels in the Swin Transformer module. 2. Image Patch Merging and Convolutional Dimension Reduction: Adjacent image patches are merged to form larger image patches. This reduces the number of image patches, and each merged image patch contains more local contextual information. The merged image patches undergo a convolutional network for dimension reduction, reducing the feature dimension to half of its original size. This helps to extract more abstract features. 3. Repeat Stage 2: The process of image patch merging and convolutional dimension reduction in Stage 2 is repeated multiple times. With each repetition, the number of image patches is halved, and the feature dimension is also halved, while extracting higher-level feature representations. 4. Swin Transformer Module: After Stage 3, the input is passed to the Swin Transformer module for computation. This module is based on the transformer architecture and processes the input using self-attention mechanisms and feed-forward neural network layers. It learns global contextual information and feature relationships to improve the quality of feature representation. Figure 5: Architecture diagram of the Swin Transformer. The Swin Transformer adopts a window-based multi-head self-attention module called \"Windows Multi-Head Self-Attention\" (_W-MSA_) in place of the traditional multi-head self-attention mechanism (_MSA_) used in the original transformer module. _W-MSA_ is a modified version of self-attention specifically designed for attention calculation in the Swin Transformer. The computational complexities of _MSA_ and _W-MSA_ are as follows:  
\[\Omega_{MSA}=4 hwC^{2}+2(hw)^{2}C \tag{5}\]  
\[\Omega_{W-MSA}=4 hwC^{2}+2M^{2}hwC \tag{6}\]  
where \(C\) represents the depth of the image. \(h\) and \(w\) represent the height and width of the image. \(M\) represents the size of the window. Figure 6 illustrates two consecutive Swin Transformer modules. The input image features undergo layer normalization (LN) before being independently processed by the _W-MSA_ module and the multi-layer perceptron (MLP). Additionally, each module is connected to the other through a residual connection, and another layer normalization layer follows this connection. The computation process for feature propagation in the _W-MSA_ module can be summarized as follows:  
\[\underline{z}^{l}=f_{\text{W-}MSA}\Big{[}f_{LN}\Big{(}\underline{z}^{l-1} \Big{)}\Big{]}+\underline{z}^{l-1} \tag{7}\]  
\[\underline{z}^{l}=f_{MLP}\Big{[}f_{LN}\Big{(}\underline{z}^{l}\Big{)}\Big{]} +\underline{z}^{l} \tag{8}\]  
where \(\underline{z}^{l}\) and \(\underline{z}^{l}\) refer to the output features of the _W-MSA_ and _MLP_ modules, respectively. \(f_{W-MSA},f_{MLP}\), and \(f_{LN}\) represent the output functions of the _W-MSA_ module, _MLP_ module, and layer normalization, respectively. Due to the non-overlapping nature of the cropped image patches in the _W-MSA_ module, there is a lack of effective information interaction between the windows. To further enhance the model's performance, the shift window multi-head self-attention (_SW-MSA_) module is introduced.