Source-linked AI summary

FastFlow: Unsupervised Anomaly Detection and Localization via 2D Normalizing Flows

Jiawei Yu, Ye Zheng, Xiang Wang, Wei Li, Yushuang Wu, Rui Zhao, Liwei Wu

arXiv:2111.07677v2cs.CV

TL;DR

Unsupervised anomaly detection must identify and localize anomalies when labeled abnormal data are scarce, while existing methods have difficulty modeling tractable feature distributions and global-local relationships. FastFlow uses a 2D normalizing flow as a plug-in distribution estimator for varied feature extractors, transforming normal features to a tractable distribution and using likelihoods for inference. On MVTec AD, it outperforms prior methods in accuracy and inference efficiency, while reported bad cases include missed subtle anomalies, false detections, and label ambiguity.

  • Problem

    Unsupervised anomaly detection and localization is needed when abnormal samples are unavailable or difficult to collect and annotate, while existing methods inadequately model tractable distributions and global-local feature relationships.

  • Method

    FastFlow is a 2D normalizing-flow plug-in that models visual-feature distributions while preserving spatial information and supports CNN and vision-transformer extractors.

  • Results

    FastFlow outperforms previous state-of-the-art methods in accuracy and inference efficiency on MVTec AD across backbone networks.

  • Takeaways & Limitations

    FastFlow provides end-to-end anomaly detection and localization with a lightweight, feature-extractor-agnostic design.

  • Takeaways & Limitations

    On MVTec AD, FastFlow misses some small unobvious anomalies, falsely detects certain background areas, and encounters ambiguous labels.

Abstract

from arXiv · show

Unsupervised anomaly detection and localization is crucial to the practical application when collecting and labeling sufficient anomaly data is infeasible. Most existing representation-based approaches extract normal image features with a deep convolutional neural network and characterize the corresponding distribution through non-parametric distribution estimation methods. The anomaly score is calculated by measuring the distance between the feature of the test image and the estimated distribution. However, current methods can not effectively map image features to a tractable base distribution and ignore the relationship between local and global features which are important to identify anomalies. To this end, we propose FastFlow implemented with 2D normalizing flows and use it as the probability distribution estimator. Our FastFlow can be used as a plug-in module with arbitrary deep feature extractors such as ResNet and vision transformer for unsupervised anomaly detection and localization. In training phase, FastFlow learns to transform the input visual feature into a tractable distribution and obtains the likelihood to recognize anomalies in inference phase. Extensive experimental results on the MVTec AD dataset show that FastFlow surpasses previous state-of-the-art methods in terms of accuracy and inference efficiency with various backbone networks. Our approach achieves 99.4% AUC in anomaly detection with high inference efficiency.

1 Introduction

FastFlow addresses unsupervised anomaly detection and localization by modeling global and local visual-feature distributions with a 2D normalizing flow. It provides efficient end-to-end inference and plug-in compatibility with different feature extractors.

  • Unsupervised anomaly detection uses only normal images during training while identifying and localizing abnormal regions during testing.
  • FastFlow supports end-to-end whole-image inference, directly producing anomaly detection and localization results without sliding-window patch processing.
  • The method transforms visual features toward a standard normal distribution and uses location-wise probabilities as anomaly scores.
  • FastFlow extends normalizing flows to two-dimensional feature maps, preserving spatial positions while modeling global and local distributions.
  • FastFlow uses alternating large and small convolution kernels in a lightweight structure and functions as a plug-in with varied feature extractors.
  • On MVTec AD, FastFlow outperforms previous state-of-the-art methods in accuracy and inference efficiency across backbone networks.

2 Related Work

Related work includes reconstruction-based and representation-based anomaly detection, with recent methods using deep feature extractors and normalizing flows. FastFlow builds on these directions while retaining spatial feature structure.

  • Reconstruction-based methods encode and reconstruct normal data, based on the premise that unseen anomalies cannot be reconstructed.
  • Representation-based methods extract discriminative features for normal images and detect samples whose distributions differ from normal data.
  • Recent approaches commonly use ResNet, while some introduce vision transformers as feature extractors for unsupervised anomaly detection.
  • FastFlow's pipeline can use arbitrary CNN or vision-transformer feature extractors and alternates 3 × 3 and 1 × 1 flows.
  • Normalizing flows learn bijective transformations between data distributions and support both forward and reverse processing.

