-
Notifications
You must be signed in to change notification settings - Fork 841
feat(model): add DINOv2 official implementation and AnomalyDINO #3105
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?
feat(model): add DINOv2 official implementation and AnomalyDINO #3105
Conversation
93df141 to
8e93176
Compare
3d29eab to
27e0d91
Compare
samet-akcay
left a comment
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.
Clean! Thanks a lot for the contribution!
Only have super minor comments..
f720362 to
a608e5e
Compare
f407c85 to
519c725
Compare
| self._download_weights(model_type, architecture, patch_size) | ||
|
|
||
| # Using weights_only=True for safety mitigation (see Anomalib PR #2729) | ||
| state_dict = torch.load(weight_path, map_location="cpu", weights_only=True) # nosec B614 |
Check failure
Code scanning / Semgrep OSS
Semgrep Finding: trailofbits.python.pickles-in-pytorch.pickles-in-pytorch Error
| urlretrieve( # noqa: S310 # nosec B310 | ||
| url=url, | ||
| filename=weight_path, | ||
| reporthook=progress_bar.update_to, | ||
| ) |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: python.lang.security.audit.dynamic-urllib-use-detected.dynamic-urllib-use-detected Warning
| nn.Parameter(torch.zeros(1, num_register_tokens, embed_dim)) if num_register_tokens else None | ||
| ) | ||
|
|
||
| dpr = [drop_path_rate] * depth if drop_path_uniform else np.linspace(0, drop_path_rate, depth).tolist() |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: trailofbits.python.numpy-in-pytorch-modules.numpy-in-pytorch-modules Warning
| nn.Parameter(torch.zeros(1, num_register_tokens, embed_dim)) if num_register_tokens else None | ||
| ) | ||
|
|
||
| dpr = [drop_path_rate] * depth if drop_path_uniform else np.linspace(0, drop_path_rate, depth).tolist() |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: trailofbits.python.numpy-in-pytorch-modules.numpy-in-pytorch-modules Warning
7936d17 to
3419086
Compare
samet-akcay
left a comment
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.
thanks, some super minor comments
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
…mprove comments Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
…t to matmul, work with half tensors Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
…r generating dinov2. update anomaly_dino to use factory method Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
…rom dinomaly Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
…tform#3108) * Update xpu.py regarind PR open-edge-platform#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>
Signed-off-by: Alfie Roddan <228966941+alfieroddanintel@users.noreply.github.com>
3a418ae to
0788a32
Compare
📝 Description
Implementation of DINOv2
The current Dinomaly implementation contains some custom layers like:
anomalib/src/anomalib/models/image/dinomaly/components/vision_transformer.py
Line 166 in f006ab7
I have used the official implementation of DINOv2 and implemented it without xformers.
I have placed this in
from anomalib.models.components.dinov2 import vision_transformer. It produces the exact same output as the original:DINOv2 Loader
I refactored the DINOv2 loader to be a factory method to facilitate loading weights for DINOv2 for mulitple implementations. I planned to use it as following:
Hopefully this is allowed with semgrep and bandit.
Implementation of AnomalyDINO.
AnomalyDINO uses DINOv2-Small to boost memory-bank models scores for few-shot models. The paper itself uses custom augmentations and masking depending on the category type. This is optional in my implementation.
To replicate Table 12. of the paper (full-shot with masking on MVTecAD) please run:
📄 Reported Results from the Paper
Our Implementation
We don't use Faiss.
📊 Category Metrics (%)
📈 Mean Metrics (%)
✨ 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.