Erasing Artifact Directions Before Fitting Few-Shot Medical Classifiers

When a classifier must learn a new medical category from five labeled images, those five images decide everything. If four of the five melanoma examples happen to show a calibration ruler, the classifier has no way to tell that "ruler" is not "melanoma." The best current recipe for few-shot medical classification is simple: take features from a large pretrained network and fit a regularized linear classifier on them. This recipe has no defense against that failure, and the strongest known fix needs patient identifiers that small, anonymized cohorts usually lack. We propose a different fix. Before fitting the few-shot classifier, estimate the directions in the frozen feature space that encode known imaging artifacts (rulers, chest tubes, skin markings). Estimate them from a small, separate pool of artifact-labeled images, then project those directions out. The classifier is then fit on what remains, so it cannot use the artifact even when the support set is fully confounded.

Put in two sentences: few-shot support sets in medicine are often confounded with artifacts, and a linear head on frozen features will happily learn the artifact. We remove the artifact's linear signature from the features using about ten expert-labeled examples per artifact group, with no patient metadata and no retraining, and test whether this restores accuracy on images where the artifact–disease pairing is reversed.

Core Claim

The claim is that in medical foundation-model features, the dominant shortcut artifacts are close to linearly separable from disease signal. If so, a closed-form projection estimated from a handful of artifact-labeled images is enough to make the standard linear few-shot head robust to confounded support sets. The projection would recover most of the worst-group accuracy that metadata-dependent contrastive retraining achieves, while keeping the simplicity and in-domain accuracy of the linear baseline.

Write $f(x)\in\mathbb{R}^d$ for the frozen embedding of image $x$. Write $U\in\mathbb{R}^{d\times r}$ for an orthonormal basis of $r$ artifact directions, estimated as class-conditional differences between artifact-present and artifact-absent prototypes. The classifier is fit on

$$\tilde f(x) = (I - UU^\top)\, f(x),$$

followed by $\ell^2$ normalization. Estimating $U$ within each disease class is the key ingredient. Without that conditioning, the "artifact direction" would absorb disease signal whenever artifact and disease co-occur in the estimation pool.

This claim can fail in a clear way. If an MLP probe can still decode the artifact from $\tilde f$ while worst-group accuracy does not improve, the shortcut is nonlinear and the idea is wrong in its simple form.

Why this, and how it differs from prior work

Two papers set the bar. A Comparison of Machine Learning Methods for Cross-Domain Few-Shot Learning benchmarks frozen extractors with shallow heads on the cross-domain few-shot benchmark that includes ISIC and ChestX. It finds that $\ell^2$-regularized logistic regression and cosine classifiers match or beat episodic meta-learning, and that $\ell^2$ feature normalization is critical. That paper supplies our method's skeleton: we keep its head and change only the features it sees. It also never looks at shortcuts, and that omission is the gap we target. SpurCon supplies our annotation protocol. It labels artifacts from roughly 10 expert examples per group using BiomedCLIP prototypes. It then trains a projection head with a weighted contrastive loss over same-patient pairs that differ in artifacts, and raises worst-group accuracy on ISIC 2020 from 0% to 65.0%. Our proposal reuses its first phase and replaces its second with a training-free projection that does not need Patient IDs. In single-encounter or de-identified cohorts, SpurCon's loss cannot be defined.

Several papers motivate the problem. Unveiling COVID-19 from Chest X-ray with deep learning shows small-cohort models fitting hardware and annotations rather than lung findings, and collapsing on external data. On the CORDA cohort it reports sensitivity 0.54 and specificity 0.80 even with lung segmentation. A Closer Look at the Training Strategy for Modern Meta-Learning proves that episodic training generalizes at a rate set by the number of tasks, not shots. That guarantee assumes tasks are drawn independently from one distribution. A confounded clinical support set violates exactly this assumption, which is why we do not expect episodic training alone to help.

Two other papers constrain the design. Subspace Regularizers for Few-Shot Class Incremental Learning pulls novel-class weights toward the span of base-class weights. We use the same linear-algebra tool in the opposite direction, pushing the classifier away from an artifact span. Its known weakness also warns us: when the relevant structure is not linear, projections underfit. MedMFG synthesizes extra support features with a variational autoencoder behind a frozen backbone. It reaches 69.2% versus 64.7% for fine-tuning on CRC-TP→NCT 1-shot. Nothing in it stops the generator from reproducing artifact variation, so we test whether it amplifies shortcuts and whether sampling inside the projected space prevents this.

Research Program

The first stage is a measurement study, and it decides whether the method is worth building. On ISIC 2020 (rulers, skin markings) and CheXpert (support devices), we embed images with BiomedCLIP and with an ImageNet ResNet-10, the standard extractor for the cross-domain benchmark. We then ask how much artifact information is linearly decodable, how many directions it occupies, and how much disease accuracy is lost when those directions are removed from correctly balanced data. If removing artifact directions costs substantial disease accuracy even on balanced data, artifact and disease are entangled, and the method should stop here.

The second stage builds the estimator. We estimate $U$ from a pool of about 10 artifact-labeled images per (class, artifact) cell, labeled with SpurCon's Pick-and-Predict protocol. We take within-class prototype differences, average across classes, and orthonormalize; $r$ is chosen by explained variance on the pool alone. A variant uses only artifact-positive versus artifact-negative images from unlabeled-disease data, which tests whether disease labels in the pool are needed at all.

