YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
π¬ Multi-Class Histology Semantic Segmentation & Anatomy Agent
Architecture: Mask2Former (Swin-B backbone) fine-tuned on PanNuke
Task: Instance segmentation of 5 nuclei types in H&E stained tissue
Dataset: RationAI/PanNuke β 7,904 images, 189,744 annotated nuclei
Classes
| Class | Color | Description |
|---|---|---|
| π΄ Neoplastic | Red | Tumor/cancer cells |
| π’ Inflammatory | Green | Immune cells (lymphocytes, macrophages) |
| π΅ Connective | Blue | Stromal/fibroblast cells |
| π‘ Dead | Yellow | Necrotic/apoptotic cells |
| π£ Epithelial | Magenta | Normal epithelial cells |
Key Features
- Instance segmentation (not just bounding boxes) β precise masks for each nucleus
- Medical-grade augmentation: elastic transforms, H&E stain jitter, geometric transforms
- Sliding-window WSI tiling: 512Γ512 patches with 10% overlap for large images
- Metrics: Mean IoU, Dice Coefficient, Panoptic Quality (per class)
- Visual debugging: GT vs Prediction overlay gallery every 5 epochs
- Trackio integration: real-time loss/metric monitoring
- LLM Knowledge Agent: Qwen3-1.7B explains detected tissue types
- Gradio UI: web-based inference with segmentation overlay
Quick Start (Kaggle)
- Create a new Kaggle notebook with GPU T4 enabled
- Enable Internet access
- Copy
kaggle_notebook.pycontents into cells - Set your HF username in
Config.hub_model_id - Run all cells β training takes ~4-6 hours on T4
# Install dependencies (first cell)
!pip install -q torch torchvision transformers datasets accelerate trackio \
gradio Pillow numpy scipy albumentations opencv-python-headless \
matplotlib scikit-image huggingface_hub safetensors bitsandbytes
Project Structure
βββ kaggle_notebook.py # Single-file Kaggle notebook (all-in-one)
βββ histology_agent/
β βββ config.py # All hyperparameters
β βββ data_pipeline.py # Dataset, augmentation, tiling
β βββ metrics.py # IoU, Dice, Panoptic Quality
β βββ visual_debug.py # GT vs Pred overlay galleries
β βββ llm_knowledge.py # Qwen3-1.7B tissue explanation
β βββ train.py # Training script
β βββ app.py # Gradio deployment
βββ requirements.txt
Training Recipe (from literature)
Based on research from:
- CellViT (arxiv 2306.15350): SOTA on PanNuke, mPQ=0.50
- Mask2Former (arxiv 2112.01527): CVPR 2022, universal segmentation
- SAM fine-tuning (arxiv 2404.09957): PEFT for medical segmentation
| Parameter | Value | Why |
|---|---|---|
| Backbone | Swin-B (ImageNet pretrained) | Strong feature extractor for histology |
| Decoder LR | 1e-4 | Mask2Former paper recommendation |
| Backbone LR | 1e-5 (10x lower) | Preserve pretrained features |
| Scheduler | Polynomial decay (power=0.9) | Mask2Former paper |
| Augmentation | Heavy (elastic, stain jitter) | +0.13 F1 on Dead class |
| Batch size | 2 (T4) / 4 (V100) | Gradient accumulation to effective 8 |
| Input size | 256Γ256 | PanNuke native resolution |
Metrics Explained
| Metric | What it measures | Why it matters |
|---|---|---|
| IoU (Intersection over Union) | Overlap between predicted and ground truth masks | Handles class imbalance better than accuracy |
| Dice | Harmonic mean of precision and recall | Standard in medical imaging |
| PQ (Panoptic Quality) | SQ Γ RQ β combines segmentation quality and detection | Official PanNuke benchmark metric |
License
CC-BY-NC-SA-4.0 (same as PanNuke dataset)
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support