Perform Few-shot Anomaly Detection
mainUse the run_anomalydino.py script to evaluate few-shot anomaly detection. You can specify the number of shots, repetitions (seeds), and preprocessing method.
Preprocessing Options:
agnostic: (Default) Applies masking where PCA-based masking works well and augments reference samples by rotations.informed: Use this for faster inspection.
Preprocessing logic can be customized in src/utils.py within the get_dataset_info function.
Key CLI Arguments:
--dataset: The dataset name (e.g.,MVTecorVisA).--shots: A list of shot counts (e.g.,1 2 4 8 16).--num_seeds: Number of repetitions.--preprocess: Preprocessing strategy (agnosticorinformed).--data_root: Path to the dataset root.--eval_segm: Activate this flag to enable segmentation metric evaluation.
Results are saved in the respective results directory as metrics_seed={seed}.json for each seed. The script automatically generates example plots and anomaly maps.
# Reproduce default settings for MVTec
python run_anomalydino.py --dataset MVTec --shots 1 2 4 8 16 --num_seeds 3 --preprocess agnostic --data_root data/mvtec_anomaly_detection
# Faster inspection for VisA
python run_anomalydino.py --dataset VisA --shots 1 --num_seeds 1 --preprocess informed --data_root data/VisA_pytorch/1cls/