A deep learning project for classifying brain MRI images into four classes using transfer learning with ResNet18 and PyTorch.
- Glioma
- Meningioma
- No Tumor
- Pituitary
- Python
- PyTorch
- Torchvision
- NumPy
- Matplotlib
- scikit-learn
- Jupyter Notebook
The project follows a complete image-classification workflow:
- Dataset exploration
- Stratified train/validation split
- Image preprocessing and augmentation
- Transfer learning using pretrained ResNet18
- Training with a frozen backbone
- Partial fine-tuning of ResNet18
- Model evaluation using accuracy, precision, recall and confusion matrices
- Misclassification analysis
Three ResNet18 configurations were evaluated:
| Model | Test Accuracy |
|---|---|
| Frozen ResNet18 | 80.69% |
| Layer4 + FC Fine-tuning | 91.69% |
| Layer3 + Layer4 + FC Fine-tuning | 93.19% |
The final model achieved 93.19% accuracy on the 1,600-image test set.
Directory structure:
└── Brain-Tumor-Classification/
├── images/
│ ├── CompleteFT CM.png
│ ├── CompleteFT Metrics.png
│ ├── Frozen Backbone CM.png
│ ├── Frozen Backbone Metrics.png
│ ├── Misclassified Images.png
│ ├── PartialFT CM.png
│ └── PartialFT Metrics.png
├── models/
│ ├── ResNET_Frozen.pt
│ ├── ResNET_Frozen_FT.pt
│ └── ResNET_Frozen_PartialFT.pt
├── notebooks/
│ ├── 00. Data Exploration.ipynb
│ ├── 01. ResNET.ipynb
│ └── 02. ResNET Evaluation.ipynb
├── README.md
├── requirements.txt
├── split.py
└── src/
├── data.py
├── engine.py
├── evaluation.py
├── metrics.py
└── plots.py
git clone <YOUR_REPOSITORY_URL>
cd Brain-Tumor-Classificationpython -m venv .venvActivate it:
Windows:
.venv\Scripts\activateLinux/macOS:
source .venv/bin/activatepip install -r requirements.txtPlace the original dataset inside the archive/ directory:
archive/
├── Training/
│ ├── glioma/
│ ├── meningioma/
│ ├── notumor/
│ └── pituitary/
└── Testing/
├── glioma/
├── meningioma/
├── notumor/
└── pituitary/
Run the dataset splitting script:
python split.pyThis creates the following structure:
dataset/
├── train/
├── val/
└── test/
The original test set is kept untouched.
Launch Jupyter:
jupyter notebookOpen the notebooks inside the notebooks/ directory to reproduce the analysis and experiments.
Trained ResNet18 checkpoints are available in the models/ directory.
The final model is the Layer3 + Layer4 + FC fine-tuned ResNet18.
This project is intended for educational and research purposes only. It is not a medical diagnostic system and should not be used for clinical decision-making.