Source-linked AI summary

CFLOW-AD: Real-Time Unsupervised Anomaly Detection with Localization via Conditional Normalizing Flows

Denis Gudovskiy, Shun Ishizaka, Kazuki Kozuka

arXiv:2107.12571v1cs.CVcs.AIcs.LG

TL;DR

Unsupervised anomaly localization must operate without labeled or anomalous training examples, while existing high-accuracy methods can be too complex for real-time processing. CFLOW-AD uses a conditional normalizing-flow architecture with a pretrained encoder and multi-scale likelihood-estimating decoders. On MVTec, it achieves state-of-the-art detection and localization results while being 10× faster and smaller than prior models under the same input setting.

  • Problem

    Unsupervised anomaly localization addresses settings where labeling is infeasible and anomaly examples are absent from training, while existing methods remain limited by real-time complexity.

  • Method

    CFLOW-AD combines a discriminatively pretrained CNN encoder with multi-scale conditional normalizing-flow decoders that estimate likelihoods of encoded features.

  • Results

    98.26% AUROC in detection and 98.62% AUROC with 94.60% AUPRO in localization are reported on MVTec, alongside state-of-the-art results on STC.

  • Takeaways & Limitations

    CFLOW-AD is 10× faster and smaller than prior models with the same input resolution and feature-extractor setup, supporting real-time unsupervised localization.

  • Takeaways & Limitations

    The feature-extraction framework imposes a multivariate Gaussian prior on feature vectors extracted from intermediate layers.

Abstract

from arXiv · show

Unsupervised anomaly detection with localization has many practical applications when labeling is infeasible and, moreover, when anomaly examples are completely missing in the train data. While recently proposed models for such data setup achieve high accuracy metrics, their complexity is a limiting factor for real-time processing. In this paper, we propose a real-time model and analytically derive its relationship to prior methods. Our CFLOW-AD model is based on a conditional normalizing flow framework adopted for anomaly detection with localization. In particular, CFLOW-AD consists of a discriminatively pretrained encoder followed by a multi-scale generative decoders where the latter explicitly estimate likelihood of the encoded features. Our approach results in a computationally and memory-efficient model: CFLOW-AD is faster and smaller by a factor of 10x than prior state-of-the-art with the same input setting. Our experiments on the MVTec dataset show that CFLOW-AD outperforms previous methods by 0.36% AUROC in detection task, by 1.12% AUROC and 2.5% AUPRO in localization task, respectively. We open-source our code with fully reproducible experiments.

1. Introduction

Unsupervised anomaly detection uses anomaly-free training data to identify deviations, but high-resolution image methods face real-time complexity limits. CFLOW-AD addresses this with conditional normalizing flows that model anomaly-free patch distributions and separate out-of-distribution patches using a threshold.

  • Supervised anomaly detection is impractical when labeled data are costly, anomalies are rare, and labeling requires domain expertise.These constraints motivate training with unlabeled anomaly-free images instead.
  • Unsupervised anomaly detection trains on anomaly-free images and classifies deviations from that distribution as anomalies.The task can therefore be reformulated as out-of-distribution detection.
  • High-resolution image OOD detection is difficult because post-processing CNN feature maps remains too complex for real-time state-of-the-art methods.CNN feature extraction itself has relatively low complexity.
  • CFLOW-AD learns anomaly-free patch density pX(x), transforms it into Gaussian density pZ(z), and separates in-distribution from out-of-distribution patches with threshold τ.The threshold is computed as the Euclidean distance from the distribution mean.
  • CFLOW-AD is based on conditional normalizing flows and is designed to be agnostic to feature-map spatial dimensions.The paper links this design to higher accuracy and lower computational and memory requirements.

2. Related work

