Skip to content

Conversation

@rajeshgangireddy
Copy link
Contributor

📝 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:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔄 Refactor (non-breaking change which refactors the code base)
  • ⚡ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🚧 CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

For more information about code review checklists, see the Code Review Checklist.

alfieroddanintel and others added 2 commits December 4, 2025 16:50
* 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>
Copilot AI review requested due to automatic review settings December 4, 2025 16:44
Copy link
Contributor

Copilot AI left a 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.

Copilot AI review requested due to automatic review settings December 4, 2025 16:59
Copy link
Contributor

Copilot AI left a 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.

Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Copilot AI review requested due to automatic review settings December 5, 2025 22:40
Copy link
Contributor

Copilot AI left a 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>
Copilot AI review requested due to automatic review settings December 5, 2025 22:56
Copy link
Contributor

Copilot AI left a 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.

AlexanderBarabanov and others added 2 commits December 8, 2025 11:31
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Copilot AI review requested due to automatic review settings December 8, 2025 12:57
Copy link
Contributor

Copilot AI left a 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.

Copilot AI review requested due to automatic review settings December 8, 2025 14:34
Copy link
Contributor

Copilot AI left a 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 if batch_features is 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.

@rajeshgangireddy rajeshgangireddy changed the title feat(anomalydino): Introduces anomalydino with semgrep "fixes" feat(anomalydino): Introduces anomalydino with semgrep fixes Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants