A whole-slide image (WSI) is a gigapixel scan of a stained tissue slide. Classifiers for WSIs usually cut the slide into thousands of small patches, encode each patch, and let a pooling network decide how much each patch counts toward the slide label. This patch-weighting setup is called multiple instance learning (MIL), and the pooling network is the aggregator. When such a model moves to a new hospital, its accuracy can collapse. One frozen-to-paraffin cohort transfer fell from 0.8848 to 0.6497 AUC (EPLA), and a model can also fail just because the slide was recolored (Wenzel et al.). The usual remedy treats the whole slide, or the whole hospital, as one thing to normalize or align. Our view is different: the damage is done by a subset of patches, those whose influence on the slide decision depends on stain color rather than on tissue.
We propose to find those patches directly and down-weight them, on the target slide, without target labels. For each patch, a structure-preserving stain generator re-renders the patch in several realistic hospital styles. We then measure how much that patch's contribution to the slide prediction changes across the re-renderings, and we shrink the aggregator's attention on patches whose contribution is unstable. Two features separate this from prior work. The transferability score is a counterfactual stability test, not a domain discriminator. And it scores each patch's contribution to the decision rather than its features, which keeps "is this patch diagnostic?" apart from "does this patch's vote survive a change of stain?"
Core Claim
We claim that the negative transfer of WSI classifiers across hospitals sits largely in the aggregator's attention. We further claim that a label-free, per-patch gate based on stability of decision contribution under realistic stain counterfactuals recovers more cross-hospital accuracy than spending the same counterfactuals on augmentation or consistency training.
The motivating evidence comes from Do Multiple Instance Learning Models Transfer?. That study pretrains 11 aggregators on pan-cancer data and finds, by comparing representations before and after fine-tuning, that attention layers barely change. Attention patterns therefore travel with the model, and if they lock onto stain-specific cues, fine-tuning will not undo it. That paper studies transfer between tasks and never tests hospital or scanner shift, which leaves this risk open.
We also have to explain why the obvious transplant fails, which is to bring the patch-level domain discriminator of TVT into MIL. TVT scores each image token by how well a discriminator can tell its domain and uses that score to reweight self-attention, reaching 83.6% on Office-Home. In pathology, stain shift is applied to the whole slide. A discriminator trained on three source hospitals can identify the hospital from almost any patch's color, so its scores track hue rather than which patches mislead the decision. The counterfactual score avoids this problem. A patch can change color under re-rendering and still be kept, provided its vote does not change.
Mechanism
Let slide $X$ contain patches $x_1,\dots,x_n$ with frozen encoder features $h_i$. An attention aggregator in the style of CLAM produces weights $a_i$ and a per-patch logit contribution $c_i = a_i\, w^\top h_i$, where $w$ is the classifier head. Let $G(x, s)$ be a content/style-disentangled stain generator that re-renders patch $x$ with style code $s$. For this we reuse HistAuGAN (Structure-Preserving Multi-Domain Stain Color Augmentation), which raised mean local diversity across Camelyon17 centers from 0.20 to 0.85, meaning the centers mix in feature space, and which produced tiles a pathologist often could not tell from real ones.
Sampling $K$ style codes $s_1,\dots,s_K$ from the source centers and the target slide's own inferred style, we define the instability of patch $i$ and the gated attention as
$$ u_i = \frac{1}{K}\sum_{k=1}^{K}\big|c_i(G(x_i,s_k)) - c_i(x_i)\big|, \qquad \tilde a_i = \frac{a_i\, e^{-u_i/\tau}}{\sum_j a_j\, e^{-u_j/\tau}}, $$
where $\tau$ is a temperature. The slide prediction pools $w^\top h_i$ with $\tilde a_i$ in place of $a_i$.
Recomputing $c_i$ under re-rendering lets $a_i$ itself move, so $u_i$ captures attention drift as well as head drift. To keep the cost manageable, the gate is computed only on the top patches by original attention, about 512 per slide, since only these can move the decision.
The gate is used during source training as well, so the aggregator learns to classify with unstable patches removed. At deployment it is computed again on each target slide. That makes each slide its own domain, in line with the finding in MixUp-MIL that mixing features across slides hurts while mixing within a slide helps. The temperature $\tau$ is chosen by leave-one-source-center-out validation, and the target is never consulted. This responds to the hyperparameter-selection problem that WILDS 2.0 raises for unsupervised adaptation. We will also report a full sensitivity curve over $\tau$.
Research Program
The work has three parts.
The first is a diagnostic study that tests whether the premise is true before any method is built. On Camelyon17, which provides slide labels and tumor annotations across five centers, we train ABMIL- and CLAM-style aggregators on three centers. On the held-out centers we measure two things: how much attention mass shifts onto non-tumor tissue, and whether high-$u_i$ patches account for that shift. If attention on held-out centers does not concentrate on high-instability patches, the core claim is false and the project stops at a negative result worth reporting.
The second part builds the gate and compares it against controls that use the identical generator and the identical number of counterfactual views. This is the comparison that matters, because it separates "gating" from "having a good stain generator."
The third part stress-tests the method on a shift the generator cannot model: frozen-section TCGA-COAD to FFPE Asian-CRC for MSI prediction, the setting of EPLA. Freezing artifacts are structural changes, not color changes. We therefore predict a smaller gain here, and we will report it as a boundary of the method rather than as a headline.
Baselines
The naive reference is empirical risk minimization (ERM), meaning plain training on the source hospitals: an attention-MIL aggregator on fixed pathology features, trained on Centers 1–3 and tested on the held-out center, with no adaptation. For slide-level leave-one-center-out Camelyon17 we found no reported result on Lacuna, so we will establish this number ourselves. At patch level, WILDS 2.0 reports ERM falling to 70.8% out-of-distribution accuracy on Camelyon17-WILDS, which shows the scale of the shift.
The strongest existing slide-level aggregator is CAMIL (CAMIL), which adds 8-neighbor similarity-constrained attention and a gate between local and global context. It reports 88.1% AUC on CAMELYON17, though the file does not say whether that split holds out centers. We will rerun CAMIL on our exact center split with its published settings and the same feature extractor. Beating it means higher held-out-center AUC averaged over all leave-one-center-out folds, with non-overlapping bootstrap intervals. Because CAMIL's neighbor affinity is based on appearance, we expect it to spread stain artifacts across tissue regions rather than remove them. Our gate can also be applied on top of CAMIL, which is the fairest test of whether it adds something.
The strongest competitor on our specific question uses the same HistAuGAN generator in two ways that do not involve gating. In the augmentation arm, every slide is trained with $K$ re-rendered copies, as the HistAuGAN authors do. In the consistency arm, training adds a penalty that is exactly $\sum_i u_i$ on source slides, so it uses the same quantity we gate on, but as a training loss instead of an inference-time filter. Both arms get the same number of generator calls, the same epochs, and the same validation-based tuning budget.
Two more adaptation baselines cover the alternatives a reviewer would raise. One is DANN, a domain-adversarial method that aligns pooled slide features across centers. The other is a TVT-style transplant, where a patch-level center discriminator's scores replace $u_i$ in the same gating formula; this isolates the choice of transferability signal. Slide-level self-training, using target pseudo-labels in the spirit of Noisy Student (86.7% at patch level in WILDS 2.0), serves as the strongest unsupervised competitor.
On the MSI transfer, the references are EPLA's direct evaluation at 0.6497 AUC and its supervised target fine-tuning at 0.8504 AUC. The second number uses target labels, so it is an upper reference that our unsupervised method should approach but is not expected to exceed.
The key ablations follow from the design. We replace decision-contribution instability with feature instability $\|h_i(G(x_i,s)) - h_i(x_i)\|$ to test whether separating relevance from transferability matters. We replace $u_i$ with random scores matched in distribution to test whether the gate is merely sparsifying attention. We drop the target-slide style from the sampled codes to test the slide-as-domain component.
Why not just…?
Why not just augment with HistAuGAN or stain jitter and skip the gate? This is the most serious threat. Augmentation makes the model invariant on average, but it gives no guarantee about the particular patches a given target slide's attention lands on. Targeted stain augmentation in Connect Later adds only 1.1% (DenseNet-121) and 1.4% (CLIP ViT-L) out-of-distribution accuracy on Camelyon17-WILDS. If our augmentation and consistency arms match the gated model under the same generator budget, then the gate is unnecessary and we will say so. The proposal is built to answer exactly that question.
Why not just normalize all slides to one stain? Recoloring with CycleGAN alone cost up to 18% accuracy within a single dataset (Wenzel et al.), and HistAuGAN's authors note that normalization can remove biological cues. Our method never changes the input the classifier sees. It uses re-rendering only to probe stability. We will still include Macenko-style normalization as an extra run.
Why not just use a domain discriminator to score patches, as TVT does? As argued above, the stain shift touches every patch, so a center discriminator's score mostly encodes color. The TVT-transplant baseline tests this directly. If discriminator gating matches ours, the counterfactual machinery adds nothing.
Why not just fine-tune on a few labeled target slides? That works when labels exist: EPLA recovers to 0.8504 AUC. But it needs annotated cases from every new site, and the frozen-attention finding of Do MIL Models Transfer? suggests that fine-tuning may leave the attention pattern largely unchanged. We will measure attention change before and after few-shot fine-tuning, and we will test the gate combined with fine-tuning at 4, 16, and 64 labeled target slides.
Decisive Checks
The method succeeds only if three results hold together.
First, on held-out Camelyon17 centers, the gated aggregator beats both the augmentation arm and the consistency arm with matched generator budgets, and the random-score ablation shows no comparable gain.
Second, the gate must not achieve this by discarding tumor. Using the lesion annotations, we report the fraction of annotated tumor area retained among gated-in patches and the heatmap Dice score. CAMIL's protocol gives 0.515 for CAMIL and 0.459 for CLAM-SB. A gate that improves AUC while lowering Dice would mean it is exploiting something other than tissue.
Third, on frozen-to-FFPE MSI transfer, we report how much of the gap between 0.6497 and 0.8504 AUC is closed without labels. We predict partial recovery, limited because the stain generator cannot model freezing artifacts. A gain here as large as on Camelyon17 would suggest the gate is acting through some route other than stain, and we would investigate that before claiming the mechanism.
References
- A transferrable and interpretable multiple instance learning model for microsatellite instability prediction based on histopathology images
- From modern CNNs to vision transformers: Assessing the performance, robustness, and classification strategies of deep learning models in histopathology
- Do Multiple Instance Learning Models Transfer?
- TVT: Transferable Vision Transformer for Unsupervised Domain Adaptation
- Structure-Preserving Multi-domain Stain Color Augmentation Using Style-Transfer with Disentangled Representations
- MixUp-MIL: Novel Data Augmentation for Multiple Instance Learning and a Study on Thyroid Cancer Diagnosis
- Extending the WILDS Benchmark for Unsupervised Adaptation
- CAMIL: Context-Aware Multiple Instance Learning for Cancer Detection and Subtyping in Whole Slide Images
- Connect Later: Improving Fine-tuning for Robustness with Targeted Augmentations