Letting Context Outside the Organ Speak Only When It Generalizes

Medical image classifiers often get the right answer for the wrong reason. On a chest X-ray, a model may diagnose pediatric viral pneumonia by looking at the growth plates in the shoulders, not at the lungs. On lung ultrasound, it may read the patient's body fat instead of the pleura. The usual fix is to segment the organ and throw everything else away. That fix has a cost, because tissue outside the organ sometimes carries real diagnostic signal, such as the shape of the rib cage in emphysema. This proposal keeps two separate channels of evidence. The first is a lung channel that sees only the segmented organ and is trained normally. The second is a context channel that may read the rest of the image, but it can only add a small correction to the lung channel's prediction, and that correction is penalized unless it helps equally across hospitals. The idea is to use the organ mask to decide where to apply a robustness constraint, not to decide what the model may see.

The opportunity follows from a tension in the existing results. SDFN processes the full image and a lung crop with two networks and concatenates their outputs. On NIH ChestX-ray14 this raises mean AUC to 0.815, against 0.807 for crops alone and 0.804 for whole images, and the gain is statistically significant. So context helps on average. Yet its full-image stream is exactly the stream that Unlearning Spurious Correlations in Chest X-ray Classification and The Role of Pleura and Adipose in Lung Ultrasound AI show carries demographic shortcuts. Nobody has asked which part of SDFN's gain is real signal and which part is shortcut, or built a model that keeps the first and drops the second.

Core Claim

The claim is that, for chest radiograph classification, the right way to combine organ-level and whole-image features is to treat them asymmetrically. The organ-restricted features should form the main predictor, trained by ordinary loss minimization. The outside-organ features should enter only as a bounded additive correction to the output scores (logits) whose risk is required to be invariant across data sources.

We write the prediction as

$$ z(x) = f\big(x \odot M\big) + g\big(f_{\text{feat}}(x \odot M),\, x \odot (1-M)\big), $$

where $x$ is the image and $M$ is the lung-and-heart mask. The function $f$ is the lung channel, which outputs logits using only masked-in pixels. $f_{\text{feat}}$ denotes its internal features. $g$ is the context correction, which reads the complement region $1-M$ through cross-attention: lung features act as queries, and outside-organ features act as keys and values.

The training objective is

$$ \mathcal{L} = \sum_{e} R_e(z) + \lambda \,\mathrm{Var}_e\big[R_e(z) - R_e(f)\big] + \mu \,\lVert g \rVert^2 . $$

Here $e$ indexes data sources, such as hospital databases, and $R_e$ is the classification loss on source $e$. The variance term penalizes context corrections that lower loss a lot in some sources and not in others. That uneven pattern is the signature of a source-specific shortcut. The last term keeps $g$ small unless it earns its place.

The prediction is concrete. This model should match SDFN on in-distribution AUC. It should beat SDFN under leave-one-source-out testing and under shortcuts deliberately planted outside the organ. It should also beat pure masking wherever genuine context exists.

This design differs from the closest prior work in three ways. SDFN gives both streams equal footing and fuses them only at the end. Chest X-ray Image Classification: A Causal Perspective separates "causal" from "confounding" features entirely in latent space. It pushes confounder predictions toward a uniform distribution, an assumption its authors concede is a simplification. Our method uses no uniform-confounder assumption. Instead, it assigns suspicion to a spatially defined region and tests that region's contribution against observed variation across sources. The third contrast is with mask-weighted pooling, as in the CT COVID-19 triage work and the breast ultrasound latent-phenotype work. Those methods discard context by construction, whereas ours can recover it.

Research Program

The build uses chest radiographs, because this is the only modality in the file that offers large multi-source data with precomputed anatomical masks.

CheXmask supplies lung and heart masks for ChestX-ray8, CheXpert, MIMIC-CXR, PadChest and VinDr-CXR. It reports lung Dice of 0.949 to 0.982. It also provides a per-image quality score, the reverse classification accuracy (RCA) estimate. These five databases serve as the environments $e$.

The lung channel is a DenseNet-121 applied to a high-resolution crop with the mask applied, matching SDFN's local stream. The context channel is a second DenseNet-121 on the full image with the organ zeroed out. A two-head cross-attention layer lets pooled lung tokens read context tokens. A small linear head then produces the correction $g$.

Segmentation failure is the main known weakness of two-stage pipelines. CheXmask notes that mask quality drops for bedside anteroposterior views and severe consolidation. To handle this, we dilate $M$ in proportion to low RCA quality, so that lesions a bad mask clips are pushed into the lung channel rather than into the scrutinized context channel. This is deliberately simple. We will report results stratified by RCA score to see whether it matters.

The analysis side matters as much as the model. For every baseline and for our model, we decompose performance into a lung-only part and a context-added part. We report how much of each model's AUC survives when context is replaced with another patient's context. Separately, we report how much is lost when context is removed. This gives, for the first time, a per-pathology map of where outside-organ evidence is real and where it is a shortcut.

