# ResGDANet: An Efficient Residual Group Attention Neural Network for Medical Image Classification
## 3 Methodology
### RMT Module  
Medical image lesions exhibit significant variations in morphology and orientation, while traditional deep learning models lack rotational invariance learning capabilities, making it difficult to accurately identify lesion features at different angles. In response to  
Figure 4: Gated Fusion Unit. This module accepts two inputs, uses a sigmoid function to generate weights, and outputs the weighted sum of the two components.  
this issue, we introduce the RMT module [16], shown in Figure 5, which integrates the global context modeling strengths of Vision Transformers and the retention mechanism from Retentive Networks, enabling the effective incorporation of spatial prior knowledge and the extraction of rotation-invariant features.  
Through self-attention mechanisms alongside explicit spatial prior information, the RMT module learns stable features under rotational transformations, enhancing its ability to extract features from lesions of various morphologies. The module employs a two-dimensional distance-based decay matrix and utilizes the Manhattan Self-Attention (MaSA) mechanism for computation along both image axes, reducing the computational burden associated with extensive annotations. This design is particularly suitable for capturing morphologically diverse lesion features in medical images.  
The RMT module's output can be expressed as:  
\[X_{out}=MaSA(X)+LCE(V) \tag{13}\]  
Here, \(X_{out}\) is the output feature of the RMT module, \(MaSA(X)\) is the output of the Manhattan self-attention mechanism, \(LCE(V)\) is the output of the local context enhancement module based on depthwise convolution (DWConv), and \(V\) is the value matrix of the input feature map. LCE denotes the local context enhancement module employing Depthwise Separable Convolution (DWConv), while MaSA decomposes into two image axes, as shown in Equation (14). To be precise, the attention scores are derived individually for the horizontal and vertical dimensions. Subsequently, the attention weights are modified using one-dimensional bidirectional decay matrices.  
\[\begin{array}{l}Atten_{H}=Softmax\big{(}Q_{H}K_{H}^{T}\big{)}\odot D^{H}\\ Atten_{W}=Softmax\big{(}Q_{W}K_{W}^{T}\big{)}\odot D^{W}\\ MaSA(X)=Atten_{H}\big{(}Atten_{W}V\big{)}^{T}\end{array} \tag{14}\]  
In Equation (14), \(Atten_{H}\) and \(Atten_{W}\) represent the attention weights computed along the horizontal and vertical axes, respectively. \(Q_{H}\) and \(Q_{W}\) are the query matrices along the two axes, \(K_{H}\) and \(K_{W}\) are the key matrices along the two axes, \(D_{H}\) and \(D_{W}\) are the decay matrices along the two axes, and \(\odot\) denotes element-wise multiplication (Hadamard product).  
The RMT module integrates spatial prior information explicitly into the self-attention mechanism, strengthening its ability to interpret spatial relationships. Through the application of spatial priors and attentional allocation mechanisms, the module achieves reduced computational overhead while preserving linear complexity. The rotational invariance property improves the robustness of lesions in any direction, significantly enhancing the  
Figure 5: RMT module: 3 \(\times\) 3 DWConv, LN, Manhattan self-attention, FFN, with residual connections.  
detection accuracy of abnormal tissues in medical images. This characteristic offers significant advantages in processing lesions of various angles and morphologies, helping to improve the accuracy of medical image classification.