Skip to content

jaygautam-creator/CuraLens

Repository files navigation

CuraLens ๐Ÿฉบ

AI-Assisted Multi-Module Medical Screening Platform

CuraLens is a deep learningโ€“based web platform designed to assist in the screening of oral cavity and skin images for abnormal patterns.
It functions as an AI-assisted decision-support system and does not provide medical diagnosis or replace clinical judgment.


๐Ÿ” Project Motivation

Oral cancer and skin malignancies have a high prevalence, particularly in countries like India.
Early-stage screening and risk flagging can help guide individuals toward timely clinical evaluation.

This project explores how computer vision, transfer learning, and clinical metadata fusion can support preliminary screening in an ethical and responsible manner.


๐Ÿš€ Key Features

  • Dual-modality screening: Oral cavity (v1 + v2/v3) and skin lesion (v1 + v3)
  • Multimodal fusion: EfficientNetB0 image branch fused with 6D clinical metadata
  • Grad-CAM explainability on both v1 and v2/v3 models โ€” visual heatmaps highlight suspicious regions
  • Three-tier risk scoring: Low / Medium / High with colour codes and clinical recommendations
  • Metadata schema validation with graceful degradation on missing or out-of-range fields
  • Two-phase training strategy: warm-up (CNN frozen) โ†’ fine-tuning (top-20 EfficientNet layers unfrozen)
  • Focal loss support for handling class imbalance
  • Stratified K-fold cross-validation with saved per-fold metrics
  • REST API with /predict, /predict/skin, /predict_v2, /schema/<type>, /health
  • Flask SPA web interface with animated gradients and real-time Grad-CAM display
  • Automatic prediction logging to automation_logs/
  • System health endpoint for monitoring model load status

๐Ÿง  Model Architecture Overview

v1 โ€” Image-Only Models (MobileNetV2)

Model Architecture Val AUC Input
Oral v1 MobileNetV2 (frozen) โ†’ Dense(128) โ†’ Sigmoid 0.993 224ร—224 RGB
Skin v1 MobileNetV2 (frozen) โ†’ Dense(128) โ†’ Sigmoid 0.943 224ร—224 RGB

v2 / v3 โ€” Multimodal Models (EfficientNetB0 + Metadata)

Image Input (224ร—224ร—3)          Metadata Input (6D clinical)
        โ†“                                    โ†“
EfficientNetB0 (frozen/fine-tuned)     BatchNorm
GlobalAvgPool โ†’ Dense(512) โ†’ Dropout   Dense(64) โ†’ Dense(64)
        โ†“                                    โ†“
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Concatenate (576D) โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ†“
                  Dense(256) โ†’ Dense(128) โ†’ Sigmoid โ†’ P(cancer)

Oral v3 metadata (6D): age, smoking_years, cigarettes_per_day, alcohol_units_per_week, chewing_tobacco, family_history
Skin v3 metadata (6D): age, skin_type (Fitzpatrick 1-6), sunburn_history, outdoor_hours_per_week, tanning_bed_use, family_history


๐ŸŒ API Reference

POST /predict โ€” Oral v1 (Image-Only)

curl -X POST http://localhost:5001/predict \
  -F "image=@path/to/oral.jpg" \
  -F "mode=diagnostic"

Response includes cancer_probability, risk_level, recommendation, gradcam_png_b64.

POST /predict/skin โ€” Skin v1 (Image-Only)

curl -X POST http://localhost:5001/predict/skin \
  -F "image=@path/to/lesion.jpg"

POST /predict_v2 โ€” Multimodal v2/v3

# Oral v3 with clinical metadata
curl -X POST http://localhost:5001/predict_v2 \
  -F "cancer_type=oral" \
  -F "image=@oral.jpg" \
  -F "age=52" \
  -F "smoking_years=15" \
  -F "cigarettes_per_day=10" \
  -F "alcohol_units_per_week=7" \
  -F "chewing_tobacco=0" \
  -F "family_history=1"

# Skin v3 with clinical metadata
curl -X POST http://localhost:5001/predict_v2 \
  -F "cancer_type=skin" \
  -F "image=@lesion.jpg" \
  -F "age=45" \
  -F "skin_type=2" \
  -F "sunburn_history=8" \
  -F "outdoor_hours_per_week=20" \
  -F "tanning_bed_use=0" \
  -F "family_history=0"

