When a medical image classifier moves to a new hospital, two things change at once. The images look different because of new scanners, cameras, or stains. The mix of diseases also changes: a referral center sees far more melanoma than a screening clinic does. A cheap and popular fix for the second problem is to re-balance predictions at test time. The deployed model's outputs over a batch of patients are forced to match a target class prevalence, either through a constrained assignment step (optimal transport, a method for matching one distribution of "mass" to another at minimum cost) or through logit adjustment. This works well when classes look clearly different. Many medical labels do not. Benign nevus and melanoma, adjacent fibrosis stages, and histology subtypes are separated by small cues that a shifted model reads poorly. We argue that flat rebalancing then mostly reshuffles errors among look-alike classes in order to fill quotas. Enforcing fine-grained prevalence helps exactly where classes are separable and hurts where they are not.
The proposal is to make the strength of the balancing constraint follow class separability. Prevalence is enforced hard at a coarse level of the diagnostic hierarchy, such as benign versus malignant or early versus late stage. Clinicians often know prevalence at this level for their site, and classes at this level remain distinguishable after a domain shift. Within each coarse group, fine-grained prevalence is imposed only softly. The softness is set by how confusable the sibling classes are. This is a small change to the transport objective, and it yields a testable claim: the benefit of fine-grained balancing should shrink, and eventually reverse, as sibling confusability rises. If that relationship holds, it tells practitioners when label-shift correction is safe for a clinical classifier, which matters as much as the method itself.
Core Claim and Where It Sits
Inference-time optimal transport for label shift is established. OTTER builds a cost matrix from negative log-probabilities and solves for an assignment whose class totals match a given prior, with no parameter updates. It reports a 4.8% average accuracy gain on image tasks. Its guarantees assume fixed class-conditional features, and it notes that badly misspecified priors cause negative transfer. Our proposal builds on OTTER as its method source. We change one thing: the constraint is hierarchical and graded by confusability rather than flat and hard.
The closest medical work, TTADC, handles unknown label shift in multi-center CT. It trains a committee of classifiers, each specialized to a skewed class distribution, and reweights them at test time by augmentation consistency. It never imposes a target marginal and does not reason about which classes are confusable. DeepHOT uses unbalanced transport, meaning transport whose totals need not match exactly. It applies this to align image features across domains and deliberately relaxes label mass, so it discards prior knowledge about prevalence. We relax label mass selectively instead: hard where we trust it, soft where we do not. Negative Pseudo Labeling motivates the coarse-prior regime. It shows that known class proportions are useful supervision for visually similar pathology subtypes, raising mIoU from 0.420 to 0.435. It requires proportions for every slide and works within a single cohort. The hierarchy-aware geometry of hyperbolic prototype networks supplies the grouping and a severity metric. That work reduces mistake severity from 1.95 to 1.82 on molemap+, under full supervision and without domain shift.
Research Program
We first fix notation. Let $p(j\mid x_i)$ be the deployed model's probability of fine class $j$ for test image $i$ in a batch of $n$ images. Let $C_{ij}=-\log p(j\mid x_i)$ be the cost of assigning image $i$ to class $j$. Each fine class $j$ belongs to one coarse group $G$ of the diagnostic tree. We solve for an assignment plan $P\in\mathbb{R}_{\ge 0}^{n\times K}$, whose entry $P_{ij}$ is how much of image $i$ goes to class $j$:
$$ \min_{P}\ \langle P, C\rangle \;+\; \sum_{G} \lambda_G\, \mathrm{KL}\!\big(m_G(P)\,\big\|\, q_G\, r_G\big) \quad \text{s.t.}\quad P\mathbf{1}=\tfrac{1}{n}\mathbf{1},\ \ \sum_{j\in G}\sum_i P_{ij}=q_G . $$
Here $\mathbf{1}$ is the all-ones vector. $q_G$ is the coarse prevalence of group $G$, either known from site records or estimated. $r_G$ is a fine-level prior within the group. $m_G(P)$ is the vector of fine-class totals inside $G$. $\lambda_G$ controls how strongly those fine totals are pulled toward $q_G r_G$. The coarse totals are hard constraints. The fine totals are soft penalties, so the problem can be solved with standard generalized Sinkhorn scaling (an iterative row-and-column rescaling algorithm) at roughly OTTER's cost.
The key quantity is $\lambda_G$. We set it from a separability score $s_G\in[0,1]$, computed as within-group balanced accuracy minus chance on held-out source data, and use $\lambda_G=\lambda_0\, s_G/(1-s_G+\epsilon)$. The reasoning is simple. If sibling classes had identical image distributions, every within-group assignment meeting the quotas would have the same expected error. Fine-level quotas would carry no information about individual images and would add only the risk of a wrong $r_G$, so $\lambda_G$ should go to zero. If the siblings are well separated, flat OTTER's guarantees apply, so $\lambda_G$ should be large.
Source-measured separability overstates target separability, because the domain shift blurs the cues. This is the main weakness of the design, and we address it directly. We compare the source estimate against a target-side proxy: agreement between the predicted label on an image and on an augmented copy of it, restricted to the group. This proxy needs no target labels. We report which estimate predicts the realized gains better.
The method is a decision layer, so it composes with feature-level adaptation. We apply it on top of a source-only model, a domain-adversarial model (DANN), and an entropy-minimizing test-time adapter. This lets us separate fixing the images from fixing the prevalence.
Baselines
The naive reference is the source-trained classifier applied unchanged, which is the starting point of every cited benchmark. On IMPS, Domain Adaptation for Skin Lesion reports that this model reaches 88.60% AUROC but only 41.25% F1. It falls to 16.29% F1 on the imbalanced PAD-UFES subset. Paired with it is a post-hoc threshold or temperature tuned on source validation data, which is what a clinician-facing deployment would actually try first.
The strongest feature-adaptation competitor is DANN on the same IMPS split, reported at 63.45% F1 on full IMPS and 74.32% on PAD-UFES in the same paper. Beating it means our label layer on a source-only model matches or exceeds 63.45% macro-F1 without touching the backbone, or that DANN plus our layer exceeds DANN alone by more than the seed-to-seed spread. We retrain DANN ourselves with the same backbone, augmentations, and hyperparameter search budget, and use the same unlabeled target batches.
The strongest label-shift competitor is flat OTTER given the same coarse-plus-fine prior information. It is run on identical logits and batches, with its reported advantage over iterative Prior Matching kept in view (87.0% vs 9.5% on Caltech256). We found no reported result on Lacuna for OTTER on any medical benchmark, so we establish that number ourselves. We also include expectation-maximization prior re-estimation with Bayes logit correction, and TTADC on the CT fibrosis task if access to that data is obtained. TTADC is reported at 50.7% accuracy vs 40.7% source-only on the hardest external set in TTADC.
Two ablations isolate the key ingredient. The first enforces only coarse marginals ($\lambda_G=0$). The second uses a single shared $\lambda$ for all groups. The claim is supported only if confusability-graded $\lambda_G$ beats both.
Why not just…?
Why not just use logit adjustment or expectation-maximization prior correction? These shift every image's scores by the same per-class offset. They assume the class-conditional image distribution is unchanged, which is false across sites. OTTER also documents how fragile iterative prior matching is to tuning. We run both as baselines on identical logits. If they match our method on macro-F1 and mistake severity, the transport machinery is unnecessary and we will say so.
Why not just apply flat OTTER with a good prior? This is the direct competitor, and our hypothesis is specific: flat OTTER should gain on separable groups and lose on confusable ones. We test this by stratifying per-group error change against $s_G$. If flat OTTER shows no loss on confusable groups, our premise is wrong.
Why not just enforce coarse prevalence and stop? This is the real threat. In many deployments the coarse groups may carry nearly all of the benefit. The coarse-only ablation settles it. If grading the fine-level constraint adds nothing beyond coarse balancing, the paper's contribution narrows to a finding about where the useful prior information lives. That finding is still worth reporting, but the method claim would be dropped.
Why not just do feature adaptation such as DANN or TENT? These address image shift but not prevalence. The HAM10000 UDA benchmark found that adaptation methods vary widely when target melanoma prevalence drops to 4%, and some targets resist all of them. The composition experiments show whether the two corrections are additive.
Proposed Experiments
The main setting trains on ISIC dermoscopy, grouping its classes into benign and malignant, and tests on IMPS and its PAD-UFES subset. It also uses the HAM10000-derived targets (HA, HLH, HLP, BCN20k, MSK), whose shifted melanoma ratios provide natural label shift. On each target we additionally resample to controlled priors drawn from Dirichlet distributions, so we can sweep the severity of label shift. We also corrupt $q_G$ and $r_G$ by known amounts to measure robustness to a misspecified prior. CT fibrosis staging, where adjacent stages form the groups, is a secondary ordinal setting conditional on data access. CUB-Paintings, with the bird taxonomy, serves as a non-medical control.
We report macro-F1, balanced accuracy, AUPRC for the malignant classes, and hierarchical mistake severity. Every result is given over five seeds and over batch sizes from 16 to the full target pool, because transport methods need batches and degrade in streaming settings.
The decisive check is the per-group scatter of accuracy change under fine-level balancing against sibling separability. If the slope is positive, crossing zero at low separability, and graded $\lambda_G$ tracks it, the claim stands. A flat scatter refutes it.
References
- OTTER: Effortless Label Distribution Adaptation of Zero-shot Models
- Test-Time Adaptation with Calibration of Medical Image Classification Nets for Label Distribution Shift
- Unsupervised Domain Adaptation via Deep Hierarchical Optimal Transport
- Negative Pseudo Labeling Using Class Proportion for Semantic Segmentation in Pathology
- Skin Lesion Recognition with Class-Hierarchy Regularized Hyperbolic Embeddings
- Domain Adaptation for Skin Lesion: Evaluating Real-World Generalisation
- Mitigating the influence of domain shift in skin lesion classification: A benchmark study of unsupervised domain adaptation methods