How sun-9545sunoj/few-shot-anomaly-detection works
This repository is a research and demonstration system for few-shot, unsupervised industrial defect detection. Its main workflow extracts features from normal support images, builds a reference model, scores inspection images, converts patch scores into heat maps and image scores, then applies a threshold fitted on held-out normals to produce PASS/REJECT decisions. Experiment sweeps measure accuracy and cost; reporting, stress analysis, failure analysis, and the single-image demo are additional product capabilities. The tree omits the documented data package, so dataset-loading internals are not mapped.
Main entry points: experiment.py Experiment sweep · base.py Method interface · demo.py Single-image demo · decision.py Threshold decision
Components 22
Detection workflow
- Map post-processing
src/postprocess.py - Threshold decision
src/decision.py
Feature and methods
- WideResNet features
src/models/backbone.py - CLIP features
src/models/clip_backbone.py - Method interface
src/methods/base.py - PatchCore
src/methods/patchcore.py - PaDiM
src/methods/padim.py - WinCLIP
src/methods/winclip.py
Experiment analysis
- Experiment sweep
src/experiment.py - Detection metrics
src/metrics.py - Cost profiling
src/profiling.py - Support-set stress
src/stress.py - Failure analysis
src/failures.py - Result reporting
src/report.py - Result tables
src/tables.py - Dataset integrity check
src/inventory.py - Smoke baseline
src/baseline.py
Inspection outputs
- Qualitative grids
src/qualitative.py - Single-image demo
src/demo.py
Run configuration
- Validated run config
src/config/schema.py
Other components
- Engineer or inspector
- MVTec AD / VisA
Connections 29
- Engineer or inspector → Experiment sweep: configures sweep
README.md - MVTec AD / VisA → Experiment sweep: supplies images
README.md - Engineer or inspector → Single-image demo: inspects image
README.md - MVTec AD / VisA → Single-image demo: supplies images
README.md - Validated run config → Experiment sweep: configures run
src/experiment.py - Experiment sweep → WideResNet features: extracts features
src/experiment.py - Experiment sweep → CLIP features: extracts features
src/experiment.py - Experiment sweep → Method interface: builds method
src/experiment.py - Method interface → PatchCore: dispatches to
src/methods/base.py - Method interface → PaDiM: dispatches to
src/methods/base.py - Method interface → WinCLIP: dispatches to
src/methods/base.py - Experiment sweep → Map post-processing: processes maps
src/experiment.py - Experiment sweep → Threshold decision: fits threshold
src/experiment.py - Experiment sweep → Detection metrics: computes metrics
src/experiment.py - Experiment sweep → Cost profiling: profiles cost
src/experiment.py - Experiment sweep → Support-set stress: measures stress
src/experiment.py - Failure analysis → Experiment sweep: reuses runs
src/failures.py - Failure analysis → Support-set stress: analyzes causes
src/failures.py - Result reporting → Result tables: builds tables
src/report.py - Result tables → Detection metrics: summarizes metrics
src/tables.py - Result tables → Threshold decision: summarizes decisions
src/tables.py - Qualitative grids → Experiment sweep: reads results
src/qualitative.py - Qualitative grids → Map post-processing: renders maps
src/qualitative.py - Qualitative grids → Threshold decision: shows verdicts
src/qualitative.py - Single-image demo → Threshold decision: applies threshold
src/demo.py - Single-image demo → Map post-processing: scores maps
src/demo.py - Single-image demo → Method interface: builds method
src/demo.py - Dataset integrity check → MVTec AD / VisA: checks integrity
README.md - Smoke baseline → Detection metrics: measures baseline
src/baseline.py