← All projects

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.

DINOv2PyTorchAnomalibOpenCVComputer Vision
Visual deviation, made visible
REGION OF INTERESTSUSPICIOUS REGION

Illustrative anomaly visualization

Synthetic component · not actual model output.

01

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.

02

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.

Preparation · before inspection

Confirmed-good images

A small reference set represents normal component appearance.

RGB conversion + model preprocessing

Inference · per image

New inspection image

Look for visual deviation, rather than a named defect category.

Same RGB conversion + preprocessing

Reference patches
Shared pretrained weights

DINOv2 Small

vit_small_patch14_dinov2

Forward passes only · no fine-tuning

Inspection patches

PCA-based foreground masking

Built-in AnomalyDINO masking after feature extraction, before anomaly scoring.

Reference path output

Reference feature memory

Confirmed-good patch representation

Inspection path output

Inspection patch features

Foreground-aware comparison

Experiment configuration: internal masking ON · image-space auto-ROI OFF

Normal reference featuresInspection features
Paths converge

Patch-level reference matching

AnomalyDINO compares local features with the confirmed-good memory using kNN.

Spatial output

Anomaly map

Where visual deviations appear

Image-level output

Anomaly score

How unusual the image appears

All component, patch and anomaly-map drawings are synthetic schematics, not inspection outputs.

Configured cutoff · τ

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

01 / Define

Frozen calibration split

12 good + 12 defective
Separate from reference images

02 / Inspect scores

Score distributions

Compare good and defect scores.
Inspect separation and overlap.

Ranking quality

AUROC + bootstrap

Threshold-independent ranking
Uncertainty under resampling

Decision quality

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
Earlier / ROI investigation

AUROC ≈ 0.64 → 0.81

A historical masking evaluation, not a controlled comparison with the later calibration split.

Historical / Threshold observation

0 of 50 images flagged

Configured cutoff: 0.72. A separate historical observation, not the later calibration operating point.

Later / Frozen calibration

AUROC 0.784722

12 good + 12 defective.
95% bootstrap interval:
[0.583333, 0.944444]

Image / feature flowReference matchingOffline score analysis
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.

FIG. 01 / Reference-based visual anomaly detectionResearch workflow · synthetic illustrations · no inference executed
03

Interactive Anomaly Inspection

From visual deviation to a decision

Synthetic component · illustrative controls
REGION OF INTERESTSUSPICIOUS REGION

Illustrative visualization — not actual model output

Authored SVG geometry and heatmap. This visualization does not run DINOv2 inference or identify a defect category.

Lower deviationHigher deviation
Visualization mode
Inspection layers
55%

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.

04

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

The wide confidence interval indicates uncertainty in the estimated anomaly-ranking performance. Point: calibration AUROC; band: 95% bootstrap CI. These are calibration-set results, not independent holdout or production performance.

Historical ROI Evaluation

Separate historical evaluation

Before ROI masking
~0.64 AUROC
After ROI masking
~0.81 AUROC
ROI-aware processing improved anomaly ranking in an earlier masking experiment. This separate evaluation is not directly comparable with the later calibration AUROC and does not establish production performance.

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

Bands show observed ranges; dots mark means. These are not per-image observations or fitted distributions. Overlapping scores make threshold selection challenging.
05

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.

All values are calibration-set operating points. Higher recall can increase false alarms; a lower false-positive rate can miss more defects. The historical 0.33 threshold is not a leakage-safe model-selection baseline.
06

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.

07

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.