The third stage is the few-shot evaluation under controlled confounding, described below. The fourth stage checks whether MedMFG-style feature generation reproduces the artifact. We measure artifact decodability of generated features, with and without first projecting the support features.

Baselines

The naive reference point is a frozen extractor with an $\ell^2$-normalized, $\ell^2$-regularized logistic regression, or a cosine-prototype head. These are the best performers in A Comparison of Machine Learning Methods for Cross-Domain Few-Shot Learning. This baseline also serves as the strongest few-shot competitor, because that paper shows meta-learners do not beat it under domain shift. The file reports only qualitative results for it: ChestX sometimes approaches random guessing, and no per-cell number appears. For its ISIC/ChestX 5-way accuracy, no reported result was found on Lacuna. We therefore rerun it ourselves on identical episodes, with the same regularization grid selected on a held-out validation episode set.

The strongest shortcut-mitigation competitor is SpurCon. It reports worst-group accuracy of 65.0% on ISIC 2020 and 73.0% on CheXpert, both with access to Patient IDs. We run it in two conditions: with Patient IDs where the datasets provide them, and with IDs removed. In the second condition its contrastive loss falls back to class-and-artifact pairs, which is the closest metadata-free reduction. It receives the same BiomedCLIP backbone, the same artifact labels, and the same few-shot head on top of its learned projection. Our method beats it if it matches SpurCon-with-IDs within a few points of worst-group accuracy and clearly exceeds SpurCon-without-IDs, at a small fraction of the compute.

We also include MedMFG as the strongest few-shot generative method, run behind the same frozen backbones. The comparison is on mean accuracy on standard ISIC/ChestX episodes and on worst-group accuracy in confounded episodes. Three ablations isolate the key ingredient. The first removes an equal number of random directions. The second removes directions estimated without class conditioning. The third removes the top principal components of the pool. If random or unconditioned removal does as well, the claim about artifact-specific directions is false.

Why not just…?

Why not just fit logistic regression on BiomedCLIP features and rely on the pretrained representation? The file contains direct evidence against this in the shortcut setting. SpurCon reports 0% worst-group accuracy for the frozen-feature baseline on ISIC 2020, because the feature space ties lesion predictions to rulers. Our confounded-episode experiment will confirm or refute this in the few-shot regime specifically. If the plain head already does well when the support set is fully confounded, the proposal is unnecessary, and we will report that.

Why not just mask or crop the artifact away, as lung segmentation did for chest X-rays? This is a real threat for artifacts that lie outside the anatomy, such as rulers at image borders or text labels. Tartaglione et al. found that segmentation removed hardware outside the lung, but performance was still modest on CORDA. Many devices, such as chest tubes, lie inside the lung field, and dermoscopic markings overlap lesions. We run masking (lung segmentation on CheXpert, border cropping on ISIC) as an explicit competitor and report results per artifact type. We expect masking to tie on peripheral artifacts and lose on overlapping ones. If it ties everywhere, we change the claim to "projection only for artifacts that cannot be masked."

Why not just balance the support set so each class has artifact-present and artifact-absent examples? In a true few-shot deployment, the clinician has whatever five images exist, and they may all carry the confound; balancing assumes extra data the setting excludes. Balancing is still the right upper reference. We report a "balanced-support oracle," and measure how much of the gap between confounded and balanced supports our projection closes.

Why not just meta-train episodically, or augment tasks adversarially? Adversarial Task Augmentation perturbs pixels and textures to make worst-case training tasks, and improves meta-learners across domains. It reports, for example, 68.39%→77.82% on CropDiseases 5-way 1-shot for one meta-learner. Its perturbations are generic texture changes, not artifact-specific, and the linear head already matches meta-learners under shift. We include it on the standard episodes for completeness, but do not expect it to address confounding it was not designed to see.

Proposed Experiments

From ISIC 2020 and CheXpert we construct 2-way and 5-way, 1- and 5-shot episodes. The degree of confounding $\rho$ is the fraction of support images whose artifact status matches their class's majority pattern, swept from 0.5 (balanced) to 1.0 (fully confounded). Queries are group-balanced, and we report worst-group and mean accuracy over 600 episodes with 95% intervals. The artifact-estimation pool is drawn from patients, or images where IDs are absent, that are disjoint from all episodes.

To check that projection costs nothing when no shortcut is present, we also run the standard benchmark episodes on ISIC and ChestX, and transfer to histology on CRC-TP→NCT, where MedMFG reports its 69.2% figure.

The decisive check has three parts. As $\rho\to1$, does worst-group accuracy of the projected head stay near its $\rho=0.5$ value while the plain head falls? Does an MLP probe fail to recover the artifact from $\tilde f$? Does standard-episode accuracy stay within noise of the plain head? A secondary check measures whether MedMFG-generated features carry more artifact information than the real support features, and whether projecting before generation removes this.

If all of these hold, few-shot medical classification gains a shortcut defense that needs ten labeled examples per artifact and no metadata. If the MLP probe still recovers the artifact, the result is still informative: shortcuts in these foundation features are nonlinear, and linear subspace methods of every kind are ruled out for this problem.