Baselines

The naive reference points are two single DenseNet-121 classifiers: one on whole images and one on masked lung crops. We train them under the same resolution, augmentation and tuning budget as everything else. On the NIH official split, SDFN reports mean AUC 0.804 for the whole-image model and 0.807 for the crop model. We will reproduce both before comparing.

The strongest existing competitor is SDFN, which is dual-stream DenseNet-121 with late concatenation. It is the only published method in the file that already combines organ segmentation with whole-image context on the target benchmark. Its reported mean AUC is 0.815 over 14 pathologies on the NIH benchmark split. We will reimplement it using the same CheXmask masks, the same backbones and the same number of hyperparameter trials as our model.

On the NIH split, beating SDFN means staying within 0.005 mean AUC of it. On leave-one-source-out and planted-shortcut tests, beating it means a clear improvement, with confidence intervals from patient-level bootstrap.

We also run mask-weighted global average pooling in the style of the CT triage paper. That paper reports specificity of 87.8% against 85.8% for standard pooling on CT. We include it as the "discard context softly" competitor, in a variant with a small nonzero weight left on the background.

For causal debiasing we run the causal-perspective model, which reports AUC 0.94 for cardiomegaly and 0.91 for effusion. Its mean over 14 classes is not reported in the file, so we will measure it ourselves.

For explanation-based unlearning on the 5,200-image COVID set, we compare against eXBL from Unlearning Spurious Correlations. It reports accuracy falling from 0.95 to 0.90 while activation precision inside the lungs rises from 0.32 to 0.35.

Two ablations isolate the key ingredient. The first applies the same cross-source variance penalty to the whole SDFN model rather than only to the context correction. This tests whether spatial targeting matters. The second removes the penalty but keeps the asymmetric architecture. This tests whether the bounded-correction structure alone does the work.

Why not just…?

Why not just mask to the organ and discard everything else? Pure masking wins whenever context is purely a shortcut, and that may often be true. However, SDFN's significant 0.807-to-0.815 gain on NIH says pure masking leaves signal on the table on average. The per-pathology context-removal analysis will show exactly where that signal lives. If our model does not beat the masked-crop baseline on pathologies like emphysema or cardiomegaly, where outside-lung geometry plausibly matters, the proposal fails on its own terms.

Why not just let a vision transformer attend wherever it wants? The file's evidence is that unconstrained attention finds shortcuts first. Full-frame lung ultrasound models attended to fat and reached AUC 0.6553, against 0.7742 with pleural masking (Pleura and Adipose). Pneumonia classifiers used shoulder growth plates (Unlearning). We do not claim transformers cannot be fixed, only that attention alone has no signal telling it which regions generalize. Our planted-shortcut test, run with a ViT baseline, will show whether that holds here.

Why not just swap in other patients' backgrounds as augmentation, or apply an invariance penalty to the whole model? This is the most serious threat. Background swapping would destroy shortcuts cheaply, but it would also destroy genuine context. The context-swap diagnostic measures exactly that trade-off, and swap augmentation of SDFN is run as a baseline. A whole-model invariance penalty is the first ablation above. We found no reported result on Lacuna comparing cross-source invariance penalties with ordinary training on chest X-rays. It is therefore possible that the penalty adds nothing beyond the architecture, and the second ablation is designed to reveal that. If whole-model invariance or swap augmentation matches our model on all three test regimes, we will report the spatially targeted penalty as unnecessary.

Proposed Experiments

The first experiment is the NIH ChestX-ray14 official split with 14-label mean AUC. It checks that robustness is not bought with an in-distribution loss, as eXBL's drop from 0.95 to 0.90 accuracy illustrates can happen.

The second is leave-one-source-out training across the five CheXmask databases. Evaluation uses the harmonized label subset shared across sources, such as cardiomegaly, effusion, pneumothorax, consolidation, edema and atelectasis. This is the realistic test of whether outside-organ reliance transfers.

The third is a controlled planted shortcut. A small marker is placed in the complement region, correlated with one label at 90% in training and reversed at test. Every model's AUC drop under reversal is measured. This is the cleanest test, because ground truth about what counts as a shortcut is known by construction.

The fourth is the 5,200-image COVID set used by eXBL. Here we report accuracy and lung activation precision against the published 0.90 and 0.35. We also report an age- or source-balanced test split if source metadata allow one to be constructed.

Across all four experiments, we additionally report the context-removal and context-swap gaps per pathology, results stratified by CheXmask RCA quality, and the average magnitude of $g$. This last quantity shows whether the model actually uses context where it claims to.

The decisive check is a combination of three results. First, the model must stay within noise of SDFN on NIH. Second, it must beat SDFN on leave-one-source-out and planted-shortcut tests. Third, it must beat the masked-crop model on at least the pathologies where context removal hurts. All three together would establish that context can be kept without inheriting shortcuts. Failure on the third result alone would mean the honest recommendation is simply to mask.