Anatomy as a Training Signal, Not a Filter: Lung-Guided Multi-View Pretraining for Chest X-Rays That Transfer Across Hospitals

Chest X-ray classifiers that look excellent at the hospital that trained them often lose much of their accuracy at the next hospital. Two standard remedies pull in opposite directions. The first is to cut the image down to the lungs so the model cannot latch onto borders, tubes, or scanner watermarks. The second is to give the model both the frontal and the side (lateral) view, so it can see what one projection hides. Cutting to the lungs has a hidden flaw. Automatic lung segmenters fail most often on portable, bedside, front-to-back (anteroposterior, AP) films of very sick patients. Those films are unevenly distributed across hospitals. So the mask that was meant to remove site-specific cues can become a new site-dependent error at test time. There is also no lung-mask resource for lateral views, which blocks the obvious "mask both views" design.

We propose to use the lung mask only while pretraining the image encoder, and to drop it at inference. A self-supervised model learns by reconstructing hidden image patches, a masked autoencoder. Here, its reconstruction loss is concentrated on lung tissue, and each image's mask is trusted in proportion to an automatic quality estimate of that mask. The lateral view gets no mask at all. It is trained to agree with a lung-pooled summary of the paired frontal view, so the anatomical focus carries over to a view that has no segmentation. At test time the model takes raw images, one view or two, and needs no segmenter. The central claim can be tested directly. On leave-one-hospital-out evaluation, the resulting representation should lose less accuracy across sites than three alternatives: whole-image multi-view pretraining, lung-only single-view pretraining, and inference-time lung cropping. The advantage should be largest on AP portable films, where hard masking breaks. We also separate how much of any remaining cross-site gap comes from differences in how hospitals label disease rather than how their images look.

Why this combination, and why now

The ingredients exist separately, and the file shows exactly where each one stops.

Structure is Supervision: Multiview Masked Autoencoders for Radiology (MVMAE) supplies the multi-view method we build on. It pretrains a Vision Transformer on masked reconstruction plus a frontal–lateral alignment loss. It uses more than 870k images from MIMIC-CXR, CheXpert Plus, PadChest and NIH, with labels harmonized into 14 classes by a language model. It reports 87.43 macro-average AUROC and gains even when only one view is present at test time. It treats air, shoulders and lung tissue identically, and it does not report leave-one-institution-out transfer.

RGMIM supplies the anatomical-loss idea. It restricts masked-patch reconstruction to lung patches and reaches 0.771 accuracy with 1% of labels, against 0.754 for a standard masked autoencoder. It is frontal-only, uses a single random split of one dataset, and names its reliance on binary masks as its main bottleneck.

CheXmask supplies the masks and the key constraint. It releases 657,566 frontal lung and heart masks across NIH, CheXpert, MIMIC-CXR, PadChest and VinDr-CXR, each with a per-mask quality estimate called reverse-classification-accuracy Dice. It also reports that segmentation is markedly worse on AP portable films. It has no lateral masks.

Two papers motivate treating hard masking at inference with suspicion. An automated COVID-19 triage pipeline crops frontal films to U-Net lung masks before classification. Mask-weighted global average pooling for CT multiplies features by the lung mask before pooling. Both helped, but both put the segmenter in the test-time path, which is precisely where CheXmask shows it degrades in a protocol- and site-correlated way.

One paper constrains the whole enterprise: On the limits of cross-domain generalization in automated X-ray prediction. It finds that disagreement in how hospitals define and threshold labels, not image appearance, dominates cross-site failure. Any image-level method, ours included, can only fix the image-level share of the problem. We therefore design the evaluation to measure that share rather than assume it is large.

The obvious combination would be "RGMIM plus MVMAE": mask both views and pretrain. That design is not buildable as stated, because lateral masks do not exist. It would also inherit the test-time cascade. Our version differs from each prior work in a specific way. Unlike MVMAE, reconstruction is anatomy-weighted. Unlike RGMIM, it is multi-view, trusts each mask according to its quality, and is evaluated on held-out hospitals. Unlike the triage pipeline and mask-weighted pooling, no mask is used at inference.

