Skip to content

Yaseen-md/Brain-Tumor-Detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Brain Tumor Detection System

AI-Powered MRI Analysis with Deep Learning

Streamlit App Python PyTorch License

Live Demo β€’ Report Bug β€’ Request Feature


πŸ“‹ Overview

An intelligent deep learning application that automatically classifies brain tumors from MRI scans into four categories: Glioma, Meningioma, Pituitary Tumor, and No Tumor. Built with state-of-the-art computer vision techniques and deployed as an interactive web application.

🎯 Key Highlights

  • High Accuracy: ResNet18-based architecture fine-tuned for medical image classification
  • Explainable AI: Grad-CAM visualization shows which brain regions influenced the prediction
  • User-Friendly: Intuitive Streamlit interface requiring no technical expertise
  • Flexible Input: Upload local images or provide URLs for instant analysis
  • Real-Time: Fast predictions with confidence scores for all tumor types

🌐 Live Demo

πŸš€ Try it now: Brain Tumor Detector Web App

Upload an MRI scan and get instant results with visual explanations!


✨ Features

Feature Description
πŸ” Multi-Class Detection Classifies 4 tumor types: Glioma, Meningioma, Pituitary, No Tumor
πŸ“€ Flexible Upload Support for image upload and URL-based input
🎨 Grad-CAM Visualization Heatmap overlays highlight decision-making regions
πŸ“Š Confidence Scores Probability distribution across all classes
⚑ Fast Inference Real-time predictions with optimized model
πŸ“± Responsive Design Works seamlessly on desktop and mobile devices

πŸ—οΈ Architecture

Model Specifications

  • Base Architecture: ResNet18 (Transfer Learning)
  • Framework: PyTorch 2.0+
  • Input Size: 224Γ—224 RGB images
  • Output Classes: 4 (Glioma, Meningioma, Pituitary, No Tumor)
  • Explainability: Grad-CAM visualization on final convolutional layer

Tech Stack

Frontend:  Streamlit
Backend:   PyTorch, OpenCV
Deployment: Streamlit Cloud

πŸ“Š Dataset


πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

  1. Clone the repository

    git clone https://github.com/Yaseen-md/Brain-Tumor-Detector.git
    cd Brain-Tumor-Detector
  2. Create virtual environment (recommended)

    python -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Run the application

    streamlit run app.py
  5. Open your browser

    Navigate to http://localhost:8501
    

πŸ“ Project Structure

Brain-Tumor-Detector/
β”œβ”€β”€ app.py                          # Streamlit web application
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ README.md                       # Project documentation
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ resnet18_best.pth          # Trained model weights
β”‚   β”œβ”€β”€ loss_history.npy           # Training metrics
β”‚   β”œβ”€β”€ y_pred.npy                 # Validation predictions
β”‚   └── y_true.npy                 # Ground truth labels
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ model.py                   # Model architecture
β”‚   β”œβ”€β”€ train.py                   # Training script
β”‚   β”œβ”€β”€ evaluate.py                # Evaluation utilities
β”‚   β”œβ”€β”€ inference.py               # Prediction functions
β”‚   β”œβ”€β”€ grad_cam.py                # Grad-CAM implementation
β”‚   β”œβ”€β”€ data_loader.py             # Dataset handling
β”‚   β”œβ”€β”€ utils.py                   # Helper functions
β”‚   └── validate_dataset.py        # Data validation
└── notebooks/
    β”œβ”€β”€ 01_data_exploration.ipynb  # EDA
    β”œβ”€β”€ 02_model_training.ipynb    # Training experiments
    β”œβ”€β”€ 03_model_evaluation.ipynb  # Performance analysis
    └── 04_grad_cam_visualization.ipynb  # Visualization demos

πŸ”¬ Model Performance

Metric Score
Training Accuracy High
Validation Accuracy Competitive
Inference Time < 1 second

Detailed metrics available in notebooks/03_model_evaluation.ipynb


πŸŽ“ Usage Examples

Web Interface

  1. Visit the live demo
  2. Upload an MRI scan or paste an image URL
  3. Click "Predict"
  4. View results with Grad-CAM visualization

Programmatic Usage

from src.inference import predict_image
from src.utils import load_model

model = load_model('models/resnet18_best.pth')
prediction = predict_image(model, 'path/to/mri.jpg')
print(f"Prediction: {prediction['class']}")
print(f"Confidence: {prediction['confidence']:.2%}")

πŸ›£οΈ Roadmap

  • βœ… Deploy to Streamlit Cloud
  • πŸ”„ Implement ensemble models for improved accuracy
  • πŸ“ˆ Add model performance dashboard
  • πŸŽ₯ Support for video/DICOM file uploads
  • πŸ“„ Generate downloadable PDF reports
  • 🌍 Multi-language support
  • πŸ” Add user authentication and history tracking

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.


πŸ™ Acknowledgments


πŸ“¬ Contact & Support

Yaseen MD

Found this helpful? Give it a ⭐️ to show your support!


⚠️ Disclaimer: This tool is for educational and research purposes only. It should not be used as a substitute for professional medical diagnosis.

Made with ❀️ and 🧠 by Yaseen

About

AI-powered brain tumor detection from MRI scans using PyTorch and Streamlit with Grad-CAM visualizations

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors