Topology-Aware Optimal Transport for Source-Free Test-Time Adaptation in Anomaly Segmentation

Ali Zia, Usman Ali, Abdelwahed Khamis, Muhammad Umer Ramzan, Abdul Rehman, Wei XiangNeurIPS 2026

TL;DR

Conventional anomaly segmentation relies on static score thresholds to turn continuous heatmaps into binary defect masks—a fragile approach that breaks when test data shifts even slightly from training data. TopoOT ditches fixed thresholds entirely, instead looking at the geometry of the anomaly map across multiple scales to find true structural defects that persist while noise fades away. By combining topological data analysis with optimal transport, it adapts models on the fly at 121 FPS without needing source data or labels, boosting segmentation F1 scores by up to 24.1%.

What Problem Does This Paper Address?

Imagine you have a vision model inspecting factory parts for defects. Usually, these models output a continuous "anomaly heatmap," where brighter pixels mean "more suspicious." To make an actual decision—defect or no defect—you have to pick a cutoff threshold to binarize that map.

Here is the catch: thresholds calibrated on clean validation data are notoriously brittle. If lighting changes at test time, or a new type of defect appears (a test-time distribution shift), a static cutoff either misses the defect entirely or floods the mask with false-alarm noise. Furthermore, slicing a map pixel-by-pixel completely ignores spatial structure—like whether suspicious pixels actually form a coherent crack or hole.

Test-time adaptation (TTA) tries to adjust models on the fly during inference, often without access to original training data ("source-free"). However, existing TTA methods still rely on noisy heuristics or entropy thresholds to generate pseudo-labels, which collapse under severe shifts. The authors ask: Can we replace brittle score-thresholding with principled, multi-scale structural reasoning during test-time adaptation?

Methods

TopoOT keeps the pretrained anomaly-detection backbone frozen and attaches a tiny, fast segmentation head that adapts to each unlabelled test image (or 3D point cloud) on the fly. The magic lies in how it generates clean pseudo-labels to train that head:

Figure 1: TopoOT Test-time Adaptation for Anomaly Segmentation. (Top Left) pipeline simplified view. (Bottom) detailed view. TopoOT replaces conventional dataset-calibrated thresholding by stabilising anomaly evidence via cross-PD OT matching within each filtration, then fusing sub- and super-level scores with cross-level OT. The resulting global scores yield Top-K pseudo-labels that supervise a lightweight head for final segmentation.
  1. Multi-scale Topological Filtering: Instead of picking one threshold, TopoOT sweeps across a sequence of thresholds—both from the bottom up (sublevel filtrations, tracking how connected blobs merge) and top down (superlevel filtrations, tracking how holes and loops evolve). Using Persistent Homology (a tool from Topological Data Analysis), it records when each structural feature is "born" and when it "dies" across thresholds, summarizing them in Persistence Diagrams (PDs). Long-lived features represent real structural anomalies; short-lived blips are noise.
  2. Optimal Transport (OT) Chaining (Novel): Raw persistence diagrams are still noisy. Rather than blurring them together via averaging, the authors introduce OT Chaining. Using entropy-regularized Optimal Transport (Sinkhorn distances), they sequentially match topological features across adjacent thresholds (cross-PD) and between the bottom-up and top-down views (cross-level). Features that survive this transport chain with low cost earn high "geodesic stability scores."
  3. Back-projection & Online Training: The top-$K$ most stable topological features are projected back onto the image grid as binary pseudo-labels. These supervise the lightweight MLP head using two losses: an OT-consistency loss (forcing predictions to match the stable topological structures) and a contrastive loss (pushing anomalous and normal pixel embeddings apart to sharpen boundaries).

Datasets

No new datasets are introduced; the authors evaluate across five standard industrial anomaly benchmarks spanning 2D and 3D modalities:

  • 2D RGB Images: MVTec AD, VisA, and Real-IAD (paired with PatchCore, PaDiM, Dinomaly, and MambaAD backbones).
  • 3D Multimodal & Point Clouds: MVTec 3D-AD (RGB + point clouds) and Anomaly-ShapeNet (pure point clouds), paired with CMM, M3DM, and PO3AD backbones.