Core Claim

Let $x_F, x_L$ be a paired frontal and lateral image, $m$ the frontal lung mask downsampled to the patch grid, and $q \in [0,1]$ a trust weight derived from CheXmask's estimated Dice for that mask. We set $q=0$ below 0.7 and ramp it linearly to 1 at 0.9. Pretraining minimizes

$$ \mathcal{L} = q\,\frac{\lVert (x_F-\hat{x}_F)\odot m \rVert^2}{\lvert m\rvert} + (1-q)\,\frac{\lVert x_F-\hat{x}_F\rVert^2}{N} + \frac{\lVert x_L-\hat{x}_L\rVert^2}{N} + \lambda\,\mathcal{A}\big(\mathrm{pool}_m(z_F),\, g(z_L)\big), $$

The symbols are as follows. $\hat{x}$ is the reconstruction of the hidden patches. $N$ is the number of hidden patches. $z_F, z_L$ are the encoder's patch features. $\mathrm{pool}_m$ averages frontal features over lung patches, and when $q=0$ it falls back to whole-image pooling. $g$ is a small projection head on the lateral features. $\mathcal{A}$ is the MVMAE-style alignment loss, weighted by $\lambda$. Frontal patches to hide are sampled mostly inside the lung, as in RGMIM, when $q$ is high.

The claim has three parts:

  1. Moving anatomy from the inference path into the pretraining loss keeps the cross-site benefit of masking and removes its failure on AP portable films.
  2. Aligning the unmasked lateral view to lung-pooled frontal features transfers anatomical focus to the lateral view.
  3. The resulting encoder works with frontal-only input at hospitals that never acquire laterals.

Research Program

We pretrain ViT-B encoders on the union of MIMIC-CXR, CheXpert Plus and PadChest, which contain laterals. NIH and VinDr-CXR are frontal-only and serve as held-out, single-view test sites. Labels follow MVMAE's 14-class harmonized space, reproduced with the same mapping procedure.

The main protocol is leave-one-dataset-out: pretrain and fine-tune on all but one source, then test on the held-out source. The two frontal-only sites are always external. Every method gets the same images, the same architecture, the same pretraining epochs and the same hyperparameter search budget. That budget covers learning rate, mask ratio and $\lambda$, with equal trials per method, selected on in-source validation only.

We analyze results along two axes the prior work leaves tangled.

Label shift versus appearance shift. We report held-out AUROC under two conditions. In the first, the classification head is frozen from the source sites. In the second, the head is refit on a small labeled sample from the target site: 500 studies, with the encoder frozen. Refitting the head absorbs much of the target site's labeling convention. The gap that survives the refit is therefore a rough estimate of what the representation itself fails to transfer. We check whether our method narrows that gap or only the frozen-head gap.

Covariate shift strength. We compute Fréchet Radiomic Distance between every source–target pair, once on whole images and once inside lung masks. FRD compares distributions of interpretable radiomic features and is reported to remain stable down to $N=10$ samples. It is only meaningful for relative comparisons, which is how we use it. If our gains come from reduced reliance on appearance cues, they should grow with whole-image FRD. If gains are flat across FRD, the image-level story is wrong.

Baselines

The naive reference is a single-view masked autoencoder pretrained on frontal images with uniform random masking, then fine-tuned. This is the "do nothing special" point. RGMIM reports 0.754 accuracy at 1% labels for this kind of model on its own single-site split, a number that is not comparable to our leave-one-out setting.

The strongest existing multi-view method is MVMAE (Structure is Supervision), which reports 87.43 macro AUROC on its pooled evaluation. We reimplement it on our exact splits and budget rather than quote that figure against ours, because its number is not a held-out-hospital number. It is the closest competitor because it already uses the lateral pairing and a similar data pool. Beating it means a higher mean held-out AUROC across the leave-one-out folds, with non-overlapping bootstrap intervals on at least three of five folds, and no in-source loss beyond 0.5 AUROC points.

The strongest single-view anatomical method is RGMIM, run on the same frontal images with CheXmask masks. It isolates what the lateral view adds.