Prior unsupervised localization methods use clustering, generative models, student-teacher frameworks, self-supervision, or Gaussian distance metrics, each with efficiency or modeling limitations. CFLOW-AD extends normalizing flows to efficient multi-scale pixel-level localization while providing theoretical links to prior Gaussian-based approaches.

  • Related methods include CNN features with clustering, generative models, student-teacher frameworks, self-supervised pretraining, and Mahalanobis-distance scoring.PaDiM estimates multivariate Gaussian parameters for pooled feature vectors and uses Mahalanobis distance for anomaly scores.
  • Test-time clustering is slow for high-dimensional data, motivating parallel convolutional methods for real-time systems.This limitation is described for clustering-based approaches such as SPADE.
  • Fully generative models estimate pixel-level densities or reconstruction-error proxies but cannot estimate exact data likelihoods and do not outperform traditional methods in the cited MVTec survey.DFR adds pretrained features and multi-scale pooling but also cannot estimate exact likelihoods.
  • CFLOW-AD extends normalizing flows from image-level detection to pixel-level localization using conditional flows for low-complexity multi-scale feature-map processing.The approach contrasts with RealNVP using global average pooling and is intended for computationally and memory-efficient localization.
  • Theoretical analysis argues that the multivariate Gaussian prior used by previous models is justified and that the broader normalizing-flow objective converges to similar results with less compute.This connects the flow framework to prior distance-based models with multivariate Gaussian priors.
  • CFLOW-AD reports improved detection and localization over previous state-of-the-art methods.The paper attributes this result to the proposed model's properties.

3. Theoretical background

The paper relates Mahalanobis-based anomaly scoring to normalizing flows, showing how flow likelihood optimization can recover similar behavior with fewer computational constraints. It then motivates conditional flows as a more general and compact alternative for spatially localized anomaly detection.

  • 3.1. Feature extraction with Gaussian prior: CNN L2 weight decay induces a multivariate Gaussian prior over intermediate feature vectors, motivating Mahalanobis-based anomaly scoring.The Gaussian assumption is inherited from the regularization of discriminatively trained CNNs.
  • 3.2. A case for Mahalanobis distance: Mahalanobis distance separates feature vectors by comparing them with estimated anomaly-free mean and covariance statistics from Dtrain.The true distribution is unknown, so its parameters are estimated empirically.
  • 3.3. Relationship with the flow framework: Normalizing flows estimate exact likelihoods by mapping feature data through an invertible transformation to a tractable base distribution.The change-of-variable formula combines base-distribution likelihood with the Jacobian determinant.
  • 3.3. Relationship with the flow framework: Under the multivariate Gaussian target assumption, flow training converges when the Jacobian term compensates the difference between Mahalanobis and squared Euclidean distances.This analytically explains why a general flow objective can reproduce the behavior of prior Gaussian methods.
  • 3.3. Relationship with the flow framework: Unlike Mahalanobis distance, normalizing flows can model arbitrary feature distributions and support compact fully convolutional processing.The paper extends this framework with conditional inputs for multi-scale localization.

4. The proposed CFLOW-AD model

CFLOW-AD combines a discriminatively pretrained multi-scale CNN encoder with conditional flow decoders that model spatially conditioned feature likelihoods. The resulting pipeline produces anomaly maps from normalized, upsampled likelihoods while targeting lower computational and memory requirements than prior post-processing methods.

  • 4.1. CFLOW encoder for feature extraction: The encoder maps image patches to semantic feature vectors using an ImageNet-pretrained, translation-equivariant CNN with multi-scale pyramid pooling.Pooling supplies small and large receptive fields to capture local and global patch information.
  • 4.2. CFLOW decoders for likelihood estimation: CFLOW-AD uses independent conditional normalizing-flow decoders at each feature-pyramid scale to estimate feature likelihoods.The decoders receive pooled feature vectors together with conditional spatial information.
  • 4.2. CFLOW decoders for likelihood estimation: Positional encoding supplies each conditional vector with sine and cosine harmonics unique to its spatial location.These vectors are concatenated with intermediate decoder representations inside coupling layers.
  • 4.2. CFLOW decoders for likelihood estimation: The conditional decoder remains translation-equivariant through shared kernels sliding over intermediate feature maps, while the conditional extension usually adds little model size.The experiments use a fixed conditional dimension Ck = 128.
  • 4.2. CFLOW decoders for likelihood estimation: The complexity comparison evaluates CFLOW-AD against SPADE and PaDiM using the same encoder while comparing post-processing, speed, and memory requirements.SPADE stores a training gallery for nearest-neighbor search, whereas PaDiM stores large covariance-related matrices.
  • 4.2. CFLOW decoders for likelihood estimation: At inference, CFLOW-AD converts scale-specific log-likelihoods into normalized probabilities, upsamples them, and aggregates them into an anomaly score map.The probabilities are resized to the input image resolution before aggregation.

5. Experiments

