A comprehensive Jupyter notebook project for classifying brain tumor MRI scans into four categories: Glioma, Meningioma, Pituitary, or No Tumor.
This project demonstrates end-to-end deep learning for medical image classification, featuring:
- Data exploration and preprocessing
- Two neural network architectures (transfer learning and custom CNN)
- Model training, evaluation, and visualization
- Interactive web application with AI-powered explanations
- Deployment capabilities
- Data Analysis: Exploratory data analysis with class distribution and sample visualization
- Model Training: Train and compare Xception (transfer learning) and custom CNN models
- Evaluation: Comprehensive metrics, confusion matrices, and classification reports
- Web App: Streamlit interface for real-time classification with saliency maps
- AI Explanations: Google Gemini integration for model decision explanations
- Deployment: Ngrok tunneling for public access
The project uses the Brain Tumor MRI Dataset from Kaggle, containing:
- Glioma tumors
- Meningioma tumors
- Pituitary tumors
- No tumor (healthy scans)
- Python 3.7+
- Jupyter Notebook or Google Colab
- Required packages:
- tensorflow
- keras
- pandas
- numpy
- matplotlib
- seaborn
- scikit-learn
- opencv-python
- pillow
- streamlit
- google-generativeai
- python-dotenv
- pyngrok
- plotly
-
Clone the repository:
git clone https://github.com/anbguye/Brain-Tumor-MRI-Classification.git cd Brain-Tumor-MRI-Classification -
Install dependencies:
pip install tensorflow pandas numpy matplotlib seaborn scikit-learn opencv-python pillow streamlit google-generativeai python-dotenv pyngrok plotly
-
Set up API keys:
- Create a
.envfile in the project root - Add your Google Gemini API key:
GOOGLE_API_KEY=your_api_key_here - Add your Ngrok token:
NGROK_AUTH_TOKEN=your_token_here
- Create a
- Upload
Brain_Tumor_Classification.ipynbto Google Colab - The notebook includes automatic dataset download via Kaggle API
- Run all cells sequentially
- The Streamlit app will launch with a public URL via Ngrok
- Download the dataset from Kaggle and extract to
Training/andTesting/folders - Open
Brain_Tumor_Classification.ipynbin Jupyter Notebook - Update file paths in the notebook if necessary
- Run the cells to train models and launch the web app
The notebook is divided into two main parts:
- Dataset loading and preprocessing
- Data augmentation and generators
- Xception model training and evaluation
- Custom CNN model training and evaluation
- Model comparison and visualization
- Streamlit app code for interactive classification
- Saliency map generation
- Google Gemini integration for explanations
- Ngrok deployment
- Input: 299x299 RGB images
- Base Model: Xception pretrained on ImageNet
- Top Layers: Flatten → Dropout(0.3) → Dense(128, ReLU) → Dropout(0.25) → Dense(4, Softmax)
- Training: Adamax optimizer, 0.001 learning rate, 5 epochs
- Input: 224x224 RGB images
- Architecture:
- Conv2D(512) → MaxPool → Conv2D(256) → MaxPool → Dropout(0.25)
- Conv2D(128) → MaxPool → Dropout(0.25) → Conv2D(64) → MaxPool
- Flatten → Dense(256, L2 reg) → Dropout(0.35) → Dense(256, L2 reg) → Dropout(0.35) → Dense(4, Softmax)
- Training: Adamax optimizer, 0.001 learning rate, 5 epochs
Both models achieve high accuracy on the test set with comprehensive evaluation metrics including precision, recall, and confusion matrices.
- Upload MRI images for classification
- Real-time prediction with confidence scores
- Saliency maps highlighting model focus areas
- AI-generated explanations using Google Gemini
- Interactive visualizations with Plotly
This project uses the CC0-1.0 license.