Key Insights and Ideas

  • Anomalies are topological disruptions, not just bright pixels: Treating binarization as a structural tracking problem rather than a statistical cutoff problem naturally filters out scattered, high-scoring noise islands while preserving faint but structurally coherent defects.
  • Sublevel and superlevel views are better together: Ablation studies show that aligning features within a single filtration gives only modest gains. The major performance jump comes from cross-level OT alignment—requiring an anomaly candidate to make sense both as an emerging component and as an evolving boundary/void.
  • Plug-and-play modularity: Because TopoOT only needs frozen features and an anomaly map, you can mix and match—pairing the feature extractor of one model (e.g., PatchCore) with the anomaly scorer of another (e.g., MambaAD) at test time and still beat standard baselines.

Key Results

Because standard AUROC metrics can look deceptively high even when binary masks are terrible (due to massive background-pixel imbalance), the evaluation focuses on pixel-level Precision, Recall, F1, and IoU.

  • 2D Benchmarks: TopoOT outperforms the prior TTA state-of-the-art (TTT4AS) by up to +24.1% F1 on MVTec AD (with PaDiM), +19.7% F1 on VisA, and +21.3% F1 on Real-IAD (with Dinomaly). Over standard statistical thresholding (THR), gains reach +38.6% F1.
  • 3D Benchmarks: Gains translate cleanly to 3D, beating TTT4AS by +10.2% F1 on MVTec 3D-AD (with CMM) and +1.9% F1 on Anomaly-ShapeNet.
  • Efficiency: For 2D inference, the TTA module runs at 121 FPS while consuming only 349 MB of VRAM on an RTX 5090.
Figure 2: Qualitative comparison of AD&S methods for different objects using the MVTec 3D-AD dataset.

Limitations and Future Work

  • Garbage in, garbage out: Because the backbone is frozen, TopoOT's ceiling is strictly bounded by the quality of the initial anomaly map. If a backbone completely misses a defect on a tricky texture, topology cannot resurrect it.
  • 3D Speed Bottlenecks: While 2D runs at real-time speeds (121 FPS), 3D inference has noticeably lower FPS due to heavy point-cloud operations.
  • Future Directions: The authors suggest accelerating persistence computations, tighter integration with representation learning (unfreezing or co-adapting features), extending to spatiotemporal (video) anomalies, and designing stronger unsupervised losses for complex textures.

Summary updated

Abstract

Deep topological data analysis (TDA) offers a principled framework for capturing structural invariants such as connectivity and cycles that persist across scales, making it a natural fit for anomaly segmentation (AS). Unlike threshold-based binarisation, which produces brittle masks under test-time distribution shift (TTDS), TDA allows anomalies to be characterised as disruptions to global structure rather than local fluctuations. We introduce TopoOT, a topology-aware optimal transport (OT) framework for source-free test-time adaptation in AS. Our key innovation is Optimal Transport Chaining, which sequentially aligns persistence diagrams (PDs) across thresholds and filtrations, yielding geodesic stability scores that identify features consistently preserved across scales. These stability-aware pseudo-labels supervise a lightweight head updated online using only unlabelled target samples, without access to source data or target labels, with OT-consistency and contrastive objectives, ensuring robust adaptation under TTDS. Across standard 2D and 3D anomaly detection benchmarks, TopoOT achieves state-of-the-art performance, outperforming second-best methods by up to +24.1\% mean F1 on 2D datasets and +10.2\% on 3D AS benchmarks.
BibTeX
@inproceedings{zia2026topology,
  author = {Ali Zia and Usman Ali and Abdelwahed Khamis and Muhammad Umer Ramzan and Abdul Rehman and Wei Xiang},
  title = {{Topology-Aware Optimal Transport for Source-Free Test-Time Adaptation in Anomaly Segmentation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=kG41FPloKc},
}

Loading related content...

Figure