Upload README.md
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869---license: mitlibrary_name: pytorchtags:- 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, withoutcategory labels. The model is a DiT-B (130.7M parameters) that works on frozen DINOv2 ViT-B/14 (with registers) patch features at448 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 scoreof 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
```bashgit clone https://github.com/Vshayan/Antithetic-Flow-Matching && cd Antithetic-Flow-Matchingpip install -r requirements.txt huggingface_hubhuggingface-cli download Vshayan3/AFR afr_mvtec.pt --local-dir checkpoints
python -m afr.features --dataset mvtecpython -m afr.score --dataset mvtec --ckpt checkpoints/afr_mvtec.ptpython -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 followthe 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}}```README.md+66