3 Methodology

FastFlow extracts visual features, maps their two-dimensional distribution to a tractable latent distribution, and derives anomaly scores from feature likelihoods. Its convolutional flow preserves spatial information and supports end-to-end localization.

  • The methodology combines a feature extractor with a learnable probability-density estimation model for unsupervised anomaly detection.
  • 3.2 Feature Extractor: FastFlow uses ViT features from one layer or ResNet features from the last layers of the first three blocks, followed by corresponding flow models.
  • 3.3 2D Flow Model: The 2D flow bijectively maps image features x to latent variables z and defines the feature distribution through the change-of-variables formula.
  • 3.3 2D Flow Model: Anomalous features are assigned lower likelihoods than normal features, and summed channel probabilities form an upsampled anomaly map.
  • 3.3 2D Flow Model: The flow is composed of stacked invertible transformation blocks containing affine coupling steps.
  • 3.3 2D Flow Model: Two-dimensional convolutional subnets preserve spatial relationships that flattening visual features would destroy.

4 Experiments

FastFlow is evaluated for unsupervised anomaly detection and localization across industrial and natural-image datasets, using AUROC-based detection and localization metrics. It combines strong reported accuracy with lower inference cost than comparison methods.

  • Datasets and Metrics: FastFlow is evaluated on MVTec AD, BTAD, and CIFAR-10 under unsupervised settings using normal images for training.MVTec AD and BTAD support pixel-level localization evaluation, while CIFAR-10 treats one category as abnormal and the others as normal.
  • Datasets and Metrics: AUROC measures image-level anomaly detection and pixel-level anomaly localization, with models outputting one image score or per-pixel scores.
  • Complexity Analysis: Up to 10× faster inference, 1.5× speedup and 2× parameter reduction versus CFlow, and up to 4× and 10× lower additional inference time than CFlow and Patch Core, respectively.The complexity comparison covers inference speed, additional inference time, and additional parameters beyond the backbone.
  • Quantitative Results: 99.4 image-level AUC and 98.5 pixel-level AUC on MVTec AD, surpassing the compared methods on the anomaly detection task.
  • BTAD: 97.0 pixel-wise AUC on BTAD, exceeding the reported comparison methods by as much as 7% AUC.
  • CIFAR-10: FastFlow outperforms the comparison methods on CIFAR-10, and results across three datasets show adaptation to different anomaly detection settings.

4.4 Ablation Study

The ablation study examines FastFlow’s convolution-kernel choices and its bidirectional feature-generation behavior. Results support architecture choices that balance accuracy, parameter count, and inference speed across backbone capacities.

  • Convolution-kernel selection: FastFlow compares alternating 3 × 3 and 1 × 1 convolutions with using only 3 × 3 convolutions in its subnet.The comparison evaluates AUC and inference speed across multiple backbone networks.
  • Convolution-kernel selection: Large-capacity backbones achieve higher performance with alternating kernels while reducing parameters.This pattern is reported for CaiT and Wide-ResNet50-2.
  • Convolution-kernel selection: Small-capacity backbones achieve higher performance with only 3 × 3 convolution layers.This pattern is reported for DeiT and ResNet18.
  • Convolution-kernel selection: FastFlow uses alternating kernels with DeiT, CaiT, and Wide-ResNet50-2, but only 3 × 3 kernels with ResNet18.The selected configurations aim to balance accuracy and inference speed.
  • Feature visualization and generation: FastFlow is a bidirectional invertible probability distribution transformer that maps backbone feature maps to a standard normal distribution and can reverse this mapping.The reverse process generates visual features from probability samples; Figure 4 illustrates both directions and noise-based feature generation.

4.6 Qualitative Results

