Repository navigation
feat(model): add UniADet for zero- and few-shot anomaly detection - #3947
rajeshgangireddy wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The report can accept CSV results from a mismatched run, verification claims conflict with final-source hashes, and DINOv3 initialization and CLIP feature projection lack targeted regression coverage.
4 open issues
What changed in this PR
Adds UniADet to Anomalib’s model registry for zero- and few-shot anomaly detection using frozen CLIP, DINOv2-R, and DINOv3 encoders with the existing Engine.
Changes:
- Adds encoder adapters, prototype heads, auxiliary loss, and example configuration.
- Extends quantization support and adds offline inference, export, data, and reporting tests.
- Adds documentation, licensing notices, and measured training, reproduction, and deployment artifacts, distinguishing author-head evaluation from independent training.
| File | Description |
|---|---|
uv.lock |
Aligns the minimum timm requirement. |
tools/uniadet/report.py |
Aggregates validated benchmark sweeps and paper comparisons. |
tools/uniadet/paper_results.csv |
Records published comparison values. |
tools/uniadet/author.py |
Downloads and converts authorized author heads. |
tools/uniadet/__init__.py |
Defines the reproduction-tools package. |
third-party-programs.txt |
Attributes VisA sample imagery. |
tests/unit/models/image/uniadet/test_report.py |
Tests aggregation and invalid-result rejection. |
tests/unit/models/image/uniadet/test_quantization.py |
Tests compression and accuracy-control behavior. |
tests/unit/models/image/uniadet/test_inference.py |
Tests Engine, checkpoint, and export agreement. |
tests/unit/models/image/uniadet/test_diagnosis.py |
Tests scoring diagnostics and protocol validation. |
tests/unit/models/image/uniadet/test_data.py |
Tests augmentation, calibration, and reference handling. |
tests/unit/models/image/uniadet/conftest.py |
Supplies a deterministic offline encoder. |
tests/integration/model/test_models.py |
Integrates UniADet into model lifecycle tests. |
src/anomalib/models/image/uniadet/loss.py |
Implements auxiliary classification and segmentation losses. |
src/anomalib/models/image/uniadet/head.py |
Implements multi-scale cosine prototype heads. |
src/anomalib/models/image/uniadet/backbones.py |
Adapts frozen encoders and author feature conventions. |
src/anomalib/models/image/uniadet/__init__.py |
Exports UniADet from its package. |
src/anomalib/models/image/__init__.py |
Registers UniADet among image models. |
src/anomalib/models/components/base/export_mixin/mixin.py |
Extends quantization options and validation outputs. |
src/anomalib/models/__init__.py |
Exposes UniADet through the public model API. |
results/UniADet/training/dinov3_visa/training.json |
Records DINOv3 training on VisA. |
results/UniADet/training/dinov3_mvtec/training.json |
Records DINOv3 training on MVTec AD. |
results/UniADet/training/dinov2_visa/training.json |
Records DINOv2 training on VisA. |
results/UniADet/training/dinov2_mvtec/training.json |
Records DINOv2 training on MVTec AD. |
results/UniADet/training/clip_visa/training.json |
Records CLIP training on VisA. |
results/UniADet/training/clip_mvtec/training.json |
Records CLIP training on MVTec AD. |
results/UniADet/training_summary.csv |
Consolidates training timings and provenance. |
results/UniADet/reproduction/verification.json |
Records reproduction verification claims and limitations. |
results/UniADet/reproduction/summary.json |
Summarizes author-head evaluation and deployment. |
results/UniADet/reproduction/quantization/weight_only_runtime_probe.json |
Records weight-compression runtime probes. |
results/UniADet/reproduction/quantization/author_weights_probe.json |
Compares author-graph weight-compression variants. |
results/UniADet/reproduction/quantization/author_smoothquant_probe.json |
Records SmoothQuant parameter probes. |
results/UniADet/reproduction/quantization/author_sigmoid_probe.json |
Measures error amplification through sigmoid scoring. |
results/UniADet/reproduction/quantization/activation_group_probe.json |
Isolates activation-quantization error sources. |
results/UniADet/reproduction/protocol.json |
Documents evaluation protocol and limitations. |
results/UniADet/reproduction/frozen_backbones.json |
Records backbone snapshots and checksums. |
results/UniADet/reproduction/clip_precision_deltas.csv |
Compares CLIP precision policies. |
results/UniADet/initial_recipe/training/dinov2_visa/training.json |
Preserves initial DINOv2 VisA training provenance. |
results/UniADet/initial_recipe/training/dinov2_mvtec/training.json |
Preserves initial DINOv2 MVTec training provenance. |
results/UniADet/initial_recipe/training/clip_visa/training.json |
Preserves initial CLIP VisA training provenance. |
results/UniADet/initial_recipe/training/clip_mvtec/training.json |
Preserves initial CLIP MVTec training provenance. |
results/UniADet/initial_recipe/smoke/quantization_dinov2/parity.json |
Records initial quantization smoke results. |
results/UniADet/initial_recipe/smoke/dinov3_visa/training.json |
Records a DINOv3 training smoke run. |
results/UniADet/initial_recipe/smoke/dinov2_visa/training.json |
Records a DINOv2 training smoke run. |
results/UniADet/initial_recipe/smoke/clip_visa/training.json |
Records a CLIP training smoke run. |
results/UniADet/initial_recipe/smoke/benchmark_dinov2/evaluation.json |
Records benchmark smoke-run configuration. |
results/UniADet/initial_recipe/smoke/benchmark_dinov2/categories.csv |
Preserves benchmark smoke measurements. |
results/UniADet/initial_recipe/sample_images.json |
Preserves initial sample-selection provenance. |
results/UniADet/initial_recipe/provenance.json |
Explains superseded recipe differences. |
results/UniADet/initial_recipe/diagnostics/metric_cashew/evaluation.json |
Records the initial cashew evaluation setup. |
results/UniADet/initial_recipe/diagnostics/metric_cashew/categories.csv |
Preserves initial cashew metrics. |
results/UniADet/initial_recipe/deployment/dinov2_mvtec_0_quantized_legacy/parity.json |
Preserves legacy deployment measurements. |
results/UniADet/diagnosis/training_resize_alignment.json |
Measures training interpolation differences. |
results/UniADet/diagnosis/training_convergence.json |
Records auxiliary training loss curves. |
results/UniADet/diagnosis/preprocessing.json |
Measures image-resizing differences. |
results/UniADet/diagnosis/paired_feature_normalization/summary.json |
Summarizes paired feature-normalization experiments. |
results/UniADet/diagnosis/paired_feature_normalization/categories.csv |
Records per-category normalization comparisons. |
results/UniADet/diagnosis/metric_harness.json |
Compares metric implementations on fixed cases. |
results/UniADet/diagnosis/dinov2_scoring/summary.json |
Summarizes scoring-component experiments. |
results/UniADet/diagnosis/dinov2_scoring/categories.csv |
Records per-category scoring variants. |
results/UniADet/diagnosis/dinov2_reference_sampling/summary.json |
Summarizes reference-sampling experiments. |
results/UniADet/diagnosis/dinov2_reference_sampling/categories.csv |
Records reference-sampling comparison metrics. |
results/UniADet/diagnosis/caa_alignment.json |
Records augmentation supervision checks. |
results/UniADet/diagnosis/augmentation_distribution.json |
Records augmentation frequencies and recipe differences. |
results/UniADet/deployment/dinov3_mvtec_4_activation/parity.json |
Records DINOv3 four-shot activation quantization. |
results/UniADet/deployment/dinov3_mvtec_0_activation/parity.json |
Records DINOv3 zero-shot activation quantization. |
results/UniADet/deployment/dinov2_mvtec_4_activation/ptq_diagnosis.json |
Investigates DINOv2 quantization error sources. |
results/UniADet/deployment/dinov2_mvtec_4_activation/parity.json |
Records DINOv2 four-shot activation quantization. |
results/UniADet/deployment/dinov2_mvtec_0_activation/ptq.json |
Records DINOv2 zero-shot post-training quantization. |
results/UniADet/deployment/clip_mvtec_4_activation/parity.json |
Records CLIP four-shot activation quantization. |
results/UniADet/deployment/clip_mvtec_0_activation/parity.json |
Records CLIP zero-shot activation quantization. |
results/UniADet/activation_accuracy_control.json |
Records auxiliary-domain accuracy-control measurements. |
pyproject.toml |
Requires timm 1.0.20 or later. |
examples/configs/model/uniadet.yaml |
Adds a UniADet configuration template. |
docs/source/markdown/guides/reference/models/image/uniadet.md |
Documents usage, benchmarks, deployment, and licensing. |
docs/source/markdown/guides/reference/models/image/index.md |
Adds UniADet to model documentation navigation. |
docs/source/images/uniadet/results/LICENSE |
Documents sample-panel attribution and licensing. |
docs/source/images/uniadet/architecture.svg |
Illustrates the detector architecture. |
CHANGELOG.md |
Announces UniADet under Unreleased. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Unchecked CSV identifiers can misattribute measurements to the wrong run, while INT8_ACQ output-based ranking can produce undefined rollback scores for matching all-zero predictions and labels.
5 open issues
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The shared exporter forces ACQ into output-based ranking that can divide by zero on normal predictions, producing NaN/Inf and undefined rollback ordering across models.
7 open issues
Reject category symlinks that escape the dataset root · New Use zero-safe rollback ranking for all-zero outputs Validate CSV run identity against the manifest Reject head weights that do not match the manifest checksum · New Reconcile verification hashes with final source Test CLIP feature projection in offline inference Add regression coverage for DINOv3 author initialization
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The documented image-size override changes preprocessing without updating the backbone’s fixed resolution and patch grid, causing non-native inputs to fail.
8 open issues
Use zero-safe rollback ranking for all-zero outputs Validate CSV run identity against the manifest Reject or propagate unsupported image_size overrides · New Reconcile verification hashes with final source Commit benchmark artifacts and update evidence links · New Add offline tests for CLIP and DINOv3 wrapper adaptations · New Test CLIP feature projection in offline inference Add regression coverage for DINOv3 author initialization
2 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Datamodule reference paths lack root-confinement validation, allowing symlinked external images into the saved/exported memory bank, and CLIP/DINOv3 adapter branches lack offline regression coverage.
9 open issues
Use zero-safe rollback ranking for all-zero outputs Validate CSV run identity against the manifest Confine datamodule reference paths to the dataset root · New Reject or propagate unsupported image_size overrides Reconcile verification hashes with final source Add offline tests for CLIP and DINOv3 wrapper adaptations Commit benchmark artifacts and update evidence links Test CLIP feature projection in offline inference Add regression coverage for DINOv3 author initialization
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The published AUROC and parity claims lack committed per-category/per-seed measurements and evaluation configuration, leaving them unauditable and unreproducible from the repository.
1 open issue
9 resolved since last review
Use zero-safe rollback ranking for all-zero outputs Validate CSV run identity against the manifest Confine datamodule reference paths to the dataset root Reject or propagate unsupported image_size overrides Reconcile verification hashes with final source Add offline tests for CLIP and DINOv3 wrapper adaptations Commit benchmark artifacts and update evidence links Test CLIP feature projection in offline inference Add regression coverage for DINOv3 author initialization
Review effort: Balanced
Integrate the authors' pretrained detection heads with CLIP, DINOv2-R, and DINOv3, including few-shot reference memory and deployment support. Keep raw model scores and support metric-based OpenVINO quantization rollback. Add offline tests, configuration, and documentation. Signed-off-by: Rajesh Gangireddy <rajesh.gangireddy@intel.com>
1a5cca5 to
972c08c
Compare
Signed-off-by: Rajesh Gangireddy <rajesh.gangireddy@intel.com>
| """Collect few-shot references before prediction.""" | ||
| self._initialize_references() | ||
|
|
||
| def forward(self, batch: torch.Tensor, *args, **kwargs) -> InferenceBatch: |



📝 Description
PostProcessornow applies calibrated thresholds when normalization is disabled (previously a fixed 0.5), and INT8_ACQ export ranks rollback with the configured validation metric.✨ Changes
Select what type of change your PR is:
✅ Checklist
Before you submit your pull request, please make sure you have completed the following steps:
Validation
Paper / Anomalib (%) with the authors' pretrained heads and evaluation protocol. AP is area under the precision–recall curve.
1- and 2-shot results
Engine.teston MVTec AD matches the author-protocol replay within 0.044 percentage points of mean AUROC.MVTec AD: author-protocol replay / Engine AUROC (%) at seed 10
OpenVINO weight-only INT8 and PTQ reached maximum map errors of 0.066 and 0.39, respectively (limit 0.05).
ACQ reached 0.38 and flipped 2 of 18 labels with either batch size.
Sample anomaly maps
VisA, DINOv2-R at four shots with the authors' MVTec AD head. Left to right: input, ground truth, anomaly map, predicted mask.
Adapted from VisA, Zou et al. (2022), CC BY 4.0.
For more information about code review checklists, see the Code Review Checklist.