This project provides a web-based system for classifying brain MRI scans into four categories using deep learning models (VGG16 and ResNet18). It features a FastAPI backend for inference and a Streamlit frontend for user interaction and model comparison.
- Data Source
- Project Structure
- Features
- Usage
- Setup
- Model Performance
- Run with Streamlit Application
- PostMan API Testing
- Dockerization
- Link: Brain Tumor MRI Dataset (Kaggle)
- Classes: Glioma, Meningioma, Pituitary, No Tumor
- Images: This dataset contains 7023 images of human brain MRI images
brain-mri-classification/
│
├── app/ # All application code (Streamlit & FastAPI)
│ ├── appfast.py # FastAPI backend
│ └── new_streamlit_app.py # Streamlit frontend
│
├── models/ # Trained model files
│ ├── vgg16_brain_mri_model.h5
│ └── resnet18_weights.pth
│
├── requirements.txt # Python dependencies
├── Dockerfile # Docker build file
│
├── sample_mri_images/ # For MRI images downloaded from the internet to test the model
│
├── notebooks/ # Jupyter notebooks
└── Brain_MRI.ipynb
- FastAPI backend for RESTful model inference (
appfast.py
) - Streamlit frontend for uploading images, viewing predictions, and comparing models (
new_streamlit_app.py
) - Pre-trained models: VGG16 (TensorFlow/Keras) and ResNet18 (PyTorch)
- Dockerized for easy deployment
- Upload a brain MRI image in the Streamlit app to get predictions from both models.
- Compare model performance and view detailed metrics and explanations.
- VGG16: 97% accuracy (macro avg precision: 98%, recall: 97%)
- ResNet18: 98% accuracy (macro avg precision: 98%, recall: 98%)
-
Clone the Repository
git clone https://github.com/Abdelrahman-Elshahed/brain-mri-classification.git
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Set up dependencies
Install Python dependencies: To install all the required Python packages for the project, run the following command:
pip install -r requirements.txt
- Run FastAPI In one terminal
cd app uvicorn appfast:app --reload --host 0.0.0.0 --port 8000
- Run Streamlit In another terminal
cd app streamlit run new_streamlit_app.py
-
Health Check: Send a
GET
request tohttp://localhost:8000/health
to verify the API is running. -
Model Prediction: Send a
POST
request to/predict/vgg
or/predict/resnet
with a brain MRI image file using theform-data
keyfile
.
Below is a screenshots of a successful prediction request in Postman:
- Build the Docker image with:
docker build -t brain-mri-app .
- Run the container with:
docker run -p 8000:8000 -p 8501:8501 brain-mri-app
- FastAPI docs: http://localhost:8000/docs
- Streamlit app: http://localhost:8501