This repository was a school project in Deep Learning (DAT255) at Høgskolen på Vestlandet (HVL).
The project investigates brain tumor analysis in MRI images with a focus on both:
- predictive performance (classification and detection), and
- model reliability through explainability (Grad-CAM) and cross-dataset behavior.
The main objective is to study whether deep learning models are learning medically meaningful features, not only achieving high accuracy.
The workflow covers:
- 4-class tumor classification on Kaggle MRI data,
- binary tumor vs. no-tumor classification,
- transfer learning with a pretrained ResNet model,
- localization analysis with Grad-CAM, and
- object detection with YOLO on a second dataset with bounding boxes.
DAT255_project.ipynb– main notebook containing all experiments, preprocessing, training, evaluation, Grad-CAM, and YOLO detection.XAI_tumor_classification.pdf– full project report.README.md– this file.
- Source: https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset
- ~7000 MRI images
- Used for:
- 4-class classification (
glioma,meningioma,pituitary,notumor) - binary classification (
tumorvsnotumor)
- 4-class classification (
- Source: https://docs.ultralytics.com/datasets/detect/brain-tumor/
- ~1000 images with bounding-box labels
- Used for:
- cross-dataset generalization checks
- YOLO-based tumor localization
- Initial CNN baseline (4-class)
- Final deeper CNN baseline (4-class)
- Augmented CNN variant
- Binary CNN (tumor/no-tumor)
- Pretrained ResNet50-based binary classifier
- Grad-CAM was used to inspect model attention regions and identify potential shortcut learning.
- YOLO26n (
yolo26n.pt) trained on Dataset 2 for tumor localization.
| Model | Accuracy | Macro Precision | Macro Recall | Macro F1 |
|---|---|---|---|---|
| Initial CNN | 0.86 | 0.85 | 0.85 | 0.85 |
| Final CNN | 0.89 | 0.89 | 0.88 | 0.88 |
| Augmented CNN | 0.74 | 0.76 | 0.75 | 0.74 |
| Binary CNN | 0.91 | 0.85 | 0.93 | 0.87 |
| ResNet CNN | 0.98 | 0.99 | 0.99 | 0.99 |
| Model | Box Precision | Recall | mAP@50 | mAP@50-95 |
|---|---|---|---|---|
| YOLO26n | 0.58 | 0.604 | 0.585 | 0.413 |
- Transfer learning (ResNet) gave the best classification performance.
- High accuracy alone was not enough to establish reliability.
- Grad-CAM suggested that models may rely on non-clinical artifacts (possible shortcut learning), especially for
notumorcases. - Performance dropped when transferring a CNN trained on Dataset 1 to Dataset 2, highlighting sensitivity to dataset shift.
- Detection with YOLO provided complementary localization insight, though with moderate performance.
The notebook was developed primarily in Google Colab.
- Open
DAT255_project.ipynblocally or in Colab.
The notebook includes installation commands such as:
pip install kagglehubpip install keras_cvuv pip install ultralytics(can also be replaced bypip install ultralytics)
You will also need the usual ML stack used in the notebook:
- TensorFlow / Keras
- NumPy, OpenCV, Matplotlib, Seaborn, scikit-learn
In Colab, add your Kaggle API token as a secret (e.g. KAGGLE_API_TOKEN) and run the setup cell.
The notebook is written as an end-to-end experimental flow. Run from top to bottom to reproduce preprocessing, training, evaluation, and visualization.
This project is research/educational work and is not intended for autonomous clinical deployment.
Main limitations discussed in the report:
- hardware and runtime constraints,
- limited dataset diversity/size (especially Dataset 2),
- explainability uncertainty (Grad-CAM is indicative, not definitive),
- possible shortcut learning.
If you use this repository, please cite the project report in XAI_tumor_classification.pdf.