Flownomaly: Few-Shot Anomaly Detection via Single-Step Conditional Mean Restoration

Flownomaly uses conditional flow matching in a frozen DINOv2 feature space to restore normal counterparts in a single step, detecting few-shot industrial anomalies via residuals.
Flownomaly proposes a new approach for few-shot industrial anomaly detection: instead of reconstructing images, it performs conditional flow matching in a frozen DINOv2 patch feature space, learning a velocity field that transports Gaussian noise to the normal feature distribution. Because the path is constrained to be straight, the optimal field at any time step yields the posterior mean, so inference requires only a single field evaluation to restore a query token to its normal counterpart, using the squared residual before and after restoration as the anomaly signal. To address the difficulty of tuning the restoration step size without anomalous validation samples, the authors propose a Jacobian gain–noise criterion that relies solely on normal samples to select the operating time. On the 1-shot benchmarks of MVTec-AD and VisA, image-level AUROC reaches 97.8% and 95.3%, and pixel-level reaches 98.0% and 98.7%, with VisA image-level leading the strongest baseline by 2.1 points.
Title
Flownomaly: Few-Shot Anomaly Detection via Single-Step Conditional Mean Restoration
Meta Description
Flownomaly turns few-shot industrial anomaly detection into restoring normal counterparts in a frozen DINOv2 feature space, using conditional flow matching and single-step posterior mean to achieve 97.8% image-level AUROC on MVTec-AD and 95.3% on VisA in the 1-shot setting—without needing anomalous validation samples for parameter selection.
Article Content
The challenge of few-shot industrial anomaly detection is this: with only a handful of defect-free samples per category, the model must learn what "normal" looks like from these few images, then determine where anomalies lie in any query image. Existing methods either bind inference to stored samples, impose linear structure, or—during reconstruction—end up "restoring" the anomalous content as well. Flownomaly takes a different approach: instead of reconstructing the image, it pulls query tokens back toward their "normal counterparts" in a frozen DINOv2 feature space, using the residual before and after restoration as the anomaly signal.

