You can quickly load any of the four DINOv2 Vision Transformer models using torch.hub.load. The available models include ViT-S, ViT-B, ViT-L (distilled from ViT-g), and ViT-g (trained from scratch).
Note that the models use a patch size of 14. If you provide an image whose dimensions are not multiples of 14, the model will automatically crop the image to the closest smaller multiple of the patch size.
import torch
dinov2_vits14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14')
dinov2_vitb14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14')
dinov2_vitl14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14')
dinov2_vitg14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14')