ReFP-AD: Rectified Flow Preconditioning for Energy-Based Anomaly Detection (ECCV 2026)
August 17, 2026 · View on GitHub
ReFP-AD: Rectified Flow Preconditioning for Energy-Based Anomaly Detection (ECCV 2026)
Condition the representation geometry first. Then learn the energy.
ReFP-AD enables stable energy-based density modeling directly in high-dimensional visual foundation-model token spaces. An OT-coupled rectified flow transforms anisotropic DINOv2 tokens into well-conditioned coordinates, where persistent contrastive divergence with preconditioned SGLD becomes stable and effective.
Paper · Hugging Face · Code · Citation
Overview
Modern vision foundation models provide rich representations for anomaly detection, but their token spaces are strongly anisotropic and correlated. This geometry is poorly matched to finite-step Langevin dynamics, causing unstable negative sampling when training energy-based models.
ReFP-AD addresses the geometry rather than compressing the representation. It:
- extracts dense, full-dimensional DINOv2 tokens;
- standardizes tokens per category while retaining a shared unified model;
- learns an OT-coupled rectified flow into a well-conditioned latent space;
- trains an unconstrained EBM using persistent contrastive divergence and pSGLD;
- detects anomalies using the energy-gradient norm as a local restoring-force signal.

Main results
ReFP-AD is evaluated under a strict unified anomaly-detection protocol: one shared rectified flow and one shared EBM are trained across all categories.
| Dataset | Image AUROC | Pixel AUROC |
|---|---|---|
| MVTec-AD | 98.6 | 97.9 |
| VisA | 97.3 | 99.0 |
Compared with a stabilized unified MPDR baseline, ReFP-AD improves VisA image-level AUROC by 10.8 percentage points. Removing rectified-flow preconditioning reduces image AUROC from 98.6 to 91.1 on MVTec-AD and from 97.3 to 87.0 on VisA.

Why ReFP-AD?
- Full-dimensional energy modeling. No low-dimensional bottleneck is required to stabilize the EBM.
- Geometry-aware training. The transport is selected using diagnostics tailored to finite-step MCMC: conditioning, residual correlation, tail behavior, and structural preservation.
- Unified detection. A single model captures heterogeneous normal distributions across all categories.
- Dense localization. Gradient-norm scores operate on transported patch tokens and produce spatial anomaly maps.
- Strong transfer across backbone scales. The method supports DINOv2 ViT-B/14, ViT-L/14, and ViT-G/14 token spaces.
Repository structure
.
├── backbone.py # DINOv2 token extraction and caching
├── config.py # datasets, modes, and hyperparameters
├── flow.py # rectified-flow model and ODE transport
├── flow_diagnostics.py # geometry and MCMC-oriented diagnostics
├── ot.py # optimal-transport coupling
├── ebm.py # energy model, replay buffer, and pSGLD
├── training.py # flow and EBM optimization
├── pipeline.py # unified, per-category, and hybrid pipelines
├── evaluate.py # image- and pixel-level evaluation
├── visualize.py # qualitative and diagnostic plots
├── main.py # command-line entry point
├── benchmark.sh # example Slurm job
└── environment.yml # Conda environment
Installation
The supplied environment targets Python 3.10 and CUDA-enabled PyTorch.
conda env create -f environment.yml
conda activate refpad
The DINOv2 backbone is downloaded from Hugging Face on first use. Make sure the machine has sufficient GPU memory and disk space for token caches.
Dataset preparation
MVTec-AD
Use the standard MVTec-AD directory structure:
/path/to/mvtec-ad/
├── bottle/
│ ├── train/good/
│ ├── test/...
│ └── ground_truth/...
├── cable/
└── ...
VisA
The current loader expects the one-class PyTorch-style layout:
/path/to/VisA_pytorch/1cls/
├── candle/
│ ├── train/
│ ├── test/
│ └── ground_truth/
├── capsules/
└── ...
Running ReFP-AD
Run commands from the repository directory containing main.py.
Unified training and evaluation
python main.py \
--mode UNIFIED \
--dataset MVTec \
--data_path /path/to/mvtec-ad \
--out_dir ./outputs/mvtec_unified
python main.py \
--mode UNIFIED \
--dataset VisA \
--data_path /path/to/VisA_pytorch/1cls \
--out_dir ./outputs/visa_unified
Evaluate a checkpoint
python main.py \
--mode UNIFIED \
--dataset MVTec \
--data_path /path/to/mvtec-ad \
--out_dir ./outputs/mvtec_eval \
--eval_only \
--ckpt /path/to/checkpoint.pt
Compare modeling modes
The code supports three configurations:
UNIFIED: one flow and one EBM across all categories;PER_CATEGORY: independent flow and EBM per category;
Disable geometric preconditioning
python main.py \
--mode UNIFIED \
--dataset MVTec \
--data_path /path/to/mvtec-ad \
--out_dir ./outputs/no_flow \
--no_flow
Important configuration
The main experimental defaults are defined in config.py:
| Component | Default |
|---|---|
| Backbone | DINOv2 ViT-G/14 with registers |
| Feature dimension | 1536 |
| Input crop | 672 × 672 |
| Flow | 8-layer MLP, hidden dimension 1024 |
| ODE integration | 10-step RK4 |
| EBM | 3-layer residual MLP, hidden dimension 1024 |
| Replay buffer | 400,000 states |
| Negative sampling | 60-step pSGLD |
| Patch score | energy-gradient norm |
| Image score | mean of top 1% pixel scores |
Large-scale unified training is memory intensive (due to token cache). The included benchmark.sh requests one H100 GPU and 384 GB of system memory; adapt this configuration to your cluster.
Outputs
A run writes its configuration, checkpoint, evaluation results, and visualizations to --out_dir. The principal metrics are stored in:
<out_dir>/results.json
The evaluation summary contains per-category image/pixel AUROC together with macro averages.
Reproducibility notes
- Set
--seedto reproduce sampling and training initialization. - Token extraction is cached to avoid repeatedly running the frozen backbone.
- Results can depend on GPU model, CUDA/PyTorch versions, and the numerical behavior of OT and Langevin sampling.
Citation
@misc{lendering2026refpadrectifiedflowpreconditioning,
title={ReFP-AD: Rectified Flow Preconditioning for Energy-Based Anomaly Detection},
author={Camile Lendering and Erkut Akdag and Joaquín Figueira and Egor Bondarev},
year={2026},
eprint={2608.01793},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2608.01793},
}
The BibTeX entry will be updated with the official ECCV proceedings metadata and arXiv identifier when available.
Acknowledgements
This work is supported by the ADVISOR ITEA 241007 project.
Contact
For questions, please open a GitHub issue.