Back to project

PathOS: prostate cancer grading from whole-slide images (Master's thesis)

A research system that grades prostate biopsy slides into ISUP classes, localises Gleason patterns and flags cribriform architecture, behind a review interface where the pathologist makes the decision. Research prototype, not a clinical tool.

Overview

PathOS is my Master's end-of-study project at the University of Algiers 1 (Intelligent Computer Systems Engineering, 2025-2026), graded 17.75/20. It has three models and a prototype interface. The first predicts the ISUP grade of a whole slide with multiple-instance learning over frozen Virchow2 features. The second segments Gleason patterns pixel by pixel. The third detects cribriform architecture, a pattern linked to a worse prognosis, inside Gleason 4 regions. The interface shows all three as suggestions and keeps the decision with the pathologist.

Problem

A whole-slide image is gigapixel-scale and carries a single slide-level label, so the model has to find the few regions that matter without patch-level annotations. Blurred, folded and empty patches can capture attention and distort the grade. ISUP grading is ordinal, so the work uses an ordinal loss and scores with quadratic weighted kappa rather than plain accuracy.

Context

A two-person Master's thesis, written with Chawki Ahmed Ramzi Belhaddad and supervised by an academic adviser, with clinical guidance from a co-supervising doctor at CHU Parnet. The hospital has no whole-slide scanner yet, so no local slides were used: every experiment runs on public datasets, and the interface is a prototype built around them.

Data

PANDA: 10,616 public biopsy slides from two centres (Radboud and Karolinska), labelled at slide level, grouped by patient so no patient appears in both training and evaluation. SICAPv2: 155 slides from a hospital in Valencia, used as an external test for grading and as the source of the cribriform patches (4,494 Gleason 4 patches from 83 slides, about 17% cribriform). CrowdGleason: 232 test slides from Granada, with slide grades derived from patch-level Gleason labels. Segmentation uses the 5,060 Radboud slides that carry pixel-level masks, split 80/20 by slide. The two external sets come from the same Spanish research consortium, which limits how far their agreement generalises.

My Role

Co-author of the thesis, with Chawki Ahmed Ramzi Belhaddad. The report presents the three models and the prototype as one joint project and does not divide it between the two of us, so I describe it as joint rather than claim a split.

Goals

  • Predict the slide-level ISUP grade from a single slide label, with no patch annotations
  • Show where a grade comes from, and show where the model is wrong as well as where it is right
  • Localise Gleason patterns per pixel and flag cribriform architecture, the finer detail a pathologist looks for
  • Test whether the artifact-aware gate helps, with confidence intervals rather than a single best run
  • Wrap the models in a workflow where the human decision, its justification and its audit trail stay central

Technical Decisions

  • Read SVS/TIFF/NDPI slides with OpenSlide, separate tissue with HSV-Otsu segmentation and tessellate it into 256 px patches kept as a coordinate registry instead of patch folders on disk
  • Embed patches with a frozen pathology foundation model (Virchow2, 1280-d), with GPU Macenko stain normalisation; HistoEncoder was kept as a single-seed control
  • Aggregate with TransMIL and train with the CORAL ordinal loss; ABMIL was evaluated as the lighter alternative
  • Evaluate on a fixed split with a five-seed ensemble and on five-fold cross-validation with out-of-fold predictions, and use paired bootstrap for every comparison of gating variants
  • Segment Gleason patterns with a U-Net on a pretrained ResNet-34 encoder, with quota-based sampling to counter the rarity of Gleason 5 patches
  • Detect cribriform architecture only inside Gleason 4 patches, with non-Gleason-4 pixels painted white before feature extraction, using PhiKoN features and a small MLP head
  • Keep the AI output labelled as a suggestion in the interface, require a justification for any deviation from it, and log it

Architecture

Raw WSI -> OpenSlide tissue segmentation and 256 px patches -> frozen Virchow2 embeddings -> artifact-aware gate -> TransMIL with CORAL loss -> slide-level ISUP grade and attention. A U-Net segments Gleason patterns per pixel and CribriNet flags cribriform architecture inside Gleason 4 regions. All three outputs feed a review interface where the pathologist accepts, edits or rejects the suggestion and signs the report.

Whole-slide grading pipeline

one label per gigapixel slide
REDUCEWSISVS / TIFF / NDPI~10⁹ pixelsOpenSlidetiled patch readerHSV-Otsutissue vs backgroundartifact gatevariance + Median / MADdrops blur + foldspatchesEMBED · FROZENMacenkoGPU stain normalisationHistoEncoder384-d · controlVirchow21280-d · mainTransMIL · CORALattention over bagbagISUP grade6 classes · QWKattention heatmapreprojected on the slideshown to the reviewerattentionCONTEXTMaster's thesis, with Chawki Ahmed Ramzi Belhaddad · private repoPANDA, 5-FOLD CV0.9227 QWK
A slide is billions of pixels and carries a single ISUP grade, so most of the work is deciding what to throw away. An artifact gate (spatial variance and a Median/MAD norm test) drops blurred, folded and background patches before they can dilute the bag, and the thesis tests it with confidence intervals: with Virchow2 it adds no significant gain. Attention weights come back out the other side, which is what turns a number into something a pathologist can point at.

Case Study Screenshots

8 views
The PathOS review interface: the biopsy with the Gleason overlay from the segmentation model, and the suggestion panel. The panel states that the output is decision support, never the final diagnosis, and flags when the grade and the segmentation disagree.
The same slide with the attention view: each patch is coloured by the weight the grade model gave it, so a reviewer can see where the suggestion comes from.
The worklist, with test slides. A case stays awaiting review until a pathologist signs it out; the suggestion never closes a case on its own.
The platform around the models: web interface and API, durable workflows for import, preprocessing, inference and aggregation, a Python inference worker, and storage for slides and results. Labels are in French, as in the thesis.
PANDA fixed test split (1,061 slides), 0.9134 QWK. Most errors fall between adjacent grades, mainly ISUP 1 and 2. Axis labels are in French, as in the thesis.
Attention over three test biopsies: two correct grades (ISUP 3 and 4) and one adjacent-grade error (true ISUP 1, predicted 2), kept in because failures are part of the evidence.
Gleason segmentation against the pathologist masks: a correct Gleason 3 region, an adjacent-grade error, and a Gleason 5 focus predicted as 4, the class every variant struggled with.
The artifact gate on Virchow2 embeddings: patches flagged for low spatial variance and outlying norm. It flags roughly 0.5% of patches, and the thesis finds it adds no significant gain with Virchow2.

Key Features

  • Slide viewer with Gleason and attention overlays and a suggestion panel with class probabilities
  • Decision panel: accept, edit or reject, with a mandatory justification and an audit trail
  • Structured report per case, editable before the pathologist signs
  • Worklist and batch import of slides, with durable workflows for preprocessing and inference

Challenges

  • Noisy labels: PANDA's training labels come from routine clinical reporting, so the ceiling is the inter-pathologist variability of Gleason grading itself
  • Gleason 5: the pattern is rare (under 1% of patches), morphologically varied and graded inconsistently between pathologists. Nothing tried moved it past about 0.58 Dice
  • Cribriform detection: few positive examples, labels at patch level while the structure can be cut by the patch edge, and a patch alone gives limited context
  • A negative result to report: the artifact gate, the idea the first part of the work was built around, does not help with Virchow2, and the thesis says so

Results table

Slide-level ISUP grading, quadratic weighted kappa, PANDA-trained model with the full robust gate. SICAPv2 and CrowdGleason are external sets with no retraining; the CrowdGleason figure is the mask-only five-fold ensemble (0.8080 with the full gate).
EvaluationSlidesQWK
PANDA, five-fold cross-validation (out-of-fold)10,6160.9227 ± 0.0046
PANDA, fixed test split (five-seed ensemble)1,0610.9134
SICAPv2, external, no retraining1550.8772
CrowdGleason, external, no retraining2320.8109

Results / Outcomes

  • At the ISUP 2 threshold, which separates active surveillance from treatment, the fixed-split model reaches 92.6% sensitivity (478/516) and 94.5% specificity (515/545); most false negatives are ISUP 2 slides predicted as 1
  • Gleason segmentation reaches 0.753 mean Dice and 0.706 clinical balanced Dice on 5,060 slides. Moving from a from-scratch encoder to a pretrained ResNet-34 and the full slide set was the largest gain; a multi-scale variant was worse and is reported as a negative result
  • Cribriform detection reaches 0.904 AUC and 0.661 F1 with the retained MLP head. An SVM on the same features scored slightly higher (0.918 AUC, 0.662 F1); the MLP was kept because it outputs a probability that feeds the heatmaps directly
  • The artifact gate adds no significant gain: every bootstrap interval on PANDA and CrowdGleason includes zero. The thesis attributes this to Virchow2's register tokens and to the gate flagging only about 0.5% of patches, below the 20% patch dropout used in training
  • The five-fold PANDA score sits next to the 0.916 QWK published for H-ViT, though the protocols differ (cross-validation here, the official Kaggle test there), so the comparison is indicative only

Limitations

  • Research prototype: no clinical validation, no diagnostic claim, and not a medical device
  • Cross-validation is inside PANDA, so it measures stability, not robustness across centres; the external sets are small (155 and 232 slides) with wide confidence intervals, and both come from the same Spanish consortium
  • CrowdGleason's slide grades are derived from patch labels, which adds uncertainty absent from the other sets, and it has almost no intermediate grades, so its macro F1 is low by construction
  • A CORAL-trained model with no gate on the same five folds was not run, so the 0.9227 cannot be credited to the loss rather than the gate
  • Attention weights are not causal explanations; high-norm tokens from non-tissue regions can attract them, so heatmaps need expert review before anyone relies on them
  • No pathologist study yet, and the interface has only run on public and test slides

What I Learned

  • Report the protocol next to every number: the same model is 0.9134 on one split and 0.9227 cross-validated, and picking the best of seven single runs would overstate it
  • A result that disproves your own hypothesis is worth publishing, but only with the mechanism and the confidence intervals that explain it
  • In a clinical setting the interface decides whether a model is usable: the suggestion label, the mandatory justification and the audit trail matter as much as the kappa

Future Improvements

  • Validation on cohorts from other centres, scanners and stains, then a study with pathologists on decision quality and inter-observer variability
  • More cribriform examples and cleaner patch labels, then slide-level aggregation of Gleason 4 patches instead of classifying them in isolation
  • Calibrated confidence scores and uncertainty estimates before any clinical use
  • A multi-seed comparison of Virchow2, HistoEncoder and other pathology encoders, and a CORAL no-gate control on the same five folds