Skip to content

This project implements a deep learning-based MRI tumor classification model using PyTorch. The model is trained on MRI brain scans to classify different tumor types using a CNN architecture.

License

Notifications You must be signed in to change notification settings

mertmetin1/Brain-Tumor-Image-Classification-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MRI TUMOR CLASSIFICATION

📌 Overview

This project implements a deep learning-based MRI tumor classification model using PyTorch. The model is trained on MRI brain scans to classify different tumor types using a CNN architecture.

🚀 Features

  • Preprocessing: Image transformations, data augmentation, and dataset splitting.
  • Deep Learning Model: Custom Convolutional Neural Network (CNN) for MRI classification.
  • Training & Evaluation: Model training, validation, and evaluation metrics.
  • Visualization: Data distribution, confusion matrix, class performance, and Grad-CAM heatmaps.
  • Testing & Prediction: Evaluate model accuracy and classify new MRI images.

📂 Project Structure

├── data_preparation.py   # Prepares dataset, applies transformations
├── model_definition.py   # Defines CNN model
├── train_and_evaluate.py # Training & evaluation logic
├── test_accuracy.py      # Calculates test set accuracy
├── testSample.py         # Predicts MRI tumor class for a given image
├── main.py               # Orchestrates data processing, training & testing
├── visualization.py      # Contains visualization functions
├── models/               # Stores trained model weights
├── plots/                # Stores various plots (confusion matrix, ROC curves, etc.)
└── metrics/              # Stores model performance metrics

🔧 Installation & Setup

1️⃣ Clone the Repository

git clone https://github.com/mertmetin1/MRI-Tumor-Classification.git
cd MRI-Tumor-Classification

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Dataset Preparation

Ensure the dataset is structured as follows:

./data/Raw/
 ├── Training/
 │   ├── glioma/
 │   ├── meningioma/
 │   ├── notumor/
 │   ├── pituitary/
 ├── Testing/
 │   ├── glioma/
 │   ├── meningioma/
 │   ├── notumor/
 │   ├── pituitary/

🏋️‍♂️ Training the Model

Run the main.py script to train the model:

python main.py

This will:

  • Load the dataset
  • Train the CNN model
  • Save the best-performing model
  • Generate evaluation plots

🧪 Testing & Prediction

Test Model Accuracy

python test_accuracy.py

Classify a New MRI Image

python testSample.py --image_path path/to/image.jpg

📊 Visualization & Evaluation

  • Confusion Matrix (plots/confusion_matrix.png)

  • resim

  • ROC Curves (plots/roc_curve.png)

  • resim

  • Class-wise Performance (plots/per_class_accuracy.png)

  • resim

  • Grad-CAM Heatmaps (plots/grad_cam/)

  • resim


📈 Model Performance

Metric Value
Best Validation Accuracy 97.46%
Final Training Loss 0.0272
Final Validation Loss 0.1888
Test Accuracy 98.63%

🤖 Model Architecture

The CNN model consists of 3 convolutional layers, ReLU activations, MaxPooling, and fully connected layers:

Conv2D(3 → 32) → ReLU → MaxPool
Conv2D(32 → 64) → ReLU → MaxPool
Conv2D(64 → 128) → ReLU → MaxPool
Flatten → Fully Connected → Output (Softmax)

For a detailed visualization, see plots/model_architecture.png.


📝 License

This project is licensed under the MIT License.


🙌 Acknowledgments

Special thanks to the open-source community for providing tools like PyTorch & TorchVision for deep learning research.


🔗 References

About

This project implements a deep learning-based MRI tumor classification model using PyTorch. The model is trained on MRI brain scans to classify different tumor types using a CNN architecture.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published