## 2 Materials and Methods
### Methods  
This subsection describes the DL-based method for using the attention mechanism in the GI disease classification of multi-class and multi-sited endoscopic images. In step 1, unnecessary background features, text, and other artifacts were removed from each sample dataset during pre-processing. Images were resized to 224 \(\times\) 224 pixels for the experiments. As shown in Figure 1, the raw images that contained unnecessary background and text were removed during pre-processing, and the class balancing technique was applied with ECA-DDCNN [15]. Eighty percent of the data were used for training and 20% for testing. To avoid overfitting and imbalance, data augmentation techniques were used, such as transposing, flipping, rotating, random brightness, blurring, distortion, contrasting, and limited adaptive histogram equalization. After data augmentation, the total training data were comprised of forty thousand images. In step 2, the pre-processed data were utilized for the whole model's experiments. In step 3, disease detection and classification were implemented with attention mechanisms. In step 4, disease classification or lesion categorization of the proposed method was validated using 20% of the test data. Finally, in step 5, the output was evaluated quantitatively and qualitatively using appropriate evaluation metrics and visualization techniques as shown in Figure 2.  
In this work, we propose an attention network, a CNN, that adopts a mixed attention mechanism, as shown in Figure 3 (main network) and Figure 4 (sub-network). It comprises multiple attention layers/modules, which generate attention features by stacking layers to optimize the network [18]. The proposed model explores the performance of a robust classifier on CNN architecture. The spatial attention module compresses the channel and performs average and maximum pooling in the channel dimensions. The fully connected (FC) layers are then used to capture the non-linear cross-channel interaction, during which the complexity of the model is minimized by reducing dimensionality. The performance of the proposed approach was tested on the data used in training and validation. Attention features generated at stage 2 are shown in Figure 5.  
Figure 1: Raw input multi-class gastrointestinal endoscopy images. Respectively, (**a–d**) refers to pathological findings; (**e**) refers to artefacts and equipment; (**f–h**) refers to anatomical landmarks; and (**i,j**) refers to polyp removal images. (**a**) Esophagitis, which refers to an inflammation of the esophagus, visible as a break in the esophageal mucosa with the Z-line; (**b**) polyps are lesions within the bowel detectable as mucosal outgrows; (**c**) ulcerative colitis refers to a chronic inflammatory disease affecting the large bowel; (**d**) early esophagus cancer; (**e**) images with artefacts and diagnostic equipment; (**f**) the occur (the most proximal part of the large bowel); (**g**) The Z-line that marks the transition site between the esophagus and the stomach; (**h**) the pylorus (the area around the opening from the stomach into the first part of the small bowel, called the duodenum); (**i**) dyed-lifted-polyps; (**j**) dyed-resection-margins.  
Figure 2: A framework of the proposed GI disease classification method.  
Figure 4: Attention residual learning block.  
Figure 5: Sample heat map at stage 2 feature extraction of the proposed method. (**a**,**c**) demonstrate original images, class 0–9 respectively and (**b**,**d**) show attention features of all classes.  
Figure 3: Overall spatial attention CNN architecture of the proposed method.