Skip to content

Luk446/MRI_Classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brain Cancer MRI Classification

A deep learning project for classifying brain MRI scans into three categories: glioma, meningioma, and other brain tumors using Convolutional Neural Networks (CNN) with PyTorch.

Project Overview

This project implements a custom CNN architecture to classify brain MRI images into three distinct categories:

  • Brain Glioma - A type of tumor that occurs in the brain and spinal cord
  • Brain Meningioma - A tumor that arises from the meninges
  • Brain Tumor - Other types of brain tumors

The model achieves 86.9% accuracy on the test set with strong performance across all three classes.

Key Results

Activation Function Comparison

Activation Final Epoch Train Loss Val Loss Train Acc (%) Val Acc (%)
LeakyReLU 50 0.450 0.356 81.67 86.47
SiLU 50 0.477 0.375 80.37 85.48
ReLU 50 0.459 0.416 81.48 84.71
ELU 50 0.502 0.749 79.38 63.70

The LeakyReLU activation function achieved the best validation accuracy of 86.47%, closely followed by SiLU and ReLU. ELU showed signs of overfitting with significantly lower validation accuracy.

Model Architecture

Custom CNN architecture (MRIClassifier) with the following layers:

  1. Convolutional Block 1: Conv2d (3→32) → ReLU → MaxPool
  2. Convolutional Block 2: Conv2d (32→64) → ReLU → MaxPool
  3. Convolutional Block 3: Conv2d (64→128) → ReLU → MaxPool
  4. Flatten Layer
  5. Fully Connected Block 1: Linear → ReLU → Dropout(0.5)
  6. Fully Connected Block 2: Linear → ReLU → Dropout(0.5)
  7. Output Layer: Linear (→3 classes)

Input: 224×224×3 RGB images (grayscale converted to 3 channels)
Output: 3-class softmax predictions

Technologies & Dependencies

  • Python 3.x
  • PyTorch - Deep learning framework
  • torchvision - Image transformations and datasets
  • NumPy - Numerical computations
  • Pandas - Data manipulation and analysis
  • Matplotlib - Visualization
  • PIL (Pillow) - Image processing
  • Kagglehub - Dataset management

Dataset

  • Total Images: 6,056 MRI scans
  • Classes: 3 (brain_glioma, brain_menin, brain_tumor)
  • Train/Val/Test Split: Stratified split for balanced evaluation
  • Test Set Size: 909 images

Data Preprocessing

transforms = v2.Compose([
    v2.Resize((224, 224), antialias=True),
    v2.Grayscale(num_output_channels=3),
    v2.ToImage(),
    v2.ToDtype(torch.float32, scale=True),
    v2.Normalize(mean=[0.485, 0.456, 0.406], 
                 std=[0.229, 0.224, 0.225])
])

Activation Function Comparison

The project includes experiments with different activation functions:

Activation Final Val Accuracy Model File
SiLU 85.48% ClassyModel_SiLU.pth
LeakyReLU ~86% ClassyModel_LeakyReLU.pth
ELU 63.70% ClassyModel_ELU.pth

See BrainCancerMRI_diffacfunc.ipynb for detailed comparisons.

Training Details

  • Loss Function: CrossEntropyLoss
  • Optimizer: Adam
  • Epochs: Multiple training runs with different configurations
  • Dropout: 0.5 (applied in fully connected layers)
  • Device: CPU/CUDA (automatic detection)

Contributing

This project was developed as part of a Data Mining and Machine Learning coursework at Heriot-Watt University.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published