DINOv2
DINOv2_base
¶
DINOv2_base(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 base model.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
768 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
12 |
num_heads |
int
|
12 |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_base_reg
¶
DINOv2_base_reg(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 base model with register.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision and [arXiv:2309.16588] Vision Transformers Need Registers for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
768 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
12 |
num_heads |
int
|
12 |
num_registers |
int
|
4 |
interpolate_antialias |
bool
|
True |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_giant
¶
DINOv2_giant(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 giant model.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
1536 |
feedforward_dim |
int
|
4096 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
40 |
num_heads |
int
|
24 |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_giant_reg
¶
DINOv2_giant_reg(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 giant model with register.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision and [arXiv:2309.16588] Vision Transformers Need Registers
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
1536 |
feedforward_dim |
int
|
4096 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
40 |
num_heads |
int
|
24 |
num_registers |
int
|
4 |
interpolate_antialias |
bool
|
True |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_large
¶
DINOv2_large(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 large model.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
1024 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
24 |
num_heads |
int
|
16 |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_large_reg
¶
DINOv2_large_reg(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 large model with register.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision and [arXiv:2309.16588] Vision Transformers Need Registers for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
1024 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
24 |
num_heads |
int
|
16 |
num_registers |
int
|
4 |
interpolate_antialias |
bool
|
True |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_small
¶
DINOv2_small(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 small model.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
384 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
12 |
num_heads |
int
|
6 |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
DINOv2_small_reg
¶
DINOv2_small_reg(
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: ViT
DINOv2 small model with register.
See [arXiv:2304.07193] DINOv2: Learning Robust Visual Features without Supervision and [arXiv:2309.16588] Vision Transformers Need Registers for more details.
Attributes:
Name | Type | Description |
---|---|---|
embedding_dim |
int
|
384 |
patch_size |
int
|
14 |
image_size |
int
|
518 |
num_layers |
int
|
12 |
num_heads |
int
|
6 |
num_registers |
int
|
4 |
interpolate_antialias |
bool
|
True |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/dinov2.py
ViT
¶
ViT(
embedding_dim: int = 768,
patch_size: int = 16,
image_size: int = 224,
num_layers: int = 12,
num_heads: int = 12,
norm_eps: float = 1e-06,
mlp_ratio: int = 4,
num_registers: int = 0,
activation: Activation = fl.GeLU(),
feedforward_dim: int | None = None,
interpolate_antialias: bool = False,
interpolate_mode: str = "bicubic",
device: device | str | None = None,
dtype: dtype | None = None,
)
Bases: Chain
Vision Transformer (ViT) model.
See [arXiv:2010.11929] An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale for more details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding_dim |
int
|
The dimension of the embedding. |
768
|
patch_size |
int
|
The size of the patches. |
16
|
image_size |
int
|
The size of the input image. |
224
|
num_layers |
int
|
The number of layers. |
12
|
num_heads |
int
|
The number of heads. |
12
|
norm_eps |
float
|
The epsilon value for normalization. |
1e-06
|
mlp_ratio |
int
|
The ratio for the multi-layer perceptron (MLP). |
4
|
num_registers |
int
|
The number of registers. |
0
|
activation |
Activation
|
The activation function. |
GeLU()
|
feedforward_dim |
int | None
|
The dimension of the feedforward layer. |
None
|
interpolate_antialias |
bool
|
Whether to use antialiasing for interpolation. |
False
|
interpolate_mode |
str
|
The interpolation mode. |
'bicubic'
|
device |
device | str | None
|
The PyTorch device to use. |
None
|
dtype |
dtype | None
|
The PyTorch data type to use. |
None
|
Source code in src/refiners/foundationals/dinov2/vit.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
preprocess
¶
preprocess(img: Image, dim: int = 224) -> Tensor
Preprocess an image for use with DINOv2. Uses ImageNet mean and standard deviation. Note that this only resizes and normalizes the image, there is no center crop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
Image
|
The image. |
required |
dim |
int
|
The square dimension to resize the image. Typically 224 or 518. |
224
|
Returns:
Type | Description |
---|---|
Tensor
|
A float32 tensor with shape (3, dim, dim). |