Skip to content

Commit 7936d17

Browse files
update docstrings
1 parent dc908f1 commit 7936d17

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

src/anomalib/models/components/dinov2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
77
References:
88
https://github.com/facebookresearch/dinov2/blob/main/dinov2/
9+
10+
Classes:
11+
DinoVisionTransformer: DINOv2 implementation.
12+
DinoV2Loader: Loader class to support downloading and loading weights.
913
"""
1014

1115
# vision transformer

src/anomalib/models/components/dinov2/dinov2_loader.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
"""Loader for DINOv2 Vision Transformer models.
4+
"""Loading pre-trained DINOv2 Vision Transformer models.
55
6-
This module provides a simple interface for loading pre-trained DINOv2 Vision Transformer models for the
7-
Dinomaly anomaly detection framework.
6+
This module provides the :class:`DinoV2Loader` class for constructing and loading
7+
pre-trained DINOv2 Vision Transformer models used in the Dinomaly anomaly detection
8+
framework. It supports both standard DINOv2 models and register-token variants, and
9+
allows custom Vision Transformer factories to be supplied.
810
911
Example:
10-
model = DinoV2Loader.from_name("dinov2_vit_base_14")
11-
model = DinoV2Loader.from_name("vit_base_14")
12-
model = DinoV2Loader(vit_factory=my_custom_vit_module).load("dinov2reg_vit_base_14")
12+
>>> from anomalib.models.components.dinov2 import DinoV2Loader
13+
>>> loader = DinoV2Loader()
14+
>>> model = loader.load("dinov2_vit_base_14")
15+
>>> model = loader.load("vit_base_14")
16+
>>> custom_loader = DinoV2Loader(vit_factory=my_custom_vit_module)
17+
>>> model = custom_loader.load("dinov2reg_vit_base_14")
18+
19+
The DINOv2 loader handles:
20+
21+
- Parsing model names and validating architecture types
22+
- Constructing the appropriate Vision Transformer model
23+
- Locating or downloading the corresponding pre-trained weights
24+
- Supporting custom ViT implementations via a pluggable factory
25+
26+
This enables a simple, unified interface for accessing DINOv2-based backbones in
27+
downstream anomaly detection tasks.
1328
"""
1429

1530
from __future__ import annotations

src/anomalib/models/components/dinov2/layers/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44
"""Layers needed to build DINOv2.
55
66
References:
7-
https://github.com/facebookresearch/dinov2/blob/main/dinov2/layers/__init__.py
7+
https://github.com/facebookresearch/dinov2/blob/main/dinov2/layers/__init__.py
8+
9+
Classes:
10+
Attention: Standard multi-head self-attention layer used in Vision Transformers.
11+
MemEffAttention: Memory-efficient variant of multi-head attention optimized for large inputs.
12+
Block: Transformer block consisting of attention, MLP, residuals, and normalization layers.
13+
CausalAttentionBlock: Transformer block with causal (autoregressive) attention masking.
14+
DINOHead: Projection head used in DINO/DINOv2 for self-supervised feature learning.
15+
DropPath: Implements stochastic depth, randomly dropping residual connections during training.
16+
LayerScale: Applies learnable per-channel scaling to stabilize deep transformer training.
17+
Mlp: Feedforward network used inside Vision Transformer blocks.
18+
PatchEmbed: Converts image patches into token embeddings for Vision Transformer inputs.
19+
SwiGLUFFN: SwiGLU-based feedforward network used in DINOv2 for improved expressiveness.
20+
SwiGLUFFNAligned: Variant of SwiGLUFFN with tensor alignment optimizations.
21+
SwiGLUFFNFused: Fused implementation of SwiGLUFFN for improved computational efficiency.
822
"""
923

1024
from .attention import Attention, MemEffAttention

0 commit comments

Comments
 (0)