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)

  1. Create a new Kaggle notebook with GPU T4 enabled
  2. Enable Internet access
  3. Copy kaggle_notebook.py contents into cells
  4. Set your HF username in Config.hub_model_id
  5. 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)

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support