This section provides a comprehensive description of the proposed DL framework for brain tumor detection in MRI scans. The methodological pipeline encompasses data preparation, model selection, development, evaluation, and quantitative explainability analysis. Each stage is systematically structured to ensure reproducibility, transparency, and clinical reliability. The overall workflow is visually summarized in Fig. 1, which illustrates the integration of internal and external datasets, the training and validation strategy, and the incorporation of interpretability methods.
Fig. 1
Workflow diagram of the proposed DL framework for brain tumor detection. The diagram includes data preprocessing, mathematical formulations (Normalization, Grad-CAM, Integrated Gradients, Confidence Drop), algorithmic steps for patient-wise stratified fivefold cross-validation, and quantitative XAI metrics.
Study objective and design
This study aimed to develop and validate a DL model for brain tumor detection from MRI images, addressing two critical challenges in medical AI: limited dataset availability and lack of interpretability. This research was conducted in two phases. In the first phase, several experiments were performed to identify the most suitable DL architecture, optimizer, and hyperparameter configuration for this task (details provided in the Supplementary Material). In the second phase, a rigorous evaluation protocol was implemented. This included patient-wise cross-validation with stratified group folds, ensuring balanced representation across subsets, followed by independent external validation on unseen MRI data. The overall workflow of the proposed framework is illustrated in Fig. 1, which includes mathematical formulations, algorithmic steps, and quantitative XAI metrics.
Data description
This work utilizes three publicly available brain MRI datasets from Kaggle, illustrated in Table 2. The inclusion of both datasets allowed the model to be trained on a smaller but carefully curated dataset and then tested on a larger, independent dataset, thereby strengthening confidence in its robustness, generalization, and clinical applicability.
-
1.
Dataset A24: This dataset consists of 253 MRI images, divided into two categories: tumor (Yes) and non-tumor (No). The tumor class includes 155 images, while the non-tumor class comprises 98 images. Despite its smaller size, the dataset reflects real-world constraints in clinical data availability. This dataset is used for preliminary model selection and final training pool.
-
2.
Dataset B (Br35H 2020 dataset)25: This dataset comprises approximately 3,000 MRI images, organized into three folders: Yes (1,500 images of tumorous brains) and No (1,500 images of non-tumorous brains). This dataset was specifically curated to support the development of automated brain tumor classification systems using DL approaches such as CNNs. Its balanced distribution across tumor and non-tumor classes, combined with standardized preprocessing strategies, provides a robust benchmark for assessing model generalizability and validating classification performance. This dataset is employed for external evaluation on unseen data, used only for final independent testing (no patient overlap with Dataset A).
Table 2 MRI datasets summary.
Data preparation and model development
Preprocessing strategy
Preprocessing is a critical step in medical imaging workflows, as it reduces variability and enhances model performance. In this study, the preprocessing pipeline comprised the following steps:
-
1.
Resizing All images were resized to 224 × 224 pixels using nearest-neighbor interpolation, ensuring consistency with the input requirements of architectures such as VGG-1626 and InceptionV327.
-
2.
Normalization Pixel intensity values were scaled to the range [0–1], which stabilized the training process and accelerated convergence.
These preprocessing measures improved computational efficiency, facilitated more effective feature learning, and enhanced the model’s ability to detect brain tumors under heterogeneous conditions, including variations in shape, size, and orientation.
Preliminary model selection (exploratory phase)
To identify the optimal architecture, optimizer, and hyperparameters, preliminary experiments were conducted on the original internal dataset (Dataset A, 253 images) using two pre-trained architectures: VGG-1626 and InceptionV327. Their original fully connected layers, pre-trained on ImageNet, were removed and replaced with custom layers for domain-specific adaptation. The dataset was prepared using two augmentation strategies, rotation (90°, 180°, 270°) and horizontal flip, to artificially expand the training set, followed by class balancing via random duplication of the minority class (non-tumor). The augmented and balanced dataset was then split at the image level (non-patient-wise) into 80% training, 10% validation, and 10% testing. Hyperparameter tuning explored learning rates (1e−3, 1e−4, 1e−5), batch sizes (16, 32, 64), dropout rates (0.3, 0.5, 0.7), and four optimizers (RMSprop30, Adam33, Nadam35, AdamW37), with L2 regularization (λ = 1e-4) and early stopping (patience = 10). Detailed architecture descriptions, the hyperparameter grid, the experimental setup and results are provided in the Supplementary Material (Supplementary Tables S1–S3, Supplementary Figures S1–S5).
Model development and evaluation workflow
To ensure unbiased performance evaluation and eliminate the risk of data leakage, a rigorous multi-stage workflow was implemented:
-
Patient-wise splitting of the original internal datasetTo rigorously evaluate generalization performance, a patient-wise stratified 5-fold cross validation was implemented. This ensured that scans from the same patient were never split across training and validation folds, thereby preventing data leakage and preserving clinical independence. Stratification was applied to maintain balanced representation of tumor and no-tumor cases across folds. Cross validation was conducted on the best-performing architecture (InceptionV3 optimized with Nadam), selected after preliminary model benchmarking. Starting from the original, non-augmented, imbalanced internal dataset (253 patients, 155 tumors, 98 non- tumor), a patient-wise stratified split (by patient ID) was performed to reserve 10% of images (25 original images) as a held-out test set. The remaining 90% of images formed the development set. The test set was never used during model development, cross-validation, or hyperparameter tuning; it was used only once for final performance evaluation.
-
Data augmentation and class balancing applied to the development set to expand dataset diversity and mitigate class imbalance. The development set was augmented by applying rotation (90°, 180°, 270°) and horizontal flip to each image, generating 7 additional images per original (total 8 images per patient). To address class imbalance, the minority class (non-tumor) was oversampled by randomly duplicated (with replacement) until both classes contained an equal number of images. All images retained their original patient ID. This resulted in a fully augmented and balanced development set of 2280 images.
-
Stratified group fivefold cross validation performed on the development set to ensure robust model selection and generalizability. By splitting the dataset into folds, a robust internal estimate of the performance is obtained and avoid bias from a single train/validation split. Each patient was treated as a group (all images of a patient assigned to the same fold). Stratification was based on the original patient-level class labels to preserve the original class distribution across folds. The development set (with multiple images per patient) was split accordingly.
For each fold:
-
1.
Training folds (4 folds) and validation fold (onefold) both contained all images (original, augmented, repeated) of their assigned patients.
-
2.
The selected model (InceptionV3 with Nadam, same hyperparameters as in Section “Preliminary Model Selection (Exploratory Phase)”) was trained from scratch on the training folds and evaluated on the validation fold.
-
3.
Performance metrics were recorded per fold and then averaged.
-
Final model training on the entire development set After cross-validation, a final model was trained on the entire development set using same hyperparameters and augmentation applied to the whole set.
-
Final model Evaluation:
The final model was then evaluated on:
1. The held-out internal test set (25 original images) for internal performance evaluation.
2. The Dataset B (3000 images) for independent external evaluation using a separate dataset of unseen MRI images.
3. Quantitative explainaility (XAI) analyses (Section “Quantitative Explainability (XAI)”) were performed on the external test dataset using the final model for qualitative and quantitative evaluation.
4. For the internal test set (25 images), we computed the same XAI metrics on a per-image basis to generate illustrative examples. No statistical aggregation was performed on this small set; all quantitative summaries are based on the external dataset.
This workflow ensures both robust model selection and provides a fair assessment of the model’s ability to generalize to new clinical scenarios.
Evaluation matrices
The performance of the proposed model was quantitatively assessed using the confusion matrix, which records the four possible outcomes: True Positives (TP), False Positives (FP), True Negatives (TN), and False Negatives (FN). From these, the following standard metrics were computed:
$${\text{Accuracy}} = \, \left( {{\text{TP}} + {\text{TN}}} \right)/\left( {{\text{TP}} + {\text{TN}} + {\text{FP}} + {\text{FN}}} \right)$$
(1)
$${\text{Precision}} = {\text{ TP}}/\left( {{\text{TP}} + {\text{FP}}} \right)$$
(2)
$${\text{Recall}} = {\text{ TP}}/\left( {{\text{TP}} + {\text{FN}}} \right)$$
(3)
$${\text{F1}} – {\text{Score}} = \, \left( {{2 } \times {\text{ Precision }} \times {\text{ Recall}}} \right)/\left( {{\text{Precision }} + {\text{ Recall}}} \right)$$
(4)
$$AUC \approx 0.5\left( {sensitivity + specifity} \right)$$
(5)
For internal cross-validation (patient-wise stratified fivefold CV), all metrics are reported as mean ± standard deviation (SD) over the five folds.
Quantitative explainability (XAI)
DL models often function as “black boxes,” which limits their direct clinical adoption in high-stakes domains such as medical imaging. Although CNNs achieve high accuracy in brain tumor detection, their decision-making process remains opaque. To enhance transparency and build clinical trust, we implemented a suite of quantitative XAI methods. Table 3 summarizes these methods and their associated quantitative validation metrics. The theoretical Overview of the implemented XAI Methods are provided in the Supplementary Materials (Supplementary Methods S4), while the schematic workflow is illustrated in Supplementary Figure S7. This figure highlights how these complementary methods (Grad-CAM, weight randomization, perturbation analysis, integrated gradients, occlusion sensitivity, and noise robustness) were integrated into a unified validation framework. This section focuses on the practical implementation and quantitative validation metrics used to assess fidelity, causality, and robustness of the explanations.
-
1.
Grad-CAM39: To enhance the interpretability of the proposed DL models, Grad-CAM is applied to generate class-specific localization maps. It highlights the discriminative regions within brain MRI scans that contribute most to the model’s predictions, thereby improving transparency and clinical trust in automated tumor detection systems.
-
2.
Weight randomization sanity check41: All trained weights replaced with random values (mean = 0, SD = 0.01); Grad-CAM heatmaps recomputed. Pixel-wise Pearson, Spearman, and SSIM correlations with the original were calculated. Near-zero correlations confirmed dependence on learned weights.
-
3.
Perturbation analysis42: Occlusion of the top 10% Grad-CAM-highlighted pixels (replaced with dataset mean, 0.5). Confidence drop measured and compared to random occlusion using corrected paired t-tests.
-
4.
Integrated gradients43: Implemented via Captum library with a black baseline (all zeros) and 100 interpolation steps. Completeness error calculated to verify attribution fidelity.
-
5.
Occlusion sensitivity maps42: A 10 × 10 patch slid across the image (stride = 5), replaced with dataset mean, and confidence drop recorded. Sensitivity maps compared to Grad-CAM using Spearman correlation.
Table 3 Summary of XAI methods and quantitative validation metrics.
Computational sampling for XAI metrics
Because occlusion sensitivity maps require hundreds of forward passes per image, all quantitative XAI metrics were evaluated on a stratified random subset of 200 images (100 per class) drawn from the external dataset of 3,000 cases. Stratification (seed = 42) preserved the original class balance.
Representativeness verification To ensure that the subset faithfully reflects the full test set, we compared the model’s classification accuracy, recall, and precision between the subset and the complete test set using two-proportion z-tests. No significant differences were found (p > 0.05 for all metrics). To further assess the reliability of the XAI metrics derived from the 200-image subset, we performed bootstrap resampling (1,000 iterations). The resulting 95% confidence intervals for all metrics were narrow (e.g., top-10% occlusion drop: 0.44 ± 0.04), confirming that the sample size provides sufficient precision. Detailed procedures for sampling and statistical reliability are provided in Supplementary Methods S4 Section S4.6.

