## 2 Materials and Methods
### Methods  
Firstly, we addressed the limitation of the Swin Transformer's attention operation within a single local window by implementing a region-to-region approach [40]. Specifically, we first executed a region segmentation operation, partitioning the input image X (with a height of H, a width of W, and a channel number of C) into smaller blocks of size H/S. We assumed H to be equal to W, and S was set to the square root of the number of regions post-segmentation. The tensor representation is achieved by dividing the space into S \(\times\) S distinct regions, each subjected to reshaping operations. This sequential aggregation forms a new tensor. The ensuing tensor's dimensions are denoted as (S \(\times\) S) \(\times\) (H/S) \(\times\) (W/S) \(\times\) C. For simplification, we can express (S \(\times\) S) \(\times\) (H/S) \(\times\) (W/S) as S\({}^{2}\) \(\times\) (H/S) \(\times\) (W/S) \(\times\) C. Further, (H/S) \(\times\) (W/S) \(\times\) C may be considered as a new dimension, reformulated as HW/S\({}^{2}\)\(\times\) C. Thus, our resulting tensor shape is S\({}^{2}\)\(\times\) HW/S\({}^{2}\)\(\times\) C. Here, S\({}^{2}\) corresponds to the number of regions, HW/S\({}^{2}\) quantifies the feature vectors within each region, and C indicates each feature vector's channel count. A linear projection on X then generates the query, key, and value information. \[\text{Q}=\text{X}^{\text{r}}\;\text{W}^{\text{q}}, \tag{1}\]  
\[\text{K}=\text{X}^{\text{r}}\;\text{W}^{\text{k}}, \tag{2}\]  
\[\text{V}=\text{X}^{\text{r}}\;\text{W}^{\text{v}}, \tag{3}\]  
where W\({}^{\text{q}}\), W\({}^{\text{k}}\), W\({}^{\text{v}}\)\(\in\) R\({}^{\text{C}\times\text{C}}\) are the respective projection weights of the query, key, and value. Subsequently, we determined the most relevant regions that require attention for each given area. By conducting average pooling on Q and K, we computed region-level queries and keys, denoted as Q\({}^{\text{r}}\) and K\({}^{\text{r}}\). The region adjacency matrix A\({}^{\text{r}}\) was calculated by multiplying Q\({}^{\text{r}}\) with the transpose of K\({}^{\text{r}}\). \[\text{A}^{\text{r}}=\text{Q}^{\text{r}}\;(\text{K}^{\text{r}})^{\text{T}}. \tag{4}\] \begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**Dataset**} & \multirow{2}{*}{**ID**} & \multirow{2}{*}{**Class**} & \multicolumn{4}{c}{**Numbers**} \\ \cline{3-6}  & & & **Subclass** & **Train** & **Test** \\ \cline{3-6}  & & & **Number** & **Train** & **Test** \\ \hline \multirow{6}{*}{Dataset1} & C1 & Debris Feldspar Sandstone & 1 & & \\  & C2 & Debris Quartz Sandstone & 1 & & \\  & C3 & Debris Sandstone & 1 & & \\  & C4 & Feldspar Debris Sandstone & 1 & & \\  & C5 & Feldspar Quartz Sandstone & 1 & & \\  & C6 & Feldspar Sandstone & 1 & & \\  & C7 & Quartz Debris Sandstone & 1 & 11,353 & 1360 \\  & C8 & Quartz Sandstone & 1 & & \\  & C9 & Floatstone limestone & 1 & & \\  & C10 & Grain Limestone & 1 & & \\  & C11 & Tricritic Limestone & 1 & & \\  & C12 & Packstone Limestone & 1 & & \\  & C13 & Quartz Debris Sandstone & 1 & & \\  & C14 & Quartz Sandstone & 1 & & \\ \hline \multirow{2}{*}{Dataset2} & \multicolumn{3}{c}{Metomorphic Rock} & 40 & \multirow{2}{*}{2185} & \multirow{2}{*}{449} \\  & & Sedimentary Rock & 28 & & \\ \cline{1-1}  & \multicolumn{3}{c}{Volcanic Rock} & 40 & \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Dataset statistics. Following this, we computed the index matrix \(\Gamma^{\prime}\) of the essential routing regions. This process involved pruning the affinity graph by retaining only the top k connections for each region. \[\Gamma^{\prime}=\text{topkIndex(A^{\prime})}. \tag{5}\]  
Thus, the ith row of \(\Gamma^{\prime}\) contains the k indices of the most relevant regions for the ith region. After obtaining the index matrix \(\Gamma^{\prime}\) of the routing regions, we carried out a token-to-token attention operation on these regions [41]. For each query token in region i, we gathered all key-value pairs located in the union of k routing regions indexed by \(\Gamma^{\prime}\).