可用于图像分类任务及特征提取。这是一个 DeiT-III 图像分类模型,在 ImageNet-22k 预训练并在 ImageNet-1k 微调,支持 NPU 设备,具有 22.1M 参数和 4.6 GMACs 计算量。【此简介由AI生成】
以下内容由 AI 翻译,如有问题请 点此提交 issue 反馈
license: apache-2.0 pipeline_tag: image-classification frameworks:
- PyTorch language:
- en library_name: openmind hardwares:
- NPU
deit3_small_patch16_224.fb_in22k_ft_in1k 模型卡片
一个 DeiT-III 图像分类模型。由论文作者在 ImageNet-22k 上进行预训练,并在 ImageNet-1k 上进行微调。
模型详情
- 模型类型: 图像分类 / 特征骨干网络
- 模型统计:
- 参数(M):22.1
- GMACs:4.6
- 激活值(M):11.9
- 图像尺寸:224 x 224
- 相关论文:
- DeiT III: Revenge of the ViT: https://arxiv.org/abs/2204.07118
- 原始来源: https://github.com/facebookresearch/deit
- 数据集: ImageNet-1k
- 预训练数据集: ImageNet-22k
模型使用
图像分类
import torch
import timm
import argparse
from PIL import Image
from openmind import is_torch_npu_available
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 = 'deit3_small_patch16_224.fb_in22k_ft_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 的模型结果中探索此模型的数据集和运行时指标。
引用
@article{Touvron2022DeiTIR,
title={DeiT III: Revenge of the ViT},
author={Hugo Touvron and Matthieu Cord and Herve Jegou},
journal={arXiv preprint arXiv:2204.07118},
year={2022},
}
@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}}
}