AI-powered histopathological analysis of Oral Squamous Cell Carcinoma from H&E-stained biopsy slides
Problem Β· Solution Β· Features Β· Architecture Β· Datasets Β· Quick Start Β· Training Β· Roadmap Β· License
πΈ β π§ β π β From microscope photo to structured clinical report
Oral Squamous Cell Carcinoma (OSCC) accounts for 90% of oral cancers, with ~377,000 new cases annually worldwide. Survival rates exceed 80% when detected early but plummet below 30% in late stages. The challenge:
- Pathologist shortage: In low/middle-income countries, the pathologist-to-patient ratio can be 1:1,000,000+
- Delayed diagnoses: Biopsies often take 2-4 weeks for processing and review
- Subjective grading: Inter-pathologist agreement on tumor grading is moderate (ΞΊ β 0.5-0.7)
OralPath is a non-commercial research project that builds a mobile-first AI diagnostic assistant to address these gaps.
β οΈ This is NOT a replacement for a pathologist. It is a decision-support tool for resource-limited settings where dedicated oral pathology departments are unavailable. All outputs must be reviewed by a qualified pathologist before any clinical decision-making.
A multi-stage AI pipeline that classifies and grades OSCC from H&E-stained biopsy slides photographed through a standard microscope:
| Stage | Task | Classes | Target |
|---|---|---|---|
| Stage 1 β | Binary Detection | Normal / OSCC | Sensitivity β₯ 0.95 |
| Stage 2 β | Grading | Normal / OSMF / WD / MD / PD | Macro-F1 β₯ 0.65 |
| Stage 3 (v1.2) β | Segmentation | Epithelium / Stroma / TILs / Collagen | mIoU β₯ 0.85 |
Results are surfaced through an Android app (Jetpack Compose) with structured reports, confidence scores, and full offline capability via TFLite.
π¬ AI Pipeline
- Frozen foundation backbones β UNI (ViT-L/14), CTransPath, or EfficientNetB3 extract rich features without fine-tuning
- Multi-source training β Combines 5 public datasets (~2,084 cases) for robust generalization
- Multiple Instance Learning (MIL) β Whole-slide classification from patch embeddings using Attention-Top-K pooling
- Stain normalization β Macenko & Reinhard algorithms correct cross-lab H&E staining variation
- Ordinal classification loss β Exploits natural ordering of WD < MD < PD grades
- Focal loss + weighted sampling β Handles severe class imbalance in rare grades
π± Android App
- Jetpack Compose UI β Modern, declarative UI with Material 3 theming
- 5-class result display β Predicted class badge, confidence score, probability distribution bars
- CameraX integration (planned) β Capture slide photos directly from app
- Room/SQLite storage (planned) β Patient case history locally
- PDF report export (planned) β Structured clinical report with disclaimer
- TFLite INT8 on-device (planned) β Offline inference without connectivity
π Training Infrastructure
- Google Colab β VS Code extension for GPU training with automatic dataset setup
- Kaggle Kernels β Pre-submitted kernels with bundled data; GPU probe detects T4/P100
- Lightning AI Studio β Persistent cloud GPU with multi-session resumable training
- PowerShell automation β One-command scripts for submit/monitor/download across all runtimes
- Resumable checkpoints β Training can pause/resume across Colab session limits
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π± Android App β
β Kotlin Β· Jetpack Compose Β· Coil Β· Room Β· CameraX β
β ββββββββββ ββββββββββββ ββββββββββ βββββββββββββββ β
β βCamera ββββΆβView/Edit ββββΆβInfer ββββΆβResults + PDFβ β
β βCapture β βSlide Img β β(API/TFL)β βReport β β
β ββββββββββ ββββββββββββ ββββββββββ βββββββββββββββ β
β β β
ββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββ
β REST / ONNX / TFLite
ββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββ
β π§ Inference Server β β
β FastAPI Β· ONNX Runtime Β· Python β β
β ββββββββββββββββ ββββββββββββββββββββββββββββ β
β β Preprocess ββββΆβ Stage 1 β Stage 2 β β β
β β(Normalize Β· β β Detection + Grading β β
β β Resize Β· β β Ensemble β β
β β Patch Extract)β ββββββββββββββββββββββββββββ β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββ
β ποΈ Training Pipeline β β
β PyTorch Β· timm Β· transformers β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β βStage 1 β βStage 2 β βStage 3 β β
β βDetection β βGrading β βSegment β (v1.2) β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β Colab Β· Kaggle Β· Lightning AI Β· Local GPU β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π oralpath/
βββ π± android/ # Kotlin Android app (Jetpack Compose)
β βββ app/src/main/java/com/oralpath/
β β βββ MainActivity.kt
β β βββ ui/result/ # Level 1 result screen
β β βββ ui/theme/ # Material 3 color/typography
β βββ build.gradle.kts
β βββ settings.gradle.kts
β
βββ π§ model/ # Python ML pipeline
β βββ config.py # Centralized paths and hyperparameters
β βββ data/
β β βββ datasets/ # Multi-source dataset registry (5 sources)
β β β βββ orchid_source.py, gdc_source.py
β β β βββ multi_oscc_source.py, ndb_ufes_source.py
β β β βββ wsi_patch_extraction.py
β β β βββ orchestrator.py # Unified CLI entry point
β β βββ preprocessing/ # Dataset loader + zip-backed I/O
β β βββ qa/ # Split builders, stain norm, integrity checks
β βββ training/
β β βββ stage1_detection/ # Binary OSCC/Normal classifier
β β βββ stage2_grading/ # 5-class grading with resumable training
β β βββ mil/ # MIL production pipeline (Attention-Top-K)
β βββ evaluation/ # Metrics + case-level evaluation
β βββ inference/ # CLI inference wrapper (JSON contract)
β βββ kaggle/ # Kaggle kernel source code + bundles
β βββ external/ # CTransPath, ORCHID, OralPatho references
β βββ notebooks/ # Colab bootstrap notebook
β
βββ π docs/ # Comprehensive documentation
βββ π scripts/ # PowerShell + Python automation
βββ π§ͺ tests/ # pytest test suite
βββ π¦ external/ # Git submodules (OralPatho reference)
OralPath combines 5 public datasets totaling ~2,084 cases β one of the most comprehensive OSCC training collections for a research project:
| Dataset | Type | Size | Grade Labels | Use | License |
|---|---|---|---|---|---|
| Kaggle OSCC | Patches | 1,224 (230 patients) | Normal / OSCC | Stage 1 binary | CC BY 4.0 |
| ORCHID | Patches | 23,000+ | Normal / OSMF / WD / MD / PD | Stage 2 grading | CC BY 4.0 |
| TCGA-OSCC | WSIs | ~257 | Grade info | MIL (Stage 2+) | GDC Open |
| CPTAC-OSCC | WSIs | ~165 | Grade info | MIL (Stage 2+) | GDC Open |
| Multi-OSCC | WSIs | 1,325 | Grade info | MIL (Stage 2+) | CC BY-SA 4.0 |
| NDB-UFES | Patches | 3,763 | Tissue type | Segmentation (v1.2) | CC BY 4.0 |
| Model | Role | License |
|---|---|---|
| UNI (Mahmood Lab, ViT-L/14) | Primary backbone | CC BY-NC-ND 4.0 |
| CTransPath | Secondary backbone | GPLv3-NC |
| CONCH (Mahmood Lab) | Research benchmark | CC BY-NC-ND 4.0 |
| EfficientNetB3 | Fallback / benchmark | Apache 2.0 |
- Python 3.10+
- Git
- Android Studio (for mobile app development)
# Clone the repo
git clone https://github.com/ORION2809/OSCC.git
cd oralpath
# Create and activate virtual environment
python -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS/Linux:
# source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Unified dataset download + manifest generation
python scripts/download_datasets.py
# Verify manifests (dry run β no extraction needed)
python model/data/preprocessing/dataset_loader.pypython model/inference/stage2_predict.py \
--image path/to/slide_image.png \
--checkpoint path/to/stage2_checkpoint.pt# Open android/ in Android Studio
# Sync Gradle β Select device/emulator β Run# Stage 1 β Binary Detection (OSCC vs Normal)
python model/training/stage1_detection/train.py \
--config model/training/stage1_detection/config.yaml
# Stage 2 β 5-Class Grading
python model/training/stage2_grading/train.py \
--config model/training/stage2_grading/config.yaml# 1. Install the "Google Colab" VS Code extension
# 2. Open model/notebooks/oralpath_colab_bootstrap.ipynb
# 3. Click "Connect to Colab Runtime" β select a GPU backend
# 4. Run cells to mount Drive, clone repo, install deps, launch trainingπ See docs/COLAB_SETUP.md for the full VS Code + Colab workflow.
ποΈ Kaggle Kernels
# Submit Stage 2 training kernel
.\scripts\run_kaggle_stage2.ps1
# Monitor progress
.\scripts\kaggle_stage2_status.ps1
# Download results when complete
.\scripts\download_kaggle_stage2_outputs.ps1β‘ Lightning AI Studio (Recommended for Production)
# Set your SSH target
$env:LIGHTNING_SSH_TARGET = "s_xxx@ssh.lightning.ai"
# Launch production MIL training
.\scripts\run_lightning_mil_production.ps1
# Monitor
.\scripts\lightning_mil_status.ps1π See docs/LIGHTNING_TRAINING_HANDOFF.md for the canonical training guide.
The most advanced experiment in the project uses Multiple Instance Learning for case-level classification:
- Embedding Extraction β UNI backbone produces 1024-dim patch embeddings from 5 data sources
- Top-K Attention Pooling β Learns to weight the most diagnostically-relevant patches
- Focal Loss β Handles class imbalance across grades
- 5-Fold Stratified Cross-Validation β Per-source disaggregated metrics track generalization
# Extract embeddings
python model/training/mil/extract_embeddings.py
# Train MIL model
python model/training/mil/train_mil_v2.py \
--config model/training/mil/config.lightning_mil_production.yaml# Run the full test suite
pytest tests/ -v
# Run specific test modules
pytest tests/test_multi_source_pipeline.py -v
pytest tests/test_data_qa.py -v
pytest tests/test_mil_port.py -v| Component | Status | Notes |
|---|---|---|
| Stage 1 (Binary Detection) | β Prototype | Trained as background artifact |
| Stage 2 (Grading) | π Iterating | Run B: macro-F1 0.48; targeting β₯ 0.65 |
| Multi-source MIL | π’ Pipeline ready | Awaiting production run on Lightning AI |
| Stage 3 (Segmentation) | β³ Deferred | Target v1.2 |
| Android App | π‘ Level 1 skeleton | Mock result screen complete |
| Inference API | π Spec complete | JSON contract defined in docs |
| ONNX/TFLite Export | β³ Planned | |
| Kaggle Integration | GPU detection bug; Lightning AI preferred |
| Class | Precision | Recall | F1-Score |
|---|---|---|---|
| Normal | 0.65 | 0.74 | 0.70 |
| OSMF | 0.41 | 0.48 | 0.44 |
| WD-OSCC | 0.47 | 0.57 | 0.51 |
| MD-OSCC | 0.24 | 0.12 | 0.16 |
| PD-OSCC | 0.56 | 0.52 | 0.54 |
| Macro Avg | 0.47 | 0.49 | 0.48 |
Current focus: Improving MD-OSCC recall via focal loss, weighted sampling, and ordinal loss.
v0.1 ββ Research scaffold (this release)
β β’ Repository structure, model interfaces, Android skeleton
β β’ Multi-source dataset pipeline (5 sources)
β β’ MIL production pipeline (Attention-Top-K)
β β’ Kaggle + Colab + Lightning AI training automation
β
v1 ββββ Detection + grading pilot
β β’ Stage 1 binary model (sensitivity β₯ 0.95)
β β’ Stage 2 grading model (macro-F1 β₯ 0.65)
β β’ Android: camera capture, inference display, case history
β β’ ONNX export + FastAPI inference server
β
v1.2 ββ Segmentation
β β’ Stage 3: MobileViT for tissue component ID
β β’ TILs analysis, tumor-stroma ratio
β
v2 ββββ Clinical pilot
β’ Multi-centric validation study
β’ Regulatory pathway assessment (IRB, CE/FDA)
β’ On-device TFLite INT8 inference
| Document | Description |
|---|---|
ARCHITECTURE.md |
System architecture, inference contract JSON, API spec |
VISION.md |
Product vision, problem statement, target users, success metrics |
MODEL_CARD.md |
Model descriptions, intended use, limitations, fairness |
DATASETS.md |
Complete dataset inventory, licenses, download instructions |
IMPLEMENTATION_PLAN.md |
Workstreams, acceptance gates, timeline |
COLAB_SETUP.md |
VS Code + Colab training workflow |
KAGGLE_STAGE2_TRAINING.md |
Kaggle kernel submission runbook |
LIGHTNING_TRAINING_HANDOFF.md |
Canonical Lightning AI training guide |
ORALPATHO_ADAPTATION.md |
Notes on adapting OralPatho reference architecture |
DATA_QA_REBUILD_REPORT.md |
Dataset quality assurance and rebuild |
This is a non-commercial research project. Contributions are welcome in the spirit of open science:
- Fork the repo
- Create a feature branch:
git checkout -b feature/my-idea - Commit your changes:
git commit -m 'Add my idea' - Push:
git push origin feature/my-idea - Open a Pull Request
Areas where help is especially valuable:
- Improving MD-OSCC grading recall
- Adding new dataset sources
- Android UI development
- ONNX/TFLite export and optimization
- Documentation and test coverage
- OralPatho β Reference architecture adapted for MIL (MIT license) β Repository
- Mahmood Lab β UNI and CONCH foundation models β UNI | CONCH
- CTransPath β Transformer-based pathological feature extractor β Repository
- Dataset authors β Kaggle OSCC (Tabassum et al.), ORCHID (NishaChaudhary23), TCGA, CPTAC, Multi-OSCC (Cavalcante et al.), NDB-UFES
- Google Colab, Kaggle, and Lightning AI for GPU compute resources
- Application code: MIT or Apache 2.0 (to be finalized)
- Models & datasets: Varies per component β see
docs/DATASETS.mdfor per-component licensing - Project status: Non-commercial research. NC-licensed models (UNI, CONCH, CTransPath) are used under their research terms
This application is intended for RESEARCH USE ONLY.
It does not provide a definitive medical diagnosis. The software is not cleared or approved by the FDA, CE, or any other regulatory body for clinical use. All outputs must be reviewed by a qualified pathologist before any clinical decision-making. The developers assume no liability for any clinical decisions made based on this software.
Report Bug Β· Request Feature Β· Join Discussion