# Transformer-Based Explainable Model for Breast Cancer Lesion Segmentation
## 3 Methodology
### Model Network Structure  
Figure 1 shows the model's framework, and Figure 2 illustrates its flowchart. The input image set is denoted as \(x\in R^{H\times W\times 3}\), where R represents all images in the dataset, and any individual image within this set is denoted as \(x\). Each image has a height \(H\), width \(W\), and 3 color channels. To convert the image information into sequential embeddings, the image set is first input into a patch partition layer. This layer divides the medical image pixels into non-overlapping patches of size \(N\times N\), transforming the feature dimensions into \(N\times N\times 3\) for each patch. Figure 1: Overview of the framework. The model begins with patch partitioning and linear embedding to transform input images into sequential data. The encoder consists of multiple swim transformer blocks, patch merging layers, and skip connections for feature fusion. The bottleneck layer processes the encoded features with Multi-Head Self-Attention (MSA) and Multi-Layer Perceptron (MLP) modules. The decoder includes patch expansion, normalization, and linear projection layers to produce high-resolution segmentation outputs. The output is processed through global average pooling and a softmax layer for pixel-level classification, with Grad-CAM used to visualize the results. \[x\in R^{H\times W\times 3}\to x_{p}\in R^{(H/N)\times(W/N)\times(N\times N\times 3)} \tag{1}\]  
The linear embedding layer performs feature mapping on these patches, projecting their feature dimensions into an arbitrary dimension, \(C\), resulting in feature maps. This operation can be expressed as  
\[x_{p}\in R^{(H/N)\times(W/N)\times(N\times N\times 3)}\to x_{p}^{\prime}\in R^{(H/N) \times(W/N)\times C} \tag{2}\]  
where \(R^{(H/N)\times(W/N)\times(N\times N\times 3)}\) represents the set of all patches, where any individual patch \(x_{p}\) in this set has a pixel height of \(\frac{H}{N}\), a pixel width of \(\frac{W}{N}\), and \(N\times N\times 3\) channels. \(R^{(H/N)\times(W/N)\times C}\) denotes the set of images processed by the linear embedding layer, where any image in this set has a pixel height of \(\frac{H}{p}\), a pixel width of \(\frac{W}{p}\), and \(C\) channels. The TEBLS model extracts image features through multiple downsampling and upsampling processes and fuses features from multiple levels. The encoder structure of the TEBLS model is as follows: the input data \(R^{(H/4)\times(W/4)\times C}\) are processed through three stages, and the bottleneck layer finally outputs \(R^{(H/32)\times(W/32)\times(C/8)}\). Specifically, the input data first pass through the first swin block, followed by a patch merging layer, then enter the  
Figure 2: The flowchart illustrates the main structure and data flow of TEBLS. The rounded rectangles represent the input and output modules of the model, while the gray rectangles indicate the input data preprocessing module. The blue rectangles represent the transformer-based dense nested feature fusion network module proposed in this paper, with the green rectangular frames representing the encoder and decoder parts of this module, which consist of three swin transformer blocks and swin transformer upsampling, respectively. The yellow rectangles represent the lightweight channel enhancement method based on the multi-scale features module proposed in this paper, which includes group convolution and channel transformation. second swin block, followed by another patch merging layer, and finally proceed through the third swin block and another patch merging layer before being input into the bottleneck layer. Each swin block consists of a single swin transformer module. The patch merging layer selects elements at regular intervals in the row and column directions, concatenates them into a tensor, and reshapes them. Channel normalization and a fully connected layer are then applied to adjust the channel dimensions. Through this process, feature resolution gradually decreases while feature dimensions increase, achieving downsampling.