Skip to content
Projets

Nati-1995/Brain-Tumor-MRI-Classification

Voir sur GitHub

Nati-1995/Brain-Tumor-MRI-Classification has 47 GitHub stars and 2 forks. GitHot measured 0 stars in 24 hours and +1 in 7 days. Last checked 2026-11-21 07:16 UTC. Last push 2026-08-16.

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
+1
in 15 days
Historique en cours
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

À propos

Deep learning for brain tumor MRI: detection (99.4%) and 4-class typing (94.75%) via EfficientNet transfer learning + Grad-CAM.

Apprentissage automatique

README.md

Original

Brain Tumor MRI Classification

Deep-learning classification of brain MRI scans using transfer learning, with Grad-CAM interpretability to verify the model attends to actual tumor regions. Two tasks are covered: binary (tumor vs. no-tumor) and 4-class tumor typing (glioma, meningioma, pituitary, no-tumor).

Note: This is a research and educational project. It is not a medical device and must not be used for real diagnosis.

Demo

An interactive interface (Gradio) runs both models on an uploaded scan, shows a Grad-CAM overlay of where the model looked, and answers preset questions about the result — all grounded in the model's own output.

The interface:

Demo - interface

Glioma case — detection, 4-class typing, Grad-CAM, and the chat explaining the result:

Demo - glioma

Meningioma case — the harder class, correctly typed with the chat explaining the focus region:

Demo - meningioma

The clinical-viewer style pairs each grayscale MRI with its Grad-CAM heat map and the model's impression + confidence:

Clinical viewer - glioma

Clinical viewer - meningioma

Clinical viewer - no tumor


Results

Both models are EfficientNetB0, evaluated on clean stratified splits.

Task Accuracy Macro-F1
Binary (tumor vs no-tumor) 99.4% 0.988
4-class (tumor typing) 94.75% ± 0.40% 0.950 ± 0.004

The 4-class result is averaged over 3 random seeds. On the binary task, no_tumor recall is 0.987 — of 74 healthy scans only 1 was missed — which is the key safety-relevant metric.

Multiclass confusion matrix:

Multiclass confusion matrix

Binary confusion matrix:

Binary confusion matrix

Per-class performance (representative run):

Class Precision Recall F1
glioma 0.96 0.93 0.94
meningioma 0.95 0.87 0.91
no_tumor 0.96 0.97 0.97
pituitary 0.90 1.00 0.95

Meningioma is the hardest class, occasionally confused with glioma — consistent with their visual similarity on MRI. Grad-CAM makes this visible: on the few missed cases the heatmap is diffuse with no focal lesion, whereas correct predictions localize tightly on the tumor.


Method

  • Backbone: EfficientNetB0 (ImageNet weights), ResNet50 compared as baseline.
  • Input: 224×224 RGB, normalized with the backbone's own preprocess_input.
  • Augmentation: horizontal flip, small rotation, zoom, and contrast, applied before normalization.
  • Two-stage training: (1) train the classifier head with the backbone frozen; (2) unfreeze the upper layers and fine-tune at a low learning rate (3e-5) with cosine-style scheduling, early stopping, and LR reduction on plateau.
  • Class imbalance: square-root-damped class weights (full inverse-frequency weights over-corrected and hurt minority classes).
  • Loss: categorical cross-entropy with label smoothing (0.05).
  • Evaluation: stratified 70/15/15 split pooled from the original folders, so train/val/test share the same distribution. Reported over 3 seeds.

Repository structure

code/
  FINAL CODE FOR BEST MODEL(MULTICLASSIFIER)/   # main 4-class notebook
  FINAL CODE FOR BEST MODEL(BINARY)/            # main binary notebook
  UI code/                                      # Gradio dual-model interface
  DATAIL CODE For Comparison/                   # baseline & comparison runs

Dataset

Brain Tumor MRI dataset with four categories: glioma, meningioma, pituitary, and no-tumor. Images are organized into class subfolders. In this project the original train/val/test folders are pooled and re-split with stratification to avoid distribution mismatch between the provided splits.

Expected layout after unzip:

DATA/
  Training(70%)/<class>/*.jpg
  Validation(20%)/<class>/*.jpg
  Testing(10%)/<class>/*.jpg

Running (Google Colab)

  1. Mount Drive and unzip the dataset:
    from google.colab import drive
    drive.mount('/content/drive')
    !unzip -o -q "/content/drive/MyDrive/DATA.zip" -d "/content/"
    
  2. Set a GPU runtime (Runtime → Change runtime type → T4 GPU).
  3. Open the multiclass notebook and run the cells in order: re-split → train → evaluate → Grad-CAM.

Interpretability

Grad-CAM is generated from the backbone's last convolutional layer and overlaid on the input scan (a grayscale clinical-viewer style is also provided). This confirms the model localizes to tumor tissue rather than skull or scanner artifacts, and explains where and why misclassifications occur.

Grad-CAM across all four classes

Multiple glioma cases, showing consistent focus on the tumor region:

Grad-CAM glioma grid


Limitations

  • Trained and evaluated on a single public dataset; cross-dataset generalization is not yet tested.
  • Not calibrated or clinically validated. Research use only.