-
Notifications
You must be signed in to change notification settings - Fork 846
feat(anomalydino): Introduces anomalydino with semgrep fixes #3193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* init commit Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * add cdist instead of euclidean distance, divide by 2 for cosine and improve comments Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * remove redundant euclidean distance Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * Add AnomalyDINO to model list. Also alphabetically re-order some models Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * add precision modifier Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * remove fit comments. small typo of shape dimensions Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * update docs for anomaly dino Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * cleanup docstrings Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * add unit tests for anomalydino. change distance computation from cdist to matmul, work with half tensors Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * add vit/dino implementation (no xformers). implement factory class for generating dinov2. update anomaly_dino to use factory method Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * change dinov2loader to factory method, remove duplicated components from dinomaly Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * add from_name back Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * add tests for vit and dinov2loader Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * update docstrings Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * fix(accelerator): Adding name method in XPUAccelerator (#3108) * Update xpu.py regarind PR #3092 Added the name method to fix an issue related to a newly added feature in lightning 2.5.6 Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> * Update xpu.py Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> * Update xpu.py Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> * Update xpu.py with docstring Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> * Update xpu.py with correct docstring Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> * added name method for XPUAccelerator Signed-off-by: waschsalz <niclas.zschach@icloud.com> --------- Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> Signed-off-by: waschsalz <niclas.zschach@icloud.com> Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * change licesning with meta. Tensor is torch.Tensor. remove __future__. Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> * Update src/anomalib/models/components/dinov2/layers/block.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/attention.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/dino_head.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/drop_path.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/layer_scale.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/mlp.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/patch_embed.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/layers/swiglu_ffn.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> * Update src/anomalib/models/components/dinov2/vision_transformer.py Signed-off-by: Samet Akcay <smt.akcay@gmail.com> --------- Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com> Signed-off-by: Niclas <152474825+waschsalz@users.noreply.github.com> Signed-off-by: waschsalz <niclas.zschach@icloud.com> Signed-off-by: Samet Akcay <smt.akcay@gmail.com> Co-authored-by: Niclas <152474825+waschsalz@users.noreply.github.com> Co-authored-by: Samet Akcay <smt.akcay@gmail.com> Co-authored-by: Samet Akcay <samet.akcay@intel.com> Co-authored-by: Rajesh Gangireddy <rajesh.gangireddy@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces the AnomalyDINO model for anomaly detection using DINOv2 vision transformers. The implementation refactors shared DINOv2 components into a common anomalib.models.components.dinov2 module that can be used by both AnomalyDINO and Dinomaly models. Semgrep exceptions are applied to allow safe model weight loading with weights_only=True.
Key Changes:
- Introduces AnomalyDINO model with memory-bank-based anomaly detection
- Refactors DINOv2 vision transformer and loader components into shared components module
- Migrates Dinomaly to use the new shared DINOv2 components
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/anomalib/models/image/anomaly_dino/torch_model.py |
Core PyTorch implementation of AnomalyDINO with feature extraction and kNN-based scoring |
src/anomalib/models/image/anomaly_dino/lightning_model.py |
Lightning wrapper for AnomalyDINO training and inference |
src/anomalib/models/components/dinov2/vision_transformer.py |
Shared DINOv2 vision transformer implementation |
src/anomalib/models/components/dinov2/dinov2_loader.py |
Shared loader for DINOv2 pretrained weights |
src/anomalib/models/components/dinov2/layers/ |
Shared DINOv2 layer components (attention, blocks, MLP, etc.) |
src/anomalib/models/image/dinomaly/torch_model.py |
Updated to use shared DINOv2 loader |
src/anomalib/models/image/dinomaly/components/ |
Removed duplicated DINOv2 loader and layers, now imports from shared components |
tests/unit/models/image/anomaly_dino/test_torch_model.py |
Unit tests for AnomalyDINO torch model |
tests/unit/models/components/dinov2/ |
Unit tests for shared DINOv2 components |
examples/configs/model/anomaly_dino.yaml |
Configuration example for AnomalyDINO |
docs/source/markdown/guides/reference/models/image/anomaly_dino.md |
Documentation for AnomalyDINO model |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 31 out of 31 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
src/anomalib/models/image/anomaly_dino/torch_model.py:1
- Corrected spelling of 'worse' to 'worst'.
# Copyright (C) 2025 Intel Corporation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 32 out of 32 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
src/anomalib/models/image/anomaly_dino/torch_model.py:1
- The
.astype(np.float32)cast in line 161 is likely unnecessary ifbatch_featuresis already float32, which adds overhead in a loop. Consider checking the dtype once before the loop or removing the cast if the input dtype is guaranteed.
# Copyright (C) 2025 Intel Corporation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…s and improve error message formatting
📝 Description
AnomalyDino implemented by @alfieroddanintel at : #3105
However, semgrep was failing even after following the safe way of loading models.
Therefore, we apply semgrep exception on top.
✨ 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:
For more information about code review checklists, see the Code Review Checklist.