Computer Vision / Industrial AI / Anomaly Detection
Industrial Visual Anomaly Detection
Few-Shot Computer Vision for Manufacturing Quality Inspection
A reference-based inspection pipeline that uses DINOv2 visual representations to identify manufacturing anomalies without extensive defect-specific annotations.
Illustrative anomaly visualization
Synthetic component · not actual model output.
Project Overview
Industrial defects are difficult to model when annotated examples are limited and visual conditions vary. Supervised detection typically depends on examples of known defect categories.
This reference-based workflow compares incoming images against confirmed-good visual representations. DINOv2 extracts features, while ROI-aware processing reduces the influence of irrelevant regions. The result measures visual deviation rather than assigning a specific defect category.
System Architecture
Computer vision / System architecture
Learn normal. Inspect the difference.
Pretrained features
Reference-based comparison
Two image paths share a frozen visual encoder and converge at reference matching. Ranking quality and threshold-dependent decisions are evaluated separately.
Confirmed-good images
A small reference set represents normal component appearance.
RGB conversion + model preprocessing
New inspection image
Look for visual deviation, rather than a named defect category.
Same RGB conversion + preprocessing
DINOv2 Small
vit_small_patch14_dinov2Forward passes only · no fine-tuning
PCA-based foreground masking
Built-in AnomalyDINO masking after feature extraction, before anomaly scoring.
Reference feature memory
Confirmed-good patch representation
Inspection patch features
Foreground-aware comparison
Experiment configuration: internal masking ON · image-space auto-ROI OFF
Patch-level reference matching
AnomalyDINO compares local features with the confirmed-good memory using kNN.
Anomaly map
Where visual deviations appear
Anomaly score
How unusual the image appears
All component, patch and anomaly-map drawings are synthetic schematics, not inspection outputs.
Compare score with threshold
The threshold changes flags; it does not change the ranking of scores.
- s(x) < τ
- No anomaly flag
- s(x) ≥ τ
- Anomaly flag
An inspection rule under investigation, not a production-validated cutoff.
Offline analysis of labeled examples and detector scores · outside per-image inference
Frozen calibration split
12 good + 12 defective
Separate from reference images
Score distributions
Compare good and defect scores.
Inspect separation and overlap.
AUROC + bootstrap
Threshold-independent ranking
Uncertainty under resampling
Youden · P95 · P99
Threshold candidates
Recall ↔ false-positive rate
Candidates provide evidence for review; calibration does not automatically update the runtime threshold. The independent holdout is not reported as evaluated in this calibration study.
Experimental context Separate stages
AUROC ≈ 0.64 → 0.81
A historical masking evaluation, not a controlled comparison with the later calibration split.
0 of 50 images flagged
Configured cutoff: 0.72. A separate historical observation, not the later calibration operating point.
AUROC 0.784722
12 good + 12 defective.
95% bootstrap interval:
[0.583333, 0.944444]
Text architecture & implementation scope
Confirmed-good reference images and inspection images use the same preprocessing and pretrained DINOv2 Small encoder. Reference preparation builds a feature memory through forward passes, without supervised training or weight updates.
The documented masking experiment uses AnomalyDINO’s built-in PCA-based foreground masking on extracted features. Image-space auto-ROI is a different operation and is disabled in the calibration configuration shown here. Masking does not guarantee removal of all background influence.
Inspection features are compared against the reference memory with patch-level kNN. The model returns a spatial anomaly map and an image-level score. This diagram does not specify an unverified score-aggregation formula. A configured threshold turns the score into a flag; AUROC assesses ranking independently of that cutoff.
Labeled calibration examples support score-distribution analysis, threshold-candidate assessment, and stratified bootstrap AUROC uncertainty. Historical ROI results, the historical 0.72 threshold observation, and the later 12-good/12-defective calibration results describe separate experimental contexts. No production deployment, vector database, or model fine-tuning is represented.
Interactive Anomaly Inspection
From visual deviation to a decision
Synthetic component · illustrative controlsIllustrative visualization — not actual model output
Authored SVG geometry and heatmap. This visualization does not run DINOv2 inference or identify a defect category.
Illustrative score & threshold
- Illustrative anomaly score
- 0.62
- Illustrative threshold
- 0.55
Illustrative decision: review region
Score ≥ threshold.
Demo values use a pedagogical 0–1 scale and are unrelated to the calibration scores below.
Evaluating Anomaly Separation
Evaluate ranking separately from inspection decisions. The calibration estimate and earlier ROI investigation below come from distinct evaluation contexts.
Calibration AUROC
0.785
95% Bootstrap CI: 0.583–0.944
Historical ROI Evaluation
Separate historical evaluation
- Before ROI masking
- ~0.64 AUROC
- After ROI masking
- ~0.81 AUROC
Calibration score overlap
Aggregate ranges & means only- Confirmed good
Range 0.2228–0.3576 · mean 0.2860
- Defect observations
Range 0.2732–0.4158 · mean 0.3262
Balancing Detection and False Alarms
Calibration-set operating points
Compare detection recall and false alarms. These operating points do not select a production threshold.
Calibration-only threshold candidate
- Defect recall
- 75.0%
- False-positive rate
- 25.0%
Recall
False-positive rate
Higher calibration defect recall comes with more false alarms: 75.0% recall at a 25.0% false-positive rate. This candidate uses defect labels from calibration.
Engineering Beyond the Model
Reference-Based Detection
Use pretrained DINOv2 representations and confirmed-good reference features instead of a conventional defect classifier.
Leakage-Safe Calibration
Separate calibration and holdout data. Freeze threshold candidates before holdout evaluation to prevent evaluation leakage.
Reproducible ML Engineering
Record model fingerprints, runtime metadata, split definitions, evaluation metrics, and automated test results.
Historical threshold and ROI investigations revealed that anomaly ranking and operational inspection decisions require separate evaluation.
Technology Stack
Vision Models
- DINOv2
- Anomalib
- PyTorch
Image Processing
- OpenCV
- NumPy
Evaluation
- AUROC
- Bootstrap Confidence Intervals
- Threshold Calibration
Engineering
- Python
- Pytest
- Ruff
- Black
- GitHub Actions
Integration Targets
- FastAPI · Planned
- Docker · Planned
- NVIDIA Jetson · Planned
Intended integration targets. API, container, and Jetson deployment are not claimed.