HuggingFace镜像/deit_small_patch16_224.fb_in1k
模型介绍文件和版本分析
下载使用量0

deit_small_patch16_224.fb_in1k 模型卡片

一个 DeiT 图像分类模型。由论文作者在 ImageNet-1k 上训练。

模型详情

  • 模型类型: 图像分类 / 特征骨干网络
  • 模型统计信息:
    • 参数(M):22.1
    • GMACs:4.6
    • 激活值(M):11.9
    • 图像尺寸:224 x 224
  • 相关论文:
    • Training data-efficient image transformers & distillation through attention: https://arxiv.org/abs/2012.12877
  • 原始地址: https://github.com/facebookresearch/deit
  • 数据集: ImageNet-1k

模型用途

图像分类

import torch 
import torch_npu 
from torch_npu.contrib import transfer_to_npu

from PIL import Image
from openmind import is_torch_npu_available
import timm
import argparse

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default=None,
    )
    args = parser.parse_args()
    return args

if __name__ == "__main__":
    args = parse_args()
    model_path = args.model_name_or_path
    img_path = model_path + '/img/beignets-task-guide.png'
    img = Image.open(img_path)

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"

    model_name = 'deit_small_patch16_224.fb_in1k'
    checkpoint_path=model_path + '/pytorch_model.bin'
    model = timm.create_model(model_name, pretrained=False, checkpoint_path=checkpoint_path).to(device)
    model = model.eval()

    # get model specific transforms (normalization, resize)
    data_config = timm.data.resolve_model_data_config(model)
    transforms = timm.data.create_transform(**data_config, is_training=False)

    output = model(transforms(img).unsqueeze(0).to(device))  # unsqueeze single image into batch of 1
    img.close()

    top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
    print(top5_probabilities)
    print(top5_class_indices)

模型对比

在 timm 的 model results 中探索此模型的数据集和运行时指标。

引用

@InProceedings{pmlr-v139-touvron21a,
  title =     {Training data-efficient image transformers & distillation through attention},
  author =    {Touvron, Hugo and Cord, Matthieu and Douze, Matthijs and Massa, Francisco and Sablayrolles, Alexandre and Jegou, Herve},
  booktitle = {International Conference on Machine Learning},
  pages =     {10347--10357},
  year =      {2021},
  volume =    {139},
  month =     {July}
}
@misc{rw2019timm,
  author = {Ross Wightman},
  title = {PyTorch Image Models},
  year = {2019},
  publisher = {GitHub},
  journal = {GitHub repository},
  doi = {10.5281/zenodo.4414861},
  howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}