Spaces:
Running
on
Zero
A newer version of the Gradio SDK is available:
6.3.0
title: PatchKNN Anomaly Detection
emoji: 🔍
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 6.1.0
app_file: app.py
python:
- requirements.txt
Zero-, One-, and Few-Shot Anomaly Detection Using Foundation Models
This repository contains the code and resources for “Zero-, One-, and Few-Shot Anomaly Detection Using Foundation Models”, a project for the 02456 Deep Learning course at DTU Compute (Fall 2025). The work studies how vision foundation models—primarily DINOv3—can detect industrial anomalies with minimal training data, and how optional foreground segmentation (PCA or SAM3) affects performance.
Authors
- Adams Ali Gills (s243894)
- Berk Yozkan (s253820)
- Mikolaj Zbigniew Dzwigalo (s253816)
- Vladimir Salnikov (s252682)
Overview
We evaluate anomaly detection in three data regimes:
- Zero-shot: text–image similarity with DINOv3 encoders.
- One-shot / Few-shot (PatchKNN): build a memory bank from 1–5 reference images, compute patch-level k-NN distances for test images, and upsample to heatmaps.
- Segmentation ablations: compare no segmentation vs. PCA-based masks vs. SAM3 prompts to see when foreground masking helps (notably for small objects).
Experiments are run on MVTec AD and a private dataset (concrete/wood walls) to probe robustness and data contamination concerns. Metrics include image-level AUROC/F1 and pixel-level AUROC/F1.
Quick Preview
- Space demo: Gradio app in this repo (
app.py) shows PatchKNN heatmaps (with optional SAM3 masking). - Backbones: DINOv3-S/B/L interchangeable via
backbones/. - Segmenters: PCA and SAM3 wrappers in
segmenters/.
Feel free to explore the code and adapt the demo Space for your own datasets or backbone choices.