Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HematoScan AI — Leukemia Detection

Transfer Learning-based blood smear classification using EfficientNetB3, Flask, and Grad-CAM


Project Structure

leukemia-detection/
├── backend/
│   ├── app.py              ← Flask API (predict, health endpoints)
│   └── requirements.txt    ← Python dependencies
├── frontend/
│   └── index.html          ← Main UI page
├── model/
│   └── leukemia_model.keras ← Place your trained model here
├── static/
│   ├── css/style.css       ← Dark medical theme stylesheet
│   └── js/app.js           ← Frontend JS (upload, predict, render)
└── README.md

Quick Start (Local)

1. Prerequisites

  • Python 3.10+
  • pip

2. Install backend dependencies

cd backend
pip install -r requirements.txt

Note: If you don't have a GPU, replace tensorflow with tensorflow-cpu in requirements.txt.

3. (Optional) Place your trained model

Copy your trained Keras model to:

model/leukemia_model.keras

If no model is present, the app runs in Demo Mode — predictions are simulated based on image statistics. This lets you test the full UI and API pipeline without a trained model.

To train a model: Use the provided leukemia_detection.py training script. After training, the best model is automatically saved as leukemia_model.keras. Move it to the model/ folder.

4. Start the backend

cd backend
python app.py

API will be available at http://localhost:5000

5. Open the frontend

Open frontend/index.html in any modern browser, or serve it with a simple HTTP server for proper relative paths:

# From the project root:
python -m http.server 8080
# Then open: http://localhost:8080/frontend/index.html

API Reference

POST /predict

Accepts a multipart form upload with key image.

Request:

curl -X POST http://localhost:5000/predict \
  -F "image=@blood_smear.jpg"

Response:

{
  "prediction":  "Leukemia",
  "confidence":  0.9712,
  "roc_curve":   "<base64-encoded PNG>",
  "gradcam":     "<base64-encoded PNG>",
  "demo_mode":   false
}

GET /health

{
  "status":       "ok",
  "tf_available": true,
  "model_loaded": true
}

Dataset

This project is designed for the ALL (Acute Lymphoblastic Leukemia) Image Database available on Kaggle:

Expected folder structure:

dataset/
  Normal/
    img001.jpg
    img002.jpg
    ...
  Leukemia/
    img001.jpg
    img002.jpg
    ...

Deployment

Option A — Render (recommended, free tier)

  1. Push the backend/ folder to a GitHub repository.
  2. Go to render.com → New Web Service → connect your repo.
  3. Set:
    • Build Command: pip install -r requirements.txt
    • Start Command: gunicorn app:app --bind 0.0.0.0:$PORT
    • Environment: Python 3.10
  4. Upload your model file as a Render persistent disk (or use a cloud bucket URL).
  5. Update API_BASE in static/js/app.js to your Render URL.
  6. Deploy frontend/ to Vercel or Netlify as a static site.

Option B — Railway

  1. Push project to GitHub.
  2. New Railway project → Deploy from repo.
  3. Set PORT environment variable to 5000.
  4. Railway auto-detects Python and installs requirements.

Option C — Docker

# Dockerfile (place in backend/)
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:5000", "--workers", "2"]
docker build -t hematoscan-api ./backend
docker run -p 5000:5000 hematoscan-api

Environment Variables

Variable Default Description
PORT 5000 Port the Flask server listens on
FLASK_DEBUG false Enable debug mode (true/false)

Model Architecture

Input (224×224×3)
    ↓
EfficientNetB3 (pretrained ImageNet, top 30 layers fine-tuned)
    ↓
GlobalAveragePooling2D
    ↓
BatchNormalization
    ↓
Dense(256, ReLU) → Dropout(0.5)
    ↓
Dense(64,  ReLU) → Dropout(0.3)
    ↓
Dense(1, Sigmoid)   ← Binary output: Normal (0) / Leukemia (1)

Accuracy Targets

Metric Target
Accuracy ≥ 95%
Recall ≥ 96%
Precision ≥ 93%
ROC-AUC 0.88–0.95

Disclaimer

This tool is intended for research and educational purposes only. It is not certified for clinical use and should not replace diagnosis by a licensed haematologist or pathologist.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages