Skip to content

Repository files navigation

Brain Tumor Classification & Diagnosis Assistance Using Fine-Tuned MedGamma on MRI Images

This project is a professional research and prototype full-stack web application designed for automatic brain tumor classification and diagnostic support using magnetic resonance imaging (MRI) scans. It classifies images into four categories: Glioma, Meningioma, Pituitary, or No Tumor.

Screenshots

Dashboard Upload Scan
Classification Results Analysis Report

Key Components

  • Fine-tuned MedGamma model: A pre-trained medical AI model adapted specifically for brain MRI data.
  • Brain tumor classification: The system identifies whether an MRI scan contains a tumor and classifies the tumor type.
  • Diagnosis assistance: The model provides support for medical professionals by highlighting findings and enabling faster, more consistent image interpretation.
  • MRI image input: The pipeline processes MRI scans, extracts relevant imaging features, and delivers predictions based on the fine-tuned model.

How it Works

  • Data preprocessing: MRI scans are standardized in size and intensity, then augmented with rotations, flips, and noise to improve model generalization across different patients and scanners.
  • Model fine-tuning: MedGamma is adapted with labeled brain MRI scans, enabling it to learn tumor-specific imaging patterns while preserving its medical imaging expertise. (A fallback Keras CNN model is also included).
  • Prediction pipeline: Incoming MRI scans are processed by the fine-tuned model, which outputs tumor classification, tumor type probabilities, and region-of-interest localization guidance.
  • Diagnostic support: The system highlights suspicious areas and provides concise findings to assist radiologists in faster and more consistent interpretation.

Project Structure

  • project/frontend/: React.js + TypeScript + Vite + TailwindCSS dashboard.
  • project/backend/: FastAPI + Python REST API with ML Inference orchestration.
  • project/backend/training/: Training and evaluation scripts for the dataset.

Setup Instructions

Prerequisites

  • Node.js (v18+)
  • Python (3.10+)
  • Docker (optional, for containerized deployment)

1. Environment Configuration

Copy .env.example to .env in the project root folder:

cp project/.env.example project/.env

Add your HuggingFace token if you intend to use the MedGemma model.

2. Backend Setup

cd project/backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

# Start the API server
uvicorn app.main:app --reload

The API will be available at http://localhost:8000. API Documentation: http://localhost:8000/docs

3. Frontend Setup

cd project/frontend
npm install
npm run dev

The frontend will be available at http://localhost:5173.

Inference & Models

By default, USE_FALLBACK_MODEL=True is set, which looks for a local Keras CNN model (brain_tumor_cnn_best_patched.keras). If this is not found, a mock randomizer is used.

To use MedGemma 4B, set USE_FALLBACK_MODEL=False in your environment and provide a valid HF_TOKEN.

Training

The training scripts dynamically scan the dataset directory (default: ../Dataset) and generate artifacts.

cd project/backend/training
python train.py
python evaluate.py

Disclaimer

This is a research/decision-support prototype, not a medical diagnosis system. Predictions provided by this system require independent clinical review by a qualified radiologist.

About

Automatic brain tumor classification and diagnostic support using magnetic resonance imaging (MRI) scans. It classifies images into four categories: Glioma, Meningioma, Pituitary, or No Tumor.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages