File size: 2,563 Bytes
e91908a
 
98262f2
 
 
 
 
 
 
 
 
 
e91908a
98262f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
license: mit
library_name: pytorch
tags:
- anomaly-detection
- industrial-inspection
- flow-matching
- diffusion-transformer
- dinov2
- mvtec-ad
- visa
- btad
---

# AFR: Antithetic Flow-Matching Residuals for Multi-Class Anomaly Detection

Checkpoints of the paper [Antithetic Flow-Matching Residuals for Multi-Class Anomaly Detection](https://arxiv.org/abs/2612.01546)
(Shayan Shashaani, Marco Tasca, Jawad Tayyub). Code: https://github.com/Vshayan/Antithetic-Flow-Matching

AFR detects and localizes defects with one flow-matching model per dataset, trained on the normal images of all categories, without
category labels. The model is a DiT-B (130.7M parameters) that works on frozen DINOv2 ViT-B/14 (with registers) patch features at
448 x 448 pixels. A test image is noised at 10 levels with one antithetic noise pair (+e, -e) shared by all levels, and the anomaly score
of a patch is the average over levels of its pair-mean residual, with every channel divided by its normal variance.

## Files

| File | Trained on | Steps |
|---|---|---|
| `afr_mvtec.pt` | MVTec AD, all 15 categories | 40k |
| `afr_visa.pt`  | VisA, all 12 categories | 95k |
| `afr_btad.pt`  | BTAD, all 3 products | 20k |

EMA weights, about 520 MB each. They are loaded by the code in the GitHub repository.

## Usage

```bash
git clone https://github.com/Vshayan/Antithetic-Flow-Matching && cd Antithetic-Flow-Matching
pip install -r requirements.txt huggingface_hub
huggingface-cli download Vshayan3/AFR afr_mvtec.pt --local-dir checkpoints

python -m afr.features --dataset mvtec
python -m afr.score    --dataset mvtec --ckpt checkpoints/afr_mvtec.pt
python -m afr.evaluate --dataset mvtec --save-maps
```

See the repository README for the data layout and the other datasets.

## Results

Multi-class setting, category means. mAD is the mean of I-AUROC, I-AP, I-F1max, P-AUROC, P-AP, P-F1max and AUPRO. Loose masks follow
the mask resizing of the Dinomaly and INP-Former evaluation code, strict masks use nearest-neighbor resizing.

| Dataset | I-AUROC | P-AUROC | AUPRO | mAD (loose masks) | mAD (strict masks) |
|---|---|---|---|---|---|
| MVTec AD | 99.70 | 98.67 | 96.12 | 91.25 | 90.48 |
| VisA     | 99.12 | 99.15 | 95.82 | 86.57 | 85.48 |
| BTAD     | 97.36 | 98.41 | 82.07 | 88.61 | 88.17 |

## Citation

```bibtex
@article{shashaani2026afr,
  title   = {Antithetic Flow-Matching Residuals for Multi-Class Anomaly Detection},
  author  = {Shashaani, Shayan and Tasca, Marco and Tayyub, Jawad},
  journal = {arXiv preprint arXiv:2612.01546},
  year    = {2026}
}
```