HuggingFace镜像/inception_resnet_v2.tf_ens_adv_in1k
模型介绍文件和版本分析

inception_resnet_v2.tf_ens_adv_in1k 模型卡片

一个 Inception-ResNet-v2 图像分类模型。由论文作者在 ImageNet-1k 上进行(集成)对抗训练。由 Ross Wightman 从 Tensorflow 移植而来。

模型详情

  • 模型类型: 图像分类 / 特征骨干网络
  • 模型统计信息:
    • 参数(M):55.8
    • GMACs:13.2
    • 激活值(M):25.1
    • 图像尺寸:299 x 299
  • 相关论文:
    • https://arxiv.org/abs/1602.07261: https://arxiv.org/abs/1602.07261
    • 对抗攻击与防御竞赛:https://arxiv.org/abs/1804.00097
  • 原始版本: https://github.com/tensorflow/models
  • 数据集: ImageNet-1k

模型使用

特征图提取

from PIL import Image
import timm
from timm.models.efficientnet import _cfg
from openmind import is_torch_npu_available
import torch_npu
import torch
import argparse
from openmind_hub import snapshot_download

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

def parse_args():
        parser = argparse.ArgumentParser()
        parser.add_argument( "--model_name_or_path", type=str, default="inception_resnet_v2.tf_ens_adv_in1k", )
        args = parser.parse_args()
        return args
args = parse_args()

if args.model_name_or_path:
	model_path = args.model_name_or_path
else:
	model_path = snapshot_download(
		"CICC/inception_resnet_v2.tf_ens_adv_in1k",
		revision="main",
		resume_download=True,
		ignore_patterns=["*.h5", "*.ot", "	*.msgpack"]
	)
# load tokenizer
img = Image.open('./beignets-task-guide.png')

config = _cfg(url='', file='model.safetensors')
model = timm.create_model("inception_resnet_v2.tf_ens_adv_in1k", pretrained=True, pretrained_cfg=config).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).npu())  # unsqueeze single image into batch of 1

for o in output:
    # print shape of each feature map in output
    # e.g.:
    #  torch.Size([1, 64, 147, 147])
    #  torch.Size([1, 192, 71, 71])
    #  torch.Size([1, 288, 35, 35])
    #  torch.Size([1, 768, 17, 17])
    #  torch.Size([1, 2048, 8, 8])

    print(o.shape)

模型对比

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

引用

@article{Szegedy2016Inceptionv4IA,
  title={Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning},
  author={Christian Szegedy and Sergey Ioffe and Vincent Vanhoucke and Alexander A. Alemi},
  journal={ArXiv},
  year={2016},
  volume={abs/1602.07261}
}
@article{Kurakin2018AdversarialAA,
  title={Adversarial Attacks and Defences Competition},
  author={Alexey Kurakin and Ian J. Goodfellow and Samy Bengio and Yinpeng Dong and Fangzhou Liao and Ming Liang and Tianyu Pang and Jun Zhu and Xiaolin Hu and Cihang Xie and Jianyu Wang and Zhishuai Zhang and Zhou Ren and Alan Loddon Yuille and Sangxia Huang and Yao Zhao and Yuzhe Zhao and Zhonglin Han and Junjiajia Long and Yerkebulan Berdibekov and Takuya Akiba and Seiya Tokui and Motoki Abe},
  journal={ArXiv},
  year={2018},
  volume={abs/1804.00097}
}
下载使用量0