opensi·si

timm/models/deit.py ·

DeiT

Category: ViT · Code: timm/models/deit.py · Architectures: 16 · Pretrained weights: 24 (24 with ImageNet-1k results)

Data-efficient Image Transformers (DeiT) are Vision Transformers trained on ImageNet-1k only, optionally with a distillation token that learns from a CNN teacher. DeiT III models are trained with an improved recipe.

Papers

  • Training data-efficient image transformers & distillation through attention
  • DeiT III: Revenge of the ViT

Usage

See the Quickstart for loading pretrained weights, image preprocessing and fine-tuning, and Feature Extraction for using the models as backbones.

>>> import timm
>>> model = timm.create_model('deit_small_distilled_patch16_224.fb_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)

Model API support

Feature VisionTransformer VisionTransformerDistilled
features_only=True feature maps ✓ (strides 16, 16, 16) ✓ (strides 16, 16, 16)
forward_intermediates() ✓ ✓
prune_intermediate_layers() ✓ ✓
Any input size, no changes needed ✗ ✗
set_input_size() ✓ ✓
dynamic_img_size=True ✓ ✓
set_grad_checkpointing() ✓ ✓
Layer-wise LR decay (group_matcher()) ✓ ✓
reset_classifier() ✓ ✓

✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input size). Checked by running each feature on a randomly initialized model (VisionTransformer with deit_tiny_patch16_224 at 224, VisionTransformerDistilled with deit_tiny_distilled_patch16_224 at 224), other architectures of the same class are expected to behave the same. See the Model API page for details.

Architectures

표 (17행)
Architecture Class Params (M) GMACs Input size Pretrained weights
deit3_base_patch16_224 VisionTransformer 86.59 17.58 224 2
deit3_base_patch16_384 VisionTransformer 86.88 55.54 384 2
deit3_huge_patch14_224 VisionTransformer 632.13 167.40 224 2
deit3_large_patch16_224 VisionTransformer 304.37 61.60 224 2
deit3_large_patch16_384 VisionTransformer 304.76 191.21 384 2
deit3_medium_patch16_224 VisionTransformer 38.85 8.00 224 2
deit3_small_patch16_224 VisionTransformer 22.06 4.61 224 2
deit3_small_patch16_384 VisionTransformer 22.21 15.52 384 2
deit_base_distilled_patch16_224 VisionTransformerDistilled 87.34 17.68 224 1
deit_base_distilled_patch16_384 VisionTransformerDistilled 87.63 55.65 384 1
deit_base_patch16_224 VisionTransformer 86.57 17.58 224 1
deit_base_patch16_384 VisionTransformer 86.86 55.54 384 1
deit_small_distilled_patch16_224 VisionTransformerDistilled 22.44 4.63 224 1
deit_small_patch16_224 VisionTransformer 22.05 4.61 224 1
deit_tiny_distilled_patch16_224 VisionTransformerDistilled 5.91 1.27 224 1
deit_tiny_patch16_224 VisionTransformer 5.72 1.26 224 1

GMACs and parameter counts are for the default input size and classifier of each architecture, from the benchmark results.

Pretrained weights

Top-1 is ImageNet-1k validation accuracy from results-imagenet.csv at the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the size of the pretrained classifier, none for weights without one.

표 (25행)
Weight Input size Top-1 (%) Eval size Classes License Hub
deit3_base_patch16_224.fb_in1k 224 83.800 224 1000 apache-2.0 timm
deit3_base_patch16_224.fb_in22k_ft_in1k 224 85.728 224 1000 apache-2.0 timm
deit3_base_patch16_384.fb_in1k 384 85.088 384 1000 apache-2.0 timm
deit3_base_patch16_384.fb_in22k_ft_in1k 384 86.742 384 1000 apache-2.0 timm
deit3_huge_patch14_224.fb_in1k 224 85.204 224 1000 apache-2.0 timm
deit3_huge_patch14_224.fb_in22k_ft_in1k 224 87.180 224 1000 apache-2.0 timm
deit3_large_patch16_224.fb_in1k 224 84.772 224 1000 apache-2.0 timm
deit3_large_patch16_224.fb_in22k_ft_in1k 224 86.990 224 1000 apache-2.0 timm
deit3_large_patch16_384.fb_in1k 384 85.820 384 1000 apache-2.0 timm
deit3_large_patch16_384.fb_in22k_ft_in1k 384 87.736 384 1000 apache-2.0 timm
deit3_medium_patch16_224.fb_in1k 224 83.090 224 1000 apache-2.0 timm
deit3_medium_patch16_224.fb_in22k_ft_in1k 224 84.550 224 1000 apache-2.0 timm
deit3_small_patch16_224.fb_in1k 224 81.382 224 1000 apache-2.0 timm
deit3_small_patch16_224.fb_in22k_ft_in1k 224 83.082 224 1000 apache-2.0 timm
deit3_small_patch16_384.fb_in1k 384 83.432 384 1000 apache-2.0 timm
deit3_small_patch16_384.fb_in22k_ft_in1k 384 84.846 384 1000 apache-2.0 timm
deit_base_distilled_patch16_224.fb_in1k 224 83.384 224 1000 apache-2.0 timm
deit_base_distilled_patch16_384.fb_in1k 384 85.438 384 1000 apache-2.0 timm
deit_base_patch16_224.fb_in1k 224 81.980 224 1000 apache-2.0 timm
deit_base_patch16_384.fb_in1k 384 83.108 384 1000 apache-2.0 timm
deit_small_distilled_patch16_224.fb_in1k 224 81.204 224 1000 apache-2.0 timm
deit_small_patch16_224.fb_in1k 224 79.856 224 1000 apache-2.0 timm
deit_tiny_distilled_patch16_224.fb_in1k 224 74.538 224 1000 apache-2.0 timm
deit_tiny_patch16_224.fb_in1k 224 72.190 224 1000 apache-2.0 timm

Source and license

Source: timm documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.