VariaFlow: Uncertainty-Aware Flow Matching for Unsupervised Anomaly Detection
Authors: Arnela Hadzic, Martin Urschler, Cosmin I. Bercea
Organizations: Institute for Medical Informatics, Statistics and Documentation, Medical University of Graz, Graz, Austria · Institute of Visual Computing, Graz University of Technology, Graz, Austria · Technical University of Munich, School of Medicine and Health, TUM University Hospital, Klinikum rechts der Isar, Department of Diagnostic and Interventional Radiology, Munich, Germany
Reconstruction-based anomaly detection no longer fails at reconstruction. Generative models produce high-quality pseudo-healthy reconstructions, and the remaining difficulty is the step of scoring residuals. The residual between a scan and its reconstruction has two indistinguishable sources, genuine pathology and the anatomical variation that separates one healthy brain from another. Scoring against a single reconstruction treats both as anomalous, inflating false positives where healthy anatomy varies most while small or subtle lesions are lost in the surrounding reconstruction error. We identify the missing quantity as the predictive variance, how much a healthy reconstruction can vary at each location. We introduce VariaFlow, which estimates this variance from an ensemble of mask-guided restorations under an unconditional flow matching prior, each started from a different noise initialization, and which normalizes the residual by the resulting standard deviation. Few-step flow matching keeps the ensemble computationally affordable, and restoring at two spatial scales captures lesions of different size. Across three brain MRI datasets spanning stroke and tumor, VariaFlow is trained once on healthy anatomy and generalizes across all three, attaining the highest AUROC (0.94, 0.80, 0.78) on each and the highest AUPRC on both cross-domain datasets, exceeding the strongest baseline by 37% and 50%. Under domain shift, the same baseline drops by up to 52% in AUPRC, whereas VariaFlow stays more stable and achieves the best small-lesion Dice on all three datasets.
Figures & tables
Figure 1: Given an input image, VariaFlow generates an ensemble of pseudo-healthy reconstructions ( x^(1),x^(2),…,x^(N) ). In anomalous regions, the model consistently generates healthy tissue, yielding a high residual ( R ) and low predictive variance ( σ2 ). Conversely, in variable healthy regions (e.g., ventricle boundaries), anatomical variability causes reconstructions to diverge, creating high predictive variance. Penalizing the residual with the variance suppresses false positives, isolating the pathology in the anomaly score map ( S ).
Dataset
Small
Medium
Large
ATLAS
189
152
59
UCSF-PDGM
30
126
257
BraTS
26
78
217
Total
245
356
533
Table 1: Number of images per lesion size category and dataset.
Table 2: Quantitative results on the ATLAS, UCSF-PDGM, and BraTS datasets. VariaFlow is compared to several state-of-the-art diffusion- and flow-based baselines. Bold and underline indicate the best and the second-best score per metric, respectively.
Figure 2: Qualitative anomaly detection results on ATLAS, UCSF-PDGM, and BraTS. Rows 1-2 show the input images and ground truth masks. Rows 3-6 visualize the anomaly maps generated by the baseline methods, and Row 7 shows the maps generated by VariaFlow , demonstrating both superior detection and false positive suppression.
Figure 3: Comparison of window sizes ( sl=32,sg=64 ) and fusion strategies, with geometric mean consistently yielding the highest AUPRC.
Scoring
AUROC ↑
AUPRC ↑
⌈ Dice ⌉ (%) ↑
Mean residual
0.8463
0.3935
43.11
Median residual
0.8571
0.4008
43.91
Proposed (S)
0.9417
0.5262
54.86
Table 3: Comparison of different scoring formulations. Median residual alone as proposed in Eq. 3 . Mean residual is a variant that uses the mean reconstruction instead in Eq. 1 . Based on median residual, our proposed (S) additionally penalizes variance.
Figure 4: Impact of the ensemble size N on detection performance. Metrics stabilize at N=5 .
Figure 5: Examples of diverse anatomical and structural deviations. Left: The model detects an enlarged ventricle, dominating the lesion attached to it. Right: The model misses a lesion resembling cortical folding while detecting a prominent imaging artifact.
Method
Backbone Architecture
Steps
Time (s)
VRAM (GB)
Params (M)
THOR [ 11 ]
DDPM U-Net
350
3.58
0.52
∼19
REFLECT [ 8 ]
LDM U-Net + VAE
5
0.12
1.67
∼246
VariaFlow (single patch)
Restora-Flow U-Net [ 19 ]
8
0.32
0.40
∼62
VariaFlow (global scale, N=1 )
0.64
0.82
VariaFlow (local scale, N=1 )
2.92
3.34
VariaFlow (dual-scale, N=1 )
3.56
3.34
Table 4: Computational and architectural comparison between methods.
We propose Flow Mismatching, an unsupervised anomaly detection method that deliberately avoids reconstruction-based paradigms. Instead, we treat flow matching as geometric dynamics and leverage a key insight: anomalies occur at places where the learned normal flow disagrees with the geometric path toward a test image. Given a flow matching model trained only on normal images, we probe its learned velocity field along affine paths from Gaussian noise to a target image. Along each path, we compare the model-predicted velocity, which follows normal generative dynamics, with the geometric velocity toward the target, which includes any anomalous content. Anomalies induce strong local disagreement between these velocities. Aggregating the mismatch over different time steps and multiple paths yields pixel-wise heatmaps and image-level scores without test-time optimization, feature memories, or additional calibration. Our analysis shows that the population mismatch decomposes into an irreducible denoising term and a Fisher-divergence term between the test-path and normal-path score functions, which identifies the score-gap component that drives anomaly separation and explains the effectiveness of robust path aggregation. Extensive experiments on MVTec-AD and VisA demonstrate superior performance compared with SOTA reconstruction-based and recent flow matching-based approaches.
Shengzhe Chen, Mehrdad Moradi, Kamran Paynabar +1
1Arizona State University · 2Georgia Institute of Technology
Unsupervised medical anomaly detection learns normal anatomical patterns from healthy training images and identifies deviations at test time. Reconstruction-based and diffusion-based methods commonly use the difference between an input image and its reconstruction as anomaly evidence. However, this residual can be ambiguous. Expressive models may preserve pathological structures, while benign anatomical variation, imaging noise, and acquisition differences may also produce large reconstruction errors. We propose discriminative mask-guided diffusion (DMD), a medical anomaly detection framework that complements residual-based localization with reconstruction-shift discrimination. DMD first learns a compact quantized latent representation of normal images. Localized masks then perturb selected latent regions, and a latent diffusion model reconstructs the perturbed representations. The resulting reconstructions are paired with their original normal images to define a self-supervised classification task. At inference, the classifier provides a learned image-level anomaly score, while the residual between the input and its diffusion-based reconstruction yields a pixel-level anomaly map. Experiments on five datasets spanning brain MRI, breast ultrasound, and chest radiography show that DMD achieves the best overall performance among the state-of-the-art baseline methods.
Yibo Wan, Jinyu Cai, Yunhe Zhang +2
School of Computing, National University of Singapore, Singapore · Institute of Data Science, National University of Singapore, Singapore · Department of Computer and Information Science, SKL-IOTSC, University of Macau, China +1
Unsupervised anomaly detection (UAD) aims to localize abnormal regions in medical scans without pixel-level annotations. A typical strategy seeks to reconstruct a pseudo-healthy image that preserves subject-specific anatomy. Recently, diffusion models have been proposed to perform UAD. However, these methods rely on heuristic noise schedules or synthetic corruptions to balance subject-specificity and anomaly removal. In this work, we propose an alternative formulation of UAD as a Bayesian inverse problem under a diffusion prior. First, we introduce a latent spatial anomaly mask that models pixel-wise consistency between a test image and its latent corresponding pseudo-healthy image. Then, we propose an approximation of the unknown generation process that links healthy anatomy, anomalies, and the observed image, enabling a well-defined likelihood within the Bayesian framework. Building on recent advances in diffusion-based inverse problem methods, we jointly infer the pseudo-healthy image and the anomaly mask via annealed posterior sampling. We evaluate our approach on FDG PET (ADNI) and FLAIR MRI (BraTS 2021), demonstrating improved anomaly localization performance compared to other diffusion-based approaches and validating the contribution of our introduced model. Our code is available at https://github.com/HuguesRoy/UAD_DAPS.
Hugues Roy, Reuben Dorent, Ninon Burgos
Sorbonne Université, Institut du Cerveau - Paris Brain Institute - ICM, CNRS, Inria, Inserm, AP-HP, Hôpital de la Pitié Salpêtrière, F-75013, Paris, France