Skip to content

Brain MRI Classification using deep learning (VGG16 & ResNet18) with FastAPI backend and Streamlit frontend. Upload MRI images, get predictions, and compare model performance in an interactive web app.

License

Notifications You must be signed in to change notification settings

Abdelrahman-Elshahed/brain-mri-classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brain MRI Classification (VGG16 & ResNet18)

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.


Table of Contents


Data Source


Project Structure

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

Features

  • 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

Usage

  • Upload a brain MRI image in the Streamlit app to get predictions from both models.
  • Compare model performance and view detailed metrics and explanations.

Model Performance

  • VGG16: 97% accuracy (macro avg precision: 98%, recall: 97%)
  • ResNet18: 98% accuracy (macro avg precision: 98%, recall: 98%)

Setup

  • 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 with Streamlit Application

  • 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

Image

Image

Image

Image

Image


PostMan API Testing

  • Health Check: Send a GET request to http://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 the form-data key file.

Below is a screenshots of a successful prediction request in Postman:

Image

Image

Image


Dockerization


About

Brain MRI Classification using deep learning (VGG16 & ResNet18) with FastAPI backend and Streamlit frontend. Upload MRI images, get predictions, and compare model performance in an interactive web app.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published