Qualitative MVTec AD results visualize ground-truth masks alongside anomaly heatmaps for normal and abnormal images. The reported heatmaps provide accurate anomaly localization, while the implementation uses backbone-dependent feature selections.

  • Qualitative localization: Figure 3 places input images and ground-truth localization areas above anomaly localization heatmaps.Ground-truth regions are labeled in red.
  • Qualitative localization: The qualitative examples include both normal and abnormal images with accurate anomaly localization results.The comparison is visual rather than a new numerical evaluation.
  • Feature visualization: FastFlow’s feature visualization uses a bidirectional process that maps visual features to probability maps and reverses probability perturbations into generated feature tensors.Figure 4 marks the original anomaly and the introduced anomaly after noise disturbance with different arrows.
  • Feature extraction: For vision transformers, FastFlow uses features from a specific layer without manually designing complicated multi-scale features.ResNet18 and Wide-ResNet50-2 use features from the last layer in their first three blocks.

5 Conclusion

The conclusion presents FastFlow as a lightweight 2D flow model for unsupervised anomaly detection and localization. It models normal feature distributions, supports common backbones as a plug-in, and outperforms prior methods on MVTec AD in accuracy and reasoning efficiency.

  • Conclusion: FastFlow models global and local information with a learnable 2D flow and efficient inference.The model projects normal-image feature distributions to a standard normal distribution and uses probabilities as anomaly scores.
  • Conclusion: FastFlow operates as a plug-in with typical feature extractors including ResNet and vision transformers.The conclusion describes the method as a lightweight model for unsupervised anomaly detection and localization.
  • Conclusion: FastFlow outperforms state-of-the-art methods on MVTec AD in accuracy and reasoning efficiency.The conclusion reports this outcome across the paper’s experimental evaluation.

Supplementary Material for FastFlow: Unsupervised Anomaly Detection and Localization via 2D Normalizing Flows

The supplementary material reports ablations on hidden-layer channel ratios and data augmentation. These studies examine their effects on anomaly detection and localization performance.

  • Supplementary ablations: Table 7 studies hidden-layer channel ratios for CNN and vision-transformer subnetworks on MVTec AD.The channel ratio is the hidden-layer channel count relative to the subnet’s input and output channels.
  • Supplementary ablations: Table 8 evaluates the effect of data augmentation on anomaly detection and localization performance.The caption identifies both detection and localization as evaluation targets.

6 More Ablation Studies

The ablation studies examine architectural efficiency and augmentation choices in FastFlow. They compare hidden-layer channel widths and caution that augmentation suitability varies across categories.

  • Channel Width: 2× hidden-layer channels increase model complexity but reduce inference efficiency in the original flow model.This design is used in DifferNet and CFLOW.
  • Channel Width: FastFlow uses 0.16× hidden channels for CaiT and 1× for Wide-ResNet50.
  • Data Augmentation: The training procedure applies random horizontal flips, vertical flips, and rotations with probabilities 0.5, 0.3, and 0.7, respectively.
  • Data Augmentation: Some MVTec AD categories are unsuitable for aggressive augmentation because transformations can violate their valid orientations.The transistor category is given as an example.

7 Bad Cases and Ambiguity Label

FastFlow’s MVTec AD errors fall into missed detections, false detections, and label ambiguities. The examples include subtle anomalies, background artifacts, and abnormal regions omitted from annotations.

  • Missing Detection: FastFlow misses some small and unobvious anomalies.
  • False Detection: FastFlow produces false detections in background areas containing features such as hair and dirt.
  • Label Ambiguity: FastFlow identifies some abnormal regions that are not labeled as abnormal, including “scratch neck” on screws and “fabric interior” on zippers.

8 Non-aligned Disturbed MVTec AD Dataset

The study evaluates FastFlow on an unaligned variant of MVTec AD because the original dataset has sample alignment that is uncommon in practical applications. The variant applies spatial perturbations and expands the test set fourfold.

  • Motivation: The original MVTec AD dataset has sample alignment that is infrequent in practical applications.
  • Perturbations: The unaligned test set applies random zooming, rotation of ±15 degrees, and translation with a 0.15 ratio.Random zoom in/out uses a 0.85 ratio.
  • Dataset Construction: The spatial perturbations expand the original test dataset by 4× to create the new test dataset.
  • Evaluation: FastFlow with CaiT is evaluated on the newly constructed unaligned test dataset.
Loading 2111.07677v2…