# SubspaceAD **Repository Path**: w2317q/SubspaceAD ## Basic Information - **Project Name**: SubspaceAD - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-13 - **Last Updated**: 2026-05-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SubspaceAD
This repository contains the official implementation of the paper: > [**SubspaceAD: Training-Free Few-Shot Anomaly Detection via Subspace Modeling (CVPR2026)**](https://arxiv.org/abs/2602.23013) ---
MVTec-AD |
VisA |
Figure 2. Qualitative comparison on VisA and MVTec-AD (1-shot). SubspaceAD produces sharper and more precise anomaly maps than PromptAD and AnomalyDINO, with fewer false activations and better alignment with ground-truth defects across both datasets.
## Environment Setup ```bash # 1. Create environment conda create -n subspacead python=3.10 conda activate subspacead # 2. Install dependencies and the package pip install -r requirements.txt pip install -e . ``` ## Data Preparation ### MVTec-AD Download the dataset from the [MVTec website](https://www.mvtec.com/company/research/datasets/mvtec-ad) and extract it to: ``` datasets/mvtec-ad/ ``` ### VisA ```bash # 1. Download and extract mkdir -p datasets/VisA_20220922 wget https://amazon-visual-anomaly.s3.us-west-2.amazonaws.com/VisA_20220922.tar tar -xvf VisA_20220922.tar -C datasets/VisA_20220922 # 2. Preprocess (reorganize folder structure) python tools/prepare_visa.py \ --data-folder datasets/VisA_20220922 \ --save-folder datasets/VisA_pytorch ``` ## Folder Structure ```text pca-dino/ ├── datasets/ # Dataset root │ ├── mvtec-ad/ │ └── VisA_pytorch/ ├── logs/ # Experiment logs ├── scripts/ # SLURM/Bash benchmark scripts │ ├── benchmark_few_shot.sh │ ├── benchmark_full_shot.sh │ └── ... ├── src/ │ └── subspacead/ │ ├── core/ # PCA + feature extraction code │ ├── data/ # Dataset loaders & transforms │ ├── post_process/ # Scoring, pixel maps, filters │ └── utils/ # Visualization, logging ├── tools/ │ └── prepare_visa.py ├── main.py └── README.md ``` ## Usage ### Benchmark Scripts Scripts are provided in `scripts/` to reproduce all results. Edit `MVTEC_PATH` and `VISA_PATH` inside the scripts as needed. **Few-Shot (1, 2, 4 Shots)** Selects *k* normal images per category. ```bash bash scripts/benchmark_few_shot.sh ``` **Batched Zero-Shot** Fits PCA on the full unlabeled test set. ```bash bash scripts/benchmark_batched0shot.sh ``` **Full-Shot** Uses all training images. ```bash bash scripts/benchmark_full_shot.sh ``` ### Manual Execution Example: 1-shot MVTec-AD on `bottle`: ```bash python main.py \ --dataset_name mvtec_ad \ --dataset_path datasets/mvtec-ad \ --categories bottle \ --model_ckpt facebook/dinov2-with-registers-giant \ --image_res 672 \ --k_shot 1 \ --aug_count 30 \ --pca_ev 0.99 \ --outdir results/debug_run ``` ## Benchmark Results ### Few-Shot (Image AUROC) | Setting | Method | MVTec-AD | VisA | | ---------- | -------------- | -------- | -------- | | **1-Shot** | PromptAD | 94.2 | 86.9 | | | AnomalyDINO | 96.6 | 87.4 | | | **SubspaceAD** | **97.1** | **93.4** | | **2-Shot** | PromptAD | 95.7 | 88.3 | | | AnomalyDINO | 96.9 | 89.7 | | | **SubspaceAD** | **97.6** | **93.7** | | **4-Shot** | PromptAD | 96.6 | 89.1 | | | AnomalyDINO | 97.7 | 92.6 | | | **SubspaceAD** | **97.9** | **94.7** | ### Batched Zero-Shot | Method | MVTec-AD | VisA | | -------------- | -------- | -------- | | MuSc | **97.8** | **94.1** | | AnomalyDINO | 94.2 | 90.7 | | **SubspaceAD** | 96.6 | **94.1** | ## Citation If you find this repository useful, please consider citing: ```bibtex @misc{lendering2026subspaceadtrainingfreefewshotanomaly, title={SubspaceAD: Training-Free Few-Shot Anomaly Detection via Subspace Modeling}, author={Camile Lendering and Erkut Akdag and Egor Bondarev}, year={2026}, eprint={2602.23013}, archivePrefix={arXiv}, primaryClass={cs.CV}, url={https://arxiv.org/abs/2602.23013}, } ```