Features โข Dataset โข Model Architecture โข Installation โข Usage โข Results
- Overview
- Features
- Dataset
- Model Architecture
- Installation
- Usage
- Results
- Technologies Used
- Future Enhancements
- Contributing
- License
- Acknowledgments
This project implements a Convolutional Neural Network (CNN) for classifying brain MRI scans into 4 categories:
- ๐ข Glioma Tumor
- ๐ต Meningioma Tumor
- ๐ก Pituitary Tumor
- โช No Tumor
Brain tumors are one of the most critical health conditions requiring early detection. This AI-powered solution aims to assist medical professionals in making faster and more accurate diagnoses.
|
|
|
|
The model is trained on the Brain Tumor MRI Dataset from Kaggle:
Training Set
โโโ Glioma: ~900 images
โโโ Meningioma: ~900 images
โโโ Pituitary: ~900 images
โโโ No Tumor: ~500 images
Testing Set
โโโ Glioma: ~100 images
โโโ Meningioma: ~100 images
โโโ Pituitary: ~100 images
โโโ No Tumor: ~100 images
Transforms Applied:
โ
Resize to 128ร128
โ
Convert to Tensor
โ
Normalize [-1, 1]โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Input: 128ร128ร3 RGB Image โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Conv2D(3โ32) + ReLU + MaxPool โ
โ Output: 64ร64ร32 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Conv2D(32โ64) + ReLU + MaxPool โ
โ Output: 32ร32ร64 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Conv2D(64โ128) + ReLU + MaxPool โ
โ Output: 16ร16ร128 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Flatten: 32,768 features โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Dense(32768โ256) + ReLU + Dropout(0.5) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Dense(256โ4) - Output Layer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
[Glioma, Meningioma,
Pituitary, No Tumor]
| Layer | Parameters | Output Shape |
|---|---|---|
| Conv1 | 896 | (64, 64, 32) |
| Conv2 | 18,496 | (32, 32, 64) |
| Conv3 | 73,856 | (16, 16, 128) |
| FC1 | 8,388,864 | (256) |
| FC2 | 1,028 | (4) |
| Total | 8,483,140 | - |
Python 3.7+
CUDA (optional, for GPU support)git clone https://github.com/Pratham00007/Brain-Tumor-detection-AI.git
cd Brain-Tumor-detection-AI
pip install -r requirements.txttorch>=1.9.0
torchvision>=0.10.0
matplotlib>=3.3.0
numpy>=1.19.0
pillow>=8.0.0
jupyter>=1.0.0# Download dataset from Kaggle
kaggle datasets download -d masoudnickparvar/brain-tumor-mri-dataset
# Extract to data/ folder
unzip brain-tumor-mri-dataset.zip -d data/# Open Jupyter Notebook
jupyter notebook main.ipynb
# Run all cells to train the model
# Training takes ~15-20 minutes on GPUimport torch
from torchvision import transforms
from PIL import Image
# Load model
model = torch.load('brain_tumor_model.pth')
model.eval()
# Load and preprocess image
img = Image.open('path/to/mri_scan.jpg')
transform = transforms.Compose([
transforms.Resize((128, 128)),
transforms.ToTensor(),
transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
])
img_tensor = transform(img).unsqueeze(0)
# Predict
with torch.no_grad():
output = model(img_tensor)
prediction = output.argmax(1).item()
classes = ['glioma', 'meningioma', 'pituitary', 'notumor']
print(f"Prediction: {classes[prediction]}")| Metric | Value |
|---|---|
| Test Accuracy | 78.26% |
| Training Loss | ~87.65 |
| Epochs | 25 |
| Batch Size | 32 |
| Learning Rate | 1e-4 |
| Optimizer | AdamW |
Epoch 1: Loss = 153.64 ๐ด
Epoch 2: Loss = 102.21 ๐
Epoch 3: Loss = 87.65 ๐ก
...
Training interrupted at Epoch 3
| Input MRI | Prediction | Ground Truth | Confidence |
|---|---|---|---|
| Pituitary | Pituitary | โ 95% | |
| Glioma | Glioma | โ 89% | |
| No Tumor | No Tumor | โ 92% |
- PyTorch: Deep learning framework
- torchvision: Image transformations
- NumPy: Numerical computing
- Matplotlib: Data visualization
- PIL: Image processing
- ๐ฏ Improve accuracy to 90%+
- ๐ Implement data augmentation
- ๐ฑ Create web/mobile app
- ๐ฅ Add more tumor types
- ๐จ Implement Grad-CAM visualization
- ๐ Deploy to cloud (AWS/Azure)
- ๐ Add detailed performance metrics
- ๐ฌ Integrate with DICOM files
- ๐ค Transfer learning with ResNet/VGG
- ๐ Real-time inference API
Contributions are welcome! Here's how you can help:
- ๐ด Fork the repository
- ๐ฑ Create your feature branch (
git checkout -b feature/AmazingFeature) - ๐พ Commit your changes (
git commit -m 'Add some AmazingFeature') - ๐ค Push to the branch (
git push origin feature/AmazingFeature) - ๐ Open a Pull Request
- Follow PEP 8 style guide
- Add unit tests for new features
- Update documentation
- Comment your code
- Test thoroughly before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 Your Name
Permission is hereby granted, free of charge...
- ๐ Dataset: Masoud Nickparvar for the Brain Tumor MRI Dataset
- ๐ PyTorch: Facebook AI Research team
- ๐ก Inspiration: Medical AI research community
- ๐ Contributors: All amazing contributors to this project
- Deep Learning for Medical Image Analysis
- CNN Architectures for Image Classification
- Brain Tumor Detection using AI








