Skip to content
Raisalon

Deep learning · Completed

Brain tumor detection from MRI scans

A Flask API and React app that classifies brain MRI images as glioma, meningioma, pituitary tumor, or no tumor with a Keras convolutional neural network.

Overview

Upload a brain MRI image and the app returns a prediction in seconds: either no tumor, or one of three tumor types (glioma, meningioma, or pituitary). It also returns the model’s confidence. The goal was to take an image classification model out of a notebook and put it behind a real API with a usable interface.

How it works

  1. Upload. The React app accepts an MRI image by drag and drop or file picker and posts it to the Flask API as multipart/form-data.
  2. Preprocessing. The API resizes the image to 128 × 128 pixels and scales pixel values to the 0–1 range, the input format the model expects.
  3. Classification. A trained Keras convolutional neural network (CNN) outputs a probability for each of the four classes. The class with the highest probability becomes the result, and that probability is reported as the confidence score.
  4. Response. The API returns the label (for example Tumor: glioma or No Tumor), the confidence as a percentage, and a link to the uploaded image so the interface can show it next to the result.

Architecture

Part Technology Responsibility
Model TensorFlow, Keras (CNN) Four-class MRI classification
API Flask, Flask-CORS Upload endpoint, inference, status check, image serving
Interface React 19, Vite, Tailwind CSS 4 Upload, result and confidence display, background info

API endpoints

Method Path Purpose
POST / Upload an MRI image and get the prediction
GET /uploads/<filename> Retrieve an uploaded image
GET /api/status Health check

Limitations

  • Not a medical device. This is a learning project in computer vision. It must not be used for diagnosis.
  • Model weights. The API loads models/model.h5, which is not stored in the repository, and the training notebook is not included. Publishing both, with the evaluation results, would make the model reproducible.
  • Confidence is not certainty. A softmax score shows how strongly the model prefers one class, not how likely it is to be right. Calibration and per-class metrics would give a more honest picture.

Run it locally

git clone https://github.com/kazisalon/Brain-Tumor-Detection-Using-Deep-Learning.git
cd Brain-Tumor-Detection-Using-Deep-Learning

# API: place the trained model at models/model.h5 first
pip install flask flask-cors tensorflow numpy
python app.py

# Interface (in a second terminal)
cd frontend
npm install
npm run dev

All projects