The strongest invariance method is adversarial site removal via a gradient reversal layer, as in Learning Invariant Feature Representation. That work reports out-of-source AUC rising from 0.65 to 0.70 with CheXpert held out, at a cost in in-source accuracy. We apply it on top of the MVMAE encoder with the same tuning budget. It represents the direct "remove the site signal" alternative, and our method should match or beat it out-of-source without its in-source penalty.

The inference-time masking baseline follows the triage pipeline. The frontal image is cropped to its CheXmask lung region at both train and test time, and the lateral is left whole.

Three ablations isolate the key ingredients. The first uses hard masks without quality weighting ($q\equiv 1$). The second applies anatomy weighting to the frontal view but aligns the lateral to whole-image pooled frontal features. The third applies the mask at inference on top of our pretrained encoder.

Why not just…?

Why not just crop to the lungs at test time, as the COVID triage pipeline and mask-weighted pooling did? Cropping works when the mask is right. CheXmask reports that masks are systematically worse on AP portable films. Those are the sickest patients, and their share differs by hospital, so cropping ties test accuracy to segmenter failures that track site and protocol. Cropping also discards the heart border and other context outside the lungs. Our inference-time masking baseline, stratified into AP versus PA and by estimated mask Dice, settles this. If cropping matches our method even in the low-quality-mask stratum, the training-only design is unnecessary, and we would say so.

Why not just take MVMAE and add domain-adversarial training? This is a real competitor and is run as one. Two findings make us doubt it is sufficient. The adversarial approach traded away in-source accuracy in Learning Invariant Feature Representation. Beyond Pooling shows that adding heterogeneous sources can hurt transfer rather than help. Removing "site" as a label also cannot distinguish a scanner artifact from a real prevalence difference, whereas an anatomical loss targets the specific failure of attending outside the lungs. The combined baseline tells us whether the two are complementary. If it equals our method, the anatomical ingredient is not needed.

Why not just fix the labels, since label shift dominates? On the limits of cross-domain generalization is the most serious threat to this proposal. If label disagreement explains nearly all of the cross-site gap, no image-side method can matter much. We do not argue around this; we measure it. The refit-head condition estimates the share attributable to the representation. If that share is small, and our gains vanish once the head is refit, the honest conclusion is that effort belongs in label reconciliation, and we will report that.

Why not just run RGMIM on frontal images and skip the lateral view? Most external hospitals and all bedside studies lack laterals, so a frontal-only model is attractive. MVMAE's evidence that pairing helps even when only one view is present at test time suggests the lateral carries information into the frontal encoder during training. The RGMIM baseline, evaluated frontal-only on NIH and VinDr, tests whether that holds under anatomy weighting.

Proposed Experiments and Decisive Checks

The primary result is mean held-out macro AUROC over the leave-one-dataset-out folds, under both frozen-head and refit-head conditions, with 1,000-sample bootstrap intervals. We also report in-source AUROC to expose any trade-off.

First decisive check: the AP portable stratum. Within each held-out site, we split test films into AP and PA and into CheXmask estimated-Dice bins. The claim predicts the following: our method is at least as good as inference-time cropping on PA films with high-quality masks, and clearly better on AP films with low-quality masks. The no-quality-weighting ablation should sit between the two.

Second decisive check: transfer to a view with no masks. We probe lateral-only classification at the held-out MIMIC, CheXpert and PadChest folds, and inspect attention maps on laterals, comparing the lung-pooled and whole-image alignment ablations. If anatomy-aligned laterals do not beat whole-image-aligned laterals, part two of the claim fails.

Third decisive check: correlation with FRD. We regress each fold's gain over MVMAE on whole-image FRD between source and target. A positive slope supports an image-appearance mechanism. A flat slope, combined with gains that disappear under head refitting, would indicate that the observed improvements are not about cross-site appearance at all.

Label efficiency. Following RGMIM and MVMAE, we repeat fine-tuning with 1% and 5,000-study label budgets on held-out sites. MVMAE reports roughly 80% AUROC at 5,000 labeled studies in its setting, the reference point for whether anatomy weighting adds label efficiency on top of multi-view pretraining.