NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Latent Transformer Models for out-of-distribution detection

Mark S. Graham, Petru-Daniel Tudosiu, Paul Wright, Walter Hugo Lopez Pinaya, Petteri Teikari, Ashay Patel, Jean-Marie U.-King-Im, Yee-Haur Mah, James T. Teo, Hans Rolf Jäger, David Werring, Geraint Rees, Parashkev Nachev, Sébastien Ourselin, M. Jorge Cardoso

TL;DR

This paper introduces Latent Transformer Models (LTMs) for robust out-of-distribution (OOD) detection in 3D medical imaging. They demonstrate that traditional uncertainty-based segmentation methods fail catastrophically on OOD data, while LTMs, by learning the distribution of compressed latent representations, effectively identify and flag anomalous images, paving the way for safer clinical deployment of AI.

What Problem Does This Paper Address?

Deploying deep learning models in clinical settings requires them to be robust to a wide range of input data, including images that deviate from the training distribution (OOD data). These OOD inputs can be "near-OOD" (e.g., images with artifacts or noise) or "far-OOD" (e.g., images from different modalities or organs). Traditional deep learning models often perform unpredictably and poorly on OOD data, leading to potentially dangerous misdiagnoses. While methods exist to estimate model uncertainty, this paper highlights their critical failure when faced with far-OOD data, often producing highly confident but incorrect predictions. The core problem is the lack of reliable mechanisms to detect and flag these OOD inputs before they are processed by downstream tasks, ensuring the safety and reliability of AI in healthcare.

Methods

The paper proposes a novel approach called Latent Transformer Models (LTMs) for OOD detection. The LTM has two main components:

  1. VQ-GAN (Vector Quantized Generative Adversarial Network): This component acts as a powerful image compressor. It encodes a 3D medical image into a highly compressed, discrete latent representation. This compression is crucial because directly applying transformers to raw, high-dimensional image data is computationally infeasible due to the quadratic complexity of the attention mechanism with respect to sequence length.
  2. Transformer: A transformer model is then trained on the sequences of discrete latent representations generated by the VQ-GAN. The transformer learns the probability distribution of these "normal" latent representations. By estimating the likelihood of a new image's latent representation, the LTM can determine if it's an in-distribution or OOD sample.

The authors also evaluated existing uncertainty-aware segmentation networks (baseline softmax, deep ensemble, and dropout-based variational inference) for comparison.

Datasets

  • CROMIS CT Dataset: A dataset of 687 head CT scans used for training all models. This dataset contains images with hemorrhages and was acquired across multiple sites. Ground-truth segmentation masks were available for a subset.
  • KCH CT Dataset: A validation dataset of 47 head CT scans with ground-truth masks. This dataset was used for in-distribution testing and to generate near-OOD data.
  • Corrupted KCH CT Dataset: Created by applying 15 different distortions and corruptions (e.g., Gaussian noise, inversion, skull stripping, intensity scaling, chunk removal) to the KCH CT dataset, resulting in 705 images. This serves as the near-OOD benchmark.
  • Medical Decathlon Dataset: Used to evaluate far-OOD performance. This dataset comprises 3D medical images from various organs and modalities, none of which are head CT.
  • FashionMNIST and MNIST: Used for 2D computer vision experiments to investigate the impact of the VQ-VAE encoding on OOD detection compared to raw pixel data.

Key Insights and Ideas

  • Catastrophic Failure of Uncertainty Methods: Traditional uncertainty estimation methods in segmentation networks fail dramatically on far-OOD data, producing highly confident but incorrect predictions. This highlights a critical gap in current clinical AI deployment.
  • Latent Space is Key: Compressing images into a discrete latent space using VQ-GANs is essential. This abstraction allows transformers to learn meaningful distributions and effectively detect OOD data, unlike direct pixel-level analysis.
  • Transformers Excel in Latent Space: Transformers, when applied to the compressed latent representations, are highly effective at learning the distribution of normal data and identifying deviations.
  • LTMs as a Robust Filter: LTMs can reliably flag both near- and far-OOD data, providing a crucial pre-processing step for clinical pipelines.
  • Spatial OOD Localization: The LTM can generate spatial maps indicating which regions of an image are considered OOD, offering valuable insights into why an image was flagged.
  • Synergy of OOD Filters and Uncertainty: The paper suggests a powerful combination: LTMs for filtering out severely OOD data, and uncertainty methods for handling slightly OOD data where they perform better.

Key Results

  • Perfect Far-OOD Detection: The LTM achieved a perfect AUC of 1.0 for distinguishing between normal head CT data and all far-OOD (non-head CT) classes.
  • Effective Near-OOD Detection: The LTM successfully distinguished most near-OOD corrupted head CT scans, achieving AUC=1.0 for corrupted images with adapted backgrounds, skull-stripping, and intensity scaling. It showed slightly lower AUC for subtle noise and L-R flipped images, which are also handled well by segmentation uncertainty methods.
  • Segmentation Performance Correlation: A strong relationship was found between an image's log-likelihood score from the LTM and the segmentation network's performance (measured by false positives). This indicates that filtering based on LTM likelihood can prevent poor segmentation results. For example, images with log-likelihood below -7000 were likely to have high false positives.
  • VQ-GAN Components Matter: Ablation studies showed that the 4-layer VQ-GAN was superior to a 3-layer version, and that both the adversarial component and perceptual loss in the VQ-GAN contributed to improved OOD detection performance.
  • Real-World OOD Detection: The LTM successfully flagged low-quality scans from the CROMIS dataset exhibiting artifacts like misregistration, FoV issues, and motion, even though it was trained on this dataset. This demonstrates robustness to some level of anomalous data in the training set.

Limitations and Future Work

  • Subtle Corruptions: The LTM showed slightly lower AUC for very subtle corruptions like low levels of noise and L-R flipping. The authors suggest that these are classes where segmentation uncertainty methods also perform well, implying a potential for a combined approach.
  • Data Availability: The datasets used in this study are noted as confidential, which may limit direct replication.
  • Future Work: The authors suggest that their LTM approach can be integrated into clinical pipelines as a robust filter. The ability to provide spatial OOD maps could also be used to discount results from anomalous regions within an image, allowing downstream networks to still process artifact-free parts. Further exploration of the synergy between LTMs and uncertainty-aware segmentation models is also a promising direction.

Summary updated

BibTeX
@article{graham2023latent,
  author = {Mark S. Graham and Petru-Daniel Tudosiu and Paul Wright and Walter Hugo Lopez Pinaya and Petteri Teikari and Ashay Patel and Jean-Marie U.-King-Im and Yee-Haur Mah and James T. Teo and Hans Rolf Jäger and David Werring and Geraint Rees and Parashkev Nachev and Sébastien Ourselin and M. Jorge Cardoso},
  title = {{Latent Transformer Models for out-of-distribution detection}},
  journal = {Medical Image Analysis},
  year = {2023},
  doi = {10.1016/j.media.2023.102967},
}
Figure