Experiments evaluate CFLOW-AD on MVTec and STC using detection and localization metrics, ablations, comparisons with prior methods, and complexity measurements. The results show strong accuracy alongside substantially smaller models and faster inference.

  • Experimental setup: Experiments use MVTec and STC for image-level anomaly detection and pixel-level localization, reporting AUROC and AUPRO where available.MVTec contains anomaly-free training images and defective or defect-free test images; STC uses surveillance-video frames.
  • Ablation study: A 3-scale feature pyramid improves AUROC by 1.4% over 2-scale processing, while increasing coupling layers from 4 to 8 adds 0.15% on average.The additional largest-scale feature map provides more precise spatial semantic information, and more coupling layers improve distribution modeling.
  • Ablation study: Conditional flows outperform unconditional flows by 0.5% on average, and WideResNet-50 outperforms ResNet-18 by 0.81% in the ablation study.MobileNetV3L is identified as a potential choice for fast inference and high AUROC.
  • Ablation study: Input resolution is class-dependent: macro-object classes benefit from 256×256, most classes from 512×512, and transistor from 128×128 images.The reported results therefore use the highest-performing resolution for each MVTec class, while STC uses fixed 256×256 inputs.
  • Quantitative comparison: CFLOW-AD exceeds prior MVTec state of the art by 0.36% AUROC in detection, 1.12% AUROC in localization, and 2.5% AUPRO in localization.It is also on par with or significantly better than the best models in per-class comparisons using the same encoder setups.
  • Quantitative comparison: On STC, CFLOW-AD outperforms SPADE by 0.73% AUROC in detection and PaDiM by 3.28% AUROC in localization.The STC comparison uses fixed 256×256 inputs to reduce training time.
  • Complexity evaluations: CFLOW-AD is 1.7× to 50× smaller than SPADE and 2× to 7× smaller than PaDiM when encoder parameters are excluded.Its decoders depend on feature-vector depths rather than feature-map dimensions, reducing post-processing model size.
  • Complexity evaluations: With identical input resolution and feature extractor, CFLOW-AD provides 8× to 25× faster inference on a 1080 8GB GPU than the compared models.The reference models’ large memory requirements make their GPU allocation for fast inference infeasible in the cited comparison.

6. Conclusions

The paper introduces conditional normalizing flows for exact likelihood estimation in unsupervised anomaly detection and localization, while analytically relating the framework to prior distance-based models. CFLOW-AD addresses complexity limitations and achieves state-of-the-art results on MVTec and STC.

  • Conclusions: Conditional normalizing flows estimate exact data likelihoods and reveal the relationship between this framework and prior distance-based models with multivariate Gaussian priors.The analysis explains why the Gaussian assumption is justified and why the more general normalizing-flow objective can converge to similar results with less computation.
  • Conclusions: CFLOW-AD uses a fully convolutional translation-equivariant architecture to address the complexity limitations of existing unsupervised anomaly-detection models.The architecture is designed for lower-complexity processing while retaining the conditional-flow formulation.
  • Conclusions: CFLOW-AD achieves 98.26% AUROC in MVTec detection, 98.62% AUROC and 94.60% AUPRO in MVTec localization, and 72.63% and 94.48% AUROC on STC detection and localization.The paper reports these results as new state of the art and includes ablations of practical real-time design choices.

A. Relationship with the flow framework

The flow-framework loss compares a model-predicted density with a target density. Under a standard multivariate Gaussian prior, its terms are expressed through Euclidean and Mahalanobis distances, with constants removed during substitution.

  • The reverse DKL objective compares the model prediction ˆpZ(z, θ) with a target density pZ(z).
  • Under a standard MVG prior u ∼N(0, I), the first loss term is expressed using the squared Euclidean distance of u.
  • The second loss term is expressed using the squared Mahalanobis distance for the MVG density.
  • Substituting the two MVG expressions into the loss eliminates the constants log(2π)−D/2.

B. CFLOW decoders for likelihood estimation

CFLOW-AD trains conditional normalizing-flow decoders with a maximum-likelihood objective. The loss uses transformed features and Jacobians that depend on both feature inputs and condition vectors, with expectations approximated by the training dataset.

  • CFLOW-AD uses maximum likelihood training, equivalent to minimizing a forward DKL objective.
  • The conditional flow model ˆpZ(z, c, θ) predicts a density from feature vector z and condition vector c ∈R^C.
  • The target density is replaced by a constant during gradient-based optimization because the model parameters do not depend on it.
  • The resulting loss combines the base-distribution log likelihood log pU(u) with the Jacobian term log |det J|.
  • In practice, the expectation is replaced by an empirical training dataset Dtrain of size N.
  • For CFLOW, the inverse-flow variable ui and Jacobian Ji depend on both input features zi and conditional vectors ci.
Loading 2107.12571v1…