Response includes probability, risk_level, risk_label, confidence_band, recommendation, color_code, gradcam_png_b64.

GET /schema/<cancer_type> โ€” Metadata Field Schema

curl http://localhost:5001/schema/oral
curl http://localhost:5001/schema/skin
curl http://localhost:5001/schema/oral_legacy

GET /health โ€” System Health Check

curl http://localhost:5001/health

Returns load status of all 5 model variants, available endpoints, and overall "ok" / "degraded" status.


๐Ÿ“‚ Project Structure

OralCancerApp/
โ”œโ”€โ”€ train.py                  # v1 oral training (MobileNetV2)
โ”œโ”€โ”€ train_v2.py               # v2/v3 multimodal training pipeline
โ”œโ”€โ”€ train_skin.py             # v1 skin training (MobileNetV2)
โ”œโ”€โ”€ predict.py                # CLI prediction (v1 oral)
โ”œโ”€โ”€ evaluate_v2.py            # v1 vs v2 ablation evaluation
โ”œโ”€โ”€ evaluate_skin.py          # Skin model test-set evaluation โ† NEW
โ”œโ”€โ”€ generate_research_report.py  # Auto-generate research report
โ”œโ”€โ”€ web_app.py                # Flask web application + REST API
โ”œโ”€โ”€ system_smoke_test.py      # End-to-end HTTP integration tests
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”‚
โ”œโ”€โ”€ models/                   # v1 trained models
โ”‚   โ”œโ”€โ”€ oral_cancer_model.h5
โ”‚   โ”œโ”€โ”€ model_metadata.json
โ”‚   โ””โ”€โ”€ skin_model/
โ”‚       โ””โ”€โ”€ skin_screening_model.h5
โ”‚
โ”œโ”€โ”€ models_v2/                # v2/v3 architectures + trained weights
โ”‚   โ”œโ”€โ”€ multimodal_model.py   # Legacy oral 4D architecture
โ”‚   โ”œโ”€โ”€ oral_model.py         # Oral v3 6D architecture
โ”‚   โ”œโ”€โ”€ skin_model.py         # Skin v3 6D architecture
โ”‚   โ”œโ”€โ”€ metadata_scaler.pkl   # Fitted StandardScaler (saved after training)
โ”‚   โ”œโ”€โ”€ saved_model/          # oral_legacy SavedModel
โ”‚   โ”œโ”€โ”€ oral_saved_model/     # oral v3 SavedModel
โ”‚   โ””โ”€โ”€ skin_saved_model/     # skin v3 SavedModel
โ”‚
โ”œโ”€โ”€ utils_v2/
โ”‚   โ”œโ”€โ”€ gradcam.py            # Grad-CAM explainability (single + multi-input)
โ”‚   โ”œโ”€โ”€ metadata_schema.py    # Field definitions, validation, normalisation
โ”‚   โ””โ”€โ”€ risk_scoring.py       # Risk tier logic (Low/Medium/High)
โ”‚
โ”œโ”€โ”€ modules/
โ”‚   โ””โ”€โ”€ skin_screening.py     # v1 skin screening wrapper
โ”‚
โ”œโ”€โ”€ data_clean/               # Training data (oral)
โ”‚   โ”œโ”€โ”€ metadata.csv
โ”‚   โ””โ”€โ”€ train/ val/
โ”‚
โ”œโ”€โ”€ skin_dataset_resized/     # Training data (skin)
โ”‚   โ””โ”€โ”€ train_set/ val_set/ test_set/
โ”‚
โ”œโ”€โ”€ evaluation_outputs/       # Metrics, ROC curves, confusion matrices
โ”œโ”€โ”€ research_report/          # Auto-generated publication report
โ”œโ”€โ”€ automation_logs/          # Prediction history JSONs
โ””โ”€โ”€ test_assets/              # Test images for smoke tests
    โ””โ”€โ”€ sample.jpg

โ–ถ๏ธ How to Run

1๏ธโƒฃ Install Dependencies

pip install -r requirements.txt

