An autoencoder compresses an image into a short code and then rebuilds it. A trained autoencoder has a useful habit: if you decode a code and encode the result again, codes that sit near the data it was trained on come back almost unchanged, while codes that sit away from that data get pulled toward it. This proposal turns that habit into an anomaly detector. Most reconstruction-based detectors compare the input image to its rebuilt version and flag pixels that differ. We instead encode a query, run the decode-then-encode loop on its code, and measure how that loop behaves locally. We ask whether it returns the code to itself, and whether its local linearization acts like a clean projection onto the normal data. Each code coordinate that fails this test is reported as the factor of variation responsible for the anomaly.
This matters for two reasons. First, pixel residuals are known to miss logical anomalies, where every part looks pristine but the count, placement, or combination is wrong. That failure lives in global factors, not in local texture. Second, practitioners want to know what is wrong, not only where. A detector that names the latent factor that refused to settle back onto the normal data, and then shows that factor's spatial footprint, gives both answers. Leeb et al. proposed this direction in Exploring the Latent Space of Autoencoders with Interventional Assays but never built or benchmarked it.
Core Claim
Let $f$ be an encoder, $g$ a decoder, $h(z) = f(g(z))$ the closed-loop "latent response" map, and $z_0 = f(x)$ the code of a query image $x$. Leeb et al. showed that $h$ is contractive: it pulls off-manifold codes back toward the learned data. Near a normal code, $h$ should therefore act like a projection, and its Jacobian $J = \partial h / \partial z$ evaluated at $z_0$ should be close to idempotent ($J^2 \approx J$). Our score has two parts:
$$s(x) = \lVert h(z_0) - z_0 \rVert^2 + \lambda\, \mathbb{E}_{v \sim \mathcal{N}(0,I)} \lVert J(Jv) - Jv \rVert^2 ,$$
The first term is the fixed-point defect: the loop moves the code. The second term is an idempotence defect, estimated with a few random Jacobian-vector products rather than a dense grid over the latent space. This is the scalability problem Leeb et al. flag. The weight $\lambda$ is set on normal validation data only.
A per-coordinate version is $d_k(x) = |[h(z_0) - z_0]_k| + \lambda\,|[J^2 - J]_{kk}|$. Each $d_k$ is normalized by its spread on normal data, and the result is a factor-level explanation.
The claim has two parts. Detection: the idempotence term catches logical anomalies that pixel and feature residuals miss. Explanation: on data with known factors, the top-ranked $d_k$ identifies the factor that was violated.
Research Program
The backbone must avoid the blur that plain-pixel VAEs suffer from, which PCA-AE documents on CelebA. We therefore build the autoencoder over frozen pretrained features rather than pixels. This is the same design choice that lets DecAD reach strong localization. The code has two parts: a small set of global coordinates and a coarse spatial grid. The global coordinates are organized with an ordering and decorrelation penalty, taking the covariance-penalty method from PCA-AE and the total-correlation objective from Auto-Encoding Total Correlation Explanation. These papers supply the method for making coordinates nameable. They also constrain us, since the CorEx–ELBO duality assumes a factorized decoder, which we keep.
To localize anomalies, we backpropagate each flagged coordinate's defect $d_k$ to the feature grid. This reuses the gradient-attention construction of Towards Visually Explaining Variational Autoencoders, which maps individual latent units to image regions. That paper scored anomalies with attention over a vanilla VAE and gave no account of which factor failed. Here attention serves only to draw the footprint of a coordinate that the loop has already identified.
There is a known risk that, with long training, an autoencoder learns to reconstruct outliers and the reconstruction gap closes, as shown in Latent feature reconstruction for unsupervised anomaly detection. We will check whether the idempotence term erodes in the same way by tracking it across training checkpoints.
Three lines of prior work sit closest. OIAD perturbs disentangled codes, decodes them, and scores SSIM stability. It never re-encodes, so it measures how fragile decoding is rather than how the loop contracts. It also reports only image-level scores on low-resolution datasets. DecAD splits invertible-network channels into normal and abnormal sets and discards the abnormal ones. It detects strongly but cannot say what the discarded channels encoded. RootCLAM names root-cause variables, but it requires a known causal graph over tabular features. Our method needs no graph and works on images. In exchange, its attribution is to learned coordinates, and those coordinates are only as nameable as the disentanglement allows.
Baselines
The do-nothing reference is the same feature autoencoder scored by plain feature-reconstruction residual. It isolates whether looking at the latent loop helps at all.
The key ablation is the fixed-point term alone, $\lVert h(z_0) - z_0 \rVert$. This is the obvious "encoder and decoder disagree" score that Leeb et al. suggest. If it matches the full score, the Jacobian term is unnecessary and the detection contribution reduces to a one-line trick. A second ablation removes the ordering and decorrelation penalty, to test whether factor attribution depends on disentanglement or comes for free from any loop.
The strongest structural-defect competitor is DecAD. On MVTec AD it reports image-level AUROC 99.0, pixel-level AUROC 97.8, and AUPRO 92.5 (DecAD). The strongest reconstruction-plus-discriminator baseline is DRÆM, which reports image AUROC 98.0 and pixel AP 68.4 on MVTec AD. For logical anomalies the reference is GLCF. The file says only that GLCF beats DRÆM by 24.9% in sPRO on MVTec LOCO AD, and no absolute sPRO value was found on Lacuna, so we will rerun it. For feature-memory methods we use PaDim, quoted in the DRÆM paper at image AUROC 95.5 and pixel AP 55.0. OIAD's own reported figures are AUC 0.983 on MNIST and 0.832 on CIFAR-10.
All baselines will run through the ADer toolbox where it includes them. They will share the same pretrained backbone where applicable, the same image resolution, the same training split, and a matched hyperparameter-search budget on normal-only validation data.
The thresholds for success are set by benchmark. On MVTec LOCO's logical subset, beating the field means exceeding GLCF's rerun sPRO and image AUROC. On MVTec AD, we aim to stay within about one point of DecAD's image AUROC. We do not need to win there, since the proposal does not claim structural-defect gains.
Why not just…?
Why not just use the fixed-point cycle error? This is the most serious threat. The fixed-point error costs one extra forward pass and may already capture most of the detection signal. Our argument for the Jacobian term is specific. A code can be near a fixed point of $h$ while the loop around it behaves badly, expanding along some directions instead of projecting. A plausible case is a pristine-looking image with a forbidden combination of factors: it may encode to a code that the loop maps nearly back to itself. The ablation in the Baselines section settles this. If the two scores tie on LOCO's logical subset, we will report the detection claim as negative and keep only the attribution claim.
Why not just use DRÆM or a feature memory bank? These methods are strong on local defects. However, GLCF's reported 24.9% sPRO margin over DRÆM on LOCO shows that synthetic local-noise training misses logical anomalies. Memory banks score patches and produce neither a counterfactual nor a factor-level explanation. They remain the bar on MVTec AD, and we expect to roughly match rather than beat them there.
Why not just attach Grad-CAM or OIAD-style perturbation? Grad-CAM needs a supervised classifier. Liu et al. note that labeled anomalies are unavailable in this setting, and RootCLAM shows that attribution highlights correlates rather than causes. OIAD perturbs the code but never closes the loop. We run OIAD's structure-consistency score on the same backbone and compare factor-attribution accuracy directly.
Proposed Experiments
The decisive checks come first. The first is the full score versus the fixed-point-only score on the logical subset of MVTec LOCO AD, measured by image AUROC and sPRO. The second is factor attribution on 3D-Shapes and dSprites. In these datasets we hold out specific factor values or combinations from training, and those held-out images serve as anomalies whose violated factor is known. We measure top-1 attribution accuracy of $d_k$ against the violated factor, and compare against OIAD's perturbation sensitivity and against DecAD-style channel energy. The third check uses MVTec LOCO's anomaly-type labels (missing, extra, misplaced, wrong combination). We test whether the flagged coordinates cluster by type, measured with normalized mutual information.
Secondary experiments come next. We report MVTec AD and VisA metrics against DecAD and DRÆM to confirm that structural detection is not lost. We plot both score terms across training epochs to test the gap-shrinking failure described in the latent-feature-reconstruction paper. We also report wall-clock cost against the number of random probes, contrasting with the multiple stochastic denoising passes required by diffusion inpainting (LMD).
A positive result is LOCO gains attributable to the idempotence term, together with above-chance factor attribution that disappears without disentanglement. Anything weaker narrows the contribution to an explanation tool layered on a conventional detector.
References
- Exploring the Latent Space of Autoencoders with Interventional Assays
- PCA-AE: Principal Component Analysis Autoencoder for Organising the Latent Space of Generative Networks
- DecAD: Decoupling Anomalies in Latent Space for Multi-Class Unsupervised Anomaly Detection
- Auto-Encoding Total Correlation Explanation
- Towards Visually Explaining Variational Autoencoders
- Latent feature reconstruction for unsupervised anomaly detection
- OIAD: One-for-all Image Anomaly Detection with Disentanglement Learning
- On Root Cause Localization and Anomaly Mitigation through Causal Inference
- DRÆM - A discriminatively trained reconstruction embedding for surface anomaly detection
- Learning Global-Local Correspondence with Semantic Bottleneck for Logical Anomaly Detection
- Unsupervised Out-of-Distribution Detection with Diffusion Inpainting