Problem Setting: Learning Category-Specific Normality from Few Samples
Industrial anomaly detection is typically modeled per category: each product category has its own detector trained or adapted separately. The few-shot setting further compresses the available normal images to 1, 2, or 4. This means the model cannot rely on large amounts of data to estimate distributions; it must leverage the general visual structure already encoded in pretrained feature spaces.
Flownomaly's approach transforms the problem into "normal counterpart restoration": given a few normal support samples, it learns a velocity field that transports Gaussian noise to the vicinity of the normal feature distribution; for a query token, this field performs a single restoration to obtain its corresponding point on the normal manifold. The degree of anomaly is measured by the squared residual between the query token and the restored result.
Method Core: Conditional Flow Matching and Single-Step Restoration
Learning a Velocity Field in a Frozen Feature Space
Flownomaly does not fine-tune the DINOv2 backbone; instead, it performs conditional flow matching on frozen patch tokens. Conditioned on the features of normal support samples, it learns a velocity field that transports standard Gaussian noise along a straight-line path to the normal features. Because the path is constrained to be straight, the optimal field at any time step directly yields the posterior mean, so inference does not require integrating along the trajectory—a single field evaluation gives the conditional mean of clean normal tokens.
This design turns "de-anomalization" into a single forward computation rather than iterative diffusion sampling, significantly reducing inference overhead and making deployment in few-shot scenarios more realistic.
Conditional Flow Matching originates from the Continuous Normalizing Flow (CNF) framework: a neural network-parameterized velocity field v(x,t) defines a time-continuous transformation that maps a simple distribution (e.g., standard Gaussian) to the target data distribution. During training, rather than directly simulating the ODE trajectory, a conditional path from noise to data is sampled for each example, and the network regresses the instantaneous velocity along that path. When the path is specified as a straight line, the target velocity is constantly the endpoint minus the starting point, making the training objective very simple. The key theoretical result is: for velocity regression on straight-line conditional paths, the optimal solution at all times equals the posterior mean of the endpoint given the condition. Flownomaly exploits exactly this property—at inference, only a single evaluation of the field at a chosen time step is needed to obtain the conditional mean of the query token on the normal manifold, eliminating ODE integration.
Choosing the Operating Time: Selecting Restoration Strength from Normal Samples Themselves
The restoration step size is controlled by an "operating time" parameter, which determines how much the restoration modifies the query token. If the time is too small, anomalies remain; if too large, normal details are smoothed away. The difficulty is that in the few-shot setting, no anomalous validation samples are available for tuning.
Flownomaly proposes a Jacobian gain–noise criterion that relies solely on normal samples: it evaluates the trade-off between the amplification of perturbations by the restoration mapping and the noise level on the support set, and selects the operating time accordingly. In other words, the restoration strength is not set arbitrarily but derived from the geometric properties of the normal data itself.
Jacobian gain refers to the local amplification factor of the restoration mapping for small input perturbations, characterized by the spectral norm (or a related quantity) of the mapping's Jacobian matrix at the support samples. Too large a gain means the mapping is sensitive to noise and perturbations, leading to higher variance in the restored output; too small a gain means the mapping is close to identity and lacks the ability to correct anomalous deviations. The noise criterion incorporates the noise level of the support set features themselves into the trade-off: given a noise level, the restoration error can be estimated as the product of gain and noise. The Jacobian gain–noise criterion essentially seeks a balance between "over-correction" and "under-correction," and its advantage is that the entire evaluation uses only normal support samples, requiring no anomalous samples or labels—thus fitting the practical constraint of unavailable anomalous samples in few-shot industrial settings.
Experimental Results: Image-Level and Pixel-Level Metrics in the 1-Shot Setting
The paper covers 1-, 2-, and 4-shot benchmarks on MVTec-AD and VisA, and evaluates varying sample counts on Real-IAD, achieving state-of-the-art results compared with recent category-specific methods.
Key numbers in the 1-shot setting:
- MVTec-AD: image-level AUROC 97.8%, pixel-level AUROC 98.0%
- VisA: image-level AUROC 95.3%, pixel-level AUROC 98.7%, image-level 2.1 points higher than the strongest baseline
The pixel-level AUROC approaching 98% in the 1-shot setting indicates that the residual maps produced by single-step restoration are sharp enough for localization; the gap between image-level and pixel-level is also small, meaning the method does not suffer from the common imbalance of "good localization but weak whole-image judgment."
AUROC (Area Under the ROC Curve) is one of the most commonly used evaluation metrics for anomaly detection, measuring the model's overall ability to rank anomalous samples ahead of normal ones; a value of 0.5 corresponds to random guessing, and 1.0 to perfect ranking. Image-level AUROC operates on the anomaly score of the entire image, while pixel-level AUROC independently evaluates the ranking quality of each pixel's anomaly score, measuring defect localization ability. Since industrial anomaly detection has far more normal samples than anomalous ones, AUROC is insensitive to class imbalance and thus more suitable than accuracy. A pixel-level AUROC approaching 98% in the 1-shot setting means the anomaly score correctly distinguishes defects from background at the vast majority of pixel locations, and the residual maps produced by single-step restoration are sharp enough for spatial localization.
Key Takeaways
First, transforming anomaly detection into counterpart restoration in feature space bypasses the pitfall of pixel reconstruction inadvertently reproducing anomalous content. A structural risk of reconstruction-based methods is that if the decoder is powerful enough, it may also reconstruct defect textures, causing the residual to vanish. Flownomaly performs conditional transport on frozen features, with the restoration target anchored to normal support samples, structurally reducing this risk.
Second, single-step inference stems from the mathematical properties of straight-line paths, not an engineering approximation. Under conditional flow matching with straight-line paths, the posterior mean can be directly obtained from a single field evaluation, ensuring that "fast" and "accurate" do not conflict.
Third, hyperparameter selection without anomalous validation samples is a long-neglected engineering pain point. The value of the Jacobian gain–noise criterion lies not only in eliminating tuning but also in making few-shot methods reproducible on actual production lines—when no anomalous samples are available, the parameter selection process itself must be normal.
The code is open-sourced at github.com/b-rbmp/Flownomaly, and the few-shot benchmarks can be directly reproduced on MVTec-AD and VisA.
Limitations and Applicable Boundaries
The paper's evaluation focuses on industrial inspection benchmarks; category-specific modeling means each category requires separate adaptation, and cross-category generalization has not yet been discussed. The frozen DINOv2 features also mean the method's upper bound is constrained by the sensitivity of that feature space to fine-grained defects. Furthermore, the choice of operating time depends on the support set size, and stability in the extreme 1-shot setting still warrants validation on more categories.
One-line Summary
Flownomaly uses conditional flow matching in a frozen DINOv2 feature space to restore normal counterparts in a single step, detecting few-shot industrial anomalies via residuals.
Paragraph Summary
Flownomaly proposes a new approach for few-shot industrial anomaly detection: instead of reconstructing images, it performs conditional flow matching in a frozen DINOv2 patch feature space, learning a velocity field that transports Gaussian noise to the normal feature distribution. Because the path is constrained to be straight, the optimal field at any time step yields the posterior mean, so inference requires only a single field evaluation to restore a query token to its normal counterpart, using the squared residual before and after restoration as the anomaly signal. To address the difficulty of tuning the restoration step size without anomalous validation samples, the authors propose a Jacobian gain–noise criterion that relies solely on normal samples to select the operating time. On the 1-shot benchmarks of MVTec-AD and VisA, image-level AUROC reaches 97.8% and 95.3%, and pixel-level reaches 98.0% and 98.7%, with VisA image-level leading the strongest baseline by 2.1 points.
Related articles

Vibe Coding Full-Stack in Practice: AI Programming from Beginner to Enterprise Deployment
From Cursor to Claude Code, this Bilibili AI programming course uses four progressive projects to cover full-stack development, open-source secondary development, and team collaboration. The article analyzes the shock to frontend roles, the efficiency shift from 50 people to 5, and the methodology required for enterprise-grade projects.

David Blaine's Global Quest for Real Magic: From South Africa to Japan and India
David Blaine travels to South Africa, Japan, and India in his Do Not Attempt special, documenting Spinning drivers, black mamba rescuers, iaijutsu masters, and ascetics—exploring the boundary between magic and real human极限 challenges.

Is a Touchscreen MacBook Coming? Vergecast Reveals Apple Executive's Response
Vergecast podcast reveals a conversation between a reporter and Apple executive John Ternus about a touchscreen MacBook and Apple Pencil support. Ternus says iPad is the best device for a stylus, while the reporter bets MacBook will eventually support Apple Pencil.