2๏ธโƒฃ Run the Web Application

python web_app.py
# or specify a port:
python web_app.py 8080

Open: http://localhost:5001

3๏ธโƒฃ Train Models

v1 oral model (MobileNetV2):

python train.py

v2 multimodal oral model (EfficientNetB0 + 4D metadata):

python train_v2.py --epochs-phase1 30 --epochs-phase2 20

v3 skin multimodal model (EfficientNetB0 + 6D metadata):

python train_v2.py --cancer-type skin --epochs-phase1 30 --epochs-phase2 20

With focal loss (recommended when dataset is imbalanced):

python train_v2.py --cancer-type oral --use-focal-loss

With cross-validation:

python train_v2.py --cross-validate --cv-folds 5

4๏ธโƒฃ Evaluate Models

v1 vs v2 oral ablation evaluation:

python evaluate_v2.py

Skin model on held-out test set:

python evaluate_skin.py

Generate research report:

python generate_research_report.py

5๏ธโƒฃ Run Smoke Tests

# Start the server first, then in another terminal:
python system_smoke_test.py

# Or auto-start the server:
python system_smoke_test.py --autostart

6๏ธโƒฃ CLI Prediction (v1 oral)

python predict.py path/to/image.jpg
python predict.py image.jpg 0.35   # custom threshold

๐ŸŽฏ Risk Scoring System

Tier P(cancer) Range Color Action
Low 0.0 โ€“ 0.3 ๐ŸŸข Green Routine monitoring
Medium 0.3 โ€“ 0.7 ๐ŸŸก Amber Further clinical evaluation
High 0.7 โ€“ 1.0 ๐Ÿ”ด Red Urgent specialist referral

๐Ÿ“ˆ Model Performance

Model Val AUC Sensitivity Specificity Notes
Oral v1 (MobileNetV2) 0.993 0.986 0.955 Real images, image-only
Skin v1 (MobileNetV2) 0.943 โ€” โ€” Real images, image-only
Oral v2 (EfficientNetB0 + 4D) 0.784 0.845 0.612 โš ๏ธ Synthetic metadata
Oral v2 training peak (0.992) โ€” โ€” Synthetic metadata

Note: v2/v3 multimodal metrics reflect synthetic metadata. Replace data_clean/metadata.csv with real patient records before any clinical or research claims.


โš ๏ธ Disclaimer (Important)

This system is developed strictly for educational and research purposes.

  • The model performs image-based screening only
  • It does not diagnose cancer or any disease
  • Results must always be reviewed by qualified medical professionals
  • Clinical decisions must not be made based on this tool alone
  • v2/v3 multimodal models are trained on synthetic metadata โ€” not validated for clinical claims

๐Ÿ”ฎ Future Scope

  • Collect real patient metadata to unlock full multimodal accuracy potential
  • Train oral v3 (6D schema) โ€” architecture is ready, training script needed
  • Multi-class oral abnormality categorisation (leukoplakia, erythroplakia, etc.)
  • REST API authentication and rate limiting for research integration
  • Mobile application interface
  • Docker containerisation for reproducible deployment

๐Ÿ‘จโ€๐ŸŽ“ Author

Jay Gautam
B.Tech โ€“ Computer Science (Artificial Intelligence & Machine Learning)


๐ŸŸข Project Status

Component Status
Oral screening v1 (MobileNetV2) โœ… Complete
Skin screening v1 (MobileNetV2) โœ… Complete
v2 Multimodal oral (EfficientNetB0 + 4D) โœ… Trained (synthetic metadata)
v3 Skin multimodal (EfficientNetB0 + 6D) โœ… Architecture ready
v3 Oral multimodal (EfficientNetB0 + 6D) ๐ŸŸก Architecture ready, training pending
Grad-CAM explainability (v1 + v2/v3) โœ… Complete
Flask REST API + SPA UI โœ… Complete
Research report pipeline โœ… Complete
Real patient metadata โŒ Pending (synthetic used for now)
Clinical validation โŒ Out of scope

CuraLens is a technical exploration of AI-assisted screening, designed with responsibility, transparency, and academic integrity at its core.

About

AI-assisted oral cancer screening system using deep learning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors