# Combining the Transformer and Convolution for Effective Brain Tumor Classification Using MRI Images
## 3 Research Methodology
### Transformer Pathway  
The CNN progressive features extractor are intended to receive further global guidance from the transformer pathway. The convolution operations are used to project the tensor onto a high-dimensional space with 768 channels before the first transformer stage. Therefore, the transformer uses local information of the convolutional layer. This is consistent with the finding that adding locality to the first layers of transformers improves feature representation [60; 61]. The CNN's feature maps are flattened to the size of patches (B \(\times\) H \(\times\) W \(\times\) C) in each step of the transformer, where B denotes the batch size, C the number of channels, and H and W are the height and weight of the feature maps, respectively. As a result, every pixel is treated as an individual PE. The feature maps of spatial dimensions are flattened, and the patch sequence is then fed to the transformer dimension. We now include a trainable class token with these patches. In the typical vision transformer, the final prediction is made using the class token, which is used to collect class-specific data during training [62]. This trainable token is used in the proposed technique along with feature maps in the FFM to offer global features. The TECNN consists of four transformer stages, where a Transformer used a local and global pathway. The global pathway makes a decision on the entire image and the local pathway learns the tumor information form a local patch as shown in Figure 4. In this work we fuse the local and global information to improve the performance. In each stage of transformer, two repeating transformer blocks are used as shown in Figure 5. Each transformer block has multi-layer perceptron (MLP) blocks and multi-head self-attention (MSA) layers, as can be seen Figure 5. Before each MSA and MLP, layer norm is used in this case. In MSA, the input of size B \(\times\) H \(\times\) W \(\times\) C is converted to a query: Q \(\in\) B \(\times\) H \(\times\) W \(\times\) D\({}_{q}\), key K \(\in\) B \(\times\) H \(\times\) W \(\times\) D\({}_{q}\), and value V \(\in\) B \(\times\) H \(\times\) W \(\times\) D\({}_{p}\) matrices. Here, C, \(D_{q}\), and \(D_{V}\) are the aspects of the input, query matrix, and value matrix, including both. The self-attention is then expressed as follows,  
\[\text{Attention (Q, K, V)}=\sigma\left(\frac{QK^{T}}{\sqrt{Dv}}\right)\text{ V} \tag{1}\]  
where \(\sigma(\cdot)\) indicates the SoftMax function. To create the MSA layer, self-attention is carried out head (h) times. There are two adjoining layers in the MLP block, followed by a GELU activation function, where the first layer projects PE to 3072 dimensions and the second layer projects them to 768 dimensions.  
Figure 4: Represents the Transformer Pathway for collecting local and global features.  
The following can be used to express the full procedure in a transformer block.  
\[T_{output}^{\text{MSA}}=MSA\ \big{(}\tau\big{(}T_{input}\big{)}\big{)}+T_{input} \tag{2}\]  
\[T_{output}=\text{MLP}\ \big{(}\tau\big{(}T_{output}^{\text{MSA}}\big{)}\big{)}+T_{output }^{\text{MSA}} \tag{3}\]  
where \(T_{output}^{\text{MSA}}\) indicates MSL layer output, \(T_{output}\) is Transformer blocks output, \(T_{input}\) is the transformer stage input, and \(\tau(\cdot)\) is the layer normalization function.