resnet50.a1 in1k

提供商timm
分类image-classification
许可证apache-2.0
下载量5.1K
星标4

简介

ResNet50 是计算机视觉领域的经典基准模型,而 resnet50.a1 是由 timm 库提供的优化版本,在 ImageNet-1K 数据集上进行了精细调优。它通过残差连接解决了深层网络的梯度消失问题,在保持高效推理速度的同时,具备极强的特征提取能力。对于开发者而言,该模型是图像分类、目标检测或语义分割任务中最理想的预训练骨干网络(Backbone)。由于其生态极其成熟,无论是部署到端侧还是在服务器端进行迁移学习,都能快速上手且性能稳定。

核心亮点

  • CV 领域经典骨干网络,迁移学习首选
  • timm 库优化版本,预训练权重更鲁棒
  • 推理速度与精度平衡,适配多种硬件
  • 广泛用于图像分类及各类视觉下游任务

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("timm/resnet50.a1_in1k")
tokenizer = AutoTokenizer.from_pretrained("timm/resnet50.a1_in1k")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download timm/resnet50.a1_in1k

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download timm/resnet50.a1_in1k config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('timm/resnet50.a1_in1k')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/timm/resnet50.a1_in1k

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/timm/resnet50.a1_in1k

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('timm/resnet50.a1_in1k')
tokenizer = AutoTokenizer.from_pretrained('timm/resnet50.a1_in1k')

模型下载

我们推荐使用命令行或者 ModelScope SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 ModelScope:

操作指引
pip install modelscope

命令行下载

下载完整模型库

下载完整模型库
modelscope download --model timm/resnet50.a1_in1k

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)
modelscope download --model timm/resnet50.a1_in1k README.md --local_dir ./dir

更多更丰富的命令行下载选项,可参见具体文档

SDK 下载

SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('timm/resnet50.a1_in1k')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://www.modelscope.cn/timm/resnet50.a1_in1k.git

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/timm/resnet50.a1_in1k.git

ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。

Notebook 快速开发

下载并安装 ModelScope library

下载并安装 ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

模型加载和推理

模型加载和推理
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'timm/resnet50.a1_in1k')

完整文档

来源: HuggingFace

---
license: apache-2.0
library_name: timm
tags:

  • image-classification

  • timm

  • transformers

---

Model card for resnet50.a1_in1k

A ResNet-B image classification model.

This model features:
* ReLU activations
* single layer 7x7 convolution with pooling
* 1x1 convolution shortcut downsample

Trained on ImageNet-1k in timm using recipe template described below.

Recipe details:
* ResNet Strikes Back A1 recipe
* LAMB optimizer with BCE loss
* Cosine LR schedule with warmup

Model Details

  • Model Type: Image classification / feature backbone
  • Model Stats:
- Params (M): 25.6 - GMACs: 4.1 - Activations (M): 11.1 - Image size: train = 224 x 224, test = 288 x 288
  • Papers:
- ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476 - Deep Residual Learning for Image Recognition: https://arxiv.org/abs/1512.03385
  • Original: https://github.com/huggingface/pytorch-image-models

Model Usage

Image Classification

python
from urllib.request import urlopen
from PIL import Image
import timm
import torch

img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))

model = timm.create_model('resnet50.a1_in1k', pretrained=True)
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)) # unsqueeze single image into batch of 1

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

Feature Map Extraction

python
from urllib.request import urlopen
from PIL import Image
import timm

img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))

model = timm.create_model(
'resnet50.a1_in1k',
pretrained=True,
features_only=True,
)
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)) # 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, 112, 112])
# torch.Size([1, 256, 56, 56])
# torch.Size([1, 512, 28, 28])
# torch.Size([1, 1024, 14, 14])
# torch.Size([1, 2048, 7, 7])

print(o.shape)

Image Embeddings

python
from urllib.request import urlopen
from PIL import Image
import timm

img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))

model = timm.create_model(
'resnet50.a1_in1k',
pretrained=True,
num_classes=0, # remove classifier nn.Linear
)
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)) # output is (batch_size, num_features) shaped tensor

or equivalently (without needing to set num_classes=0)

output = model.forward_features(transforms(img).unsqueeze(0))

output is unpooled, a (1, 2048, 7, 7) shaped tensor

output = model.forward_head(output, pre_logits=True)

output is a (1, num_features) shaped tensor

Model Comparison

Explore the dataset and runtime metrics of this model in timm model results.

|model |img_size|top1 |top5 |param_count|gmacs|macts|img/sec|
|------------------------------------------|--------|-----|-----|-----------|-----|-----|-------|
|seresnextaa101d_32x8d.sw_in12k_ft_in1k_288|320 |86.72|98.17|93.6 |35.2 |69.7 |451 |
|seresnextaa101d_32x8d.sw_in12k_ft_in1k_288|288 |86.51|98.08|93.6 |28.5 |56.4 |560 |
|seresnextaa101d_32x8d.sw_in12k_ft_in1k|288 |86.49|98.03|93.6 |28.5 |56.4 |557 |
|seresnextaa101d_32x8d.sw_in12k_ft_in1k|224 |85.96|97.82|93.6 |17.2 |34.2 |923 |
|resnext101_32x32d.fb_wsl_ig1b_ft_in1k|224 |85.11|97.44|468.5 |87.3 |91.1 |254 |
|resnetrs420.tf_in1k|416 |85.0 |97.12|191.9 |108.4|213.8|134 |
|ecaresnet269d.ra2_in1k|352 |84.96|97.22|102.1 |50.2 |101.2|291 |
|ecaresnet269d.ra2_in1k|320 |84.73|97.18|102.1 |41.5 |83.7 |353 |
|resnetrs350.tf_in1k|384 |84.71|96.99|164.0 |77.6 |154.7|183 |
|seresnextaa101d_32x8d.ah_in1k|288 |84.57|97.08|93.6 |28.5 |56.4 |557 |
|resnetrs200.tf_in1k|320 |84.45|97.08|93.2 |31.5 |67.8 |446 |
|resnetrs270.tf_in1k|352 |84.43|96.97|129.9 |51.1 |105.5|280 |
|seresnext101d_32x8d.ah_in1k|288 |84.36|96.92|93.6 |27.6 |53.0 |595 |
|seresnet152d.ra2_in1k|320 |84.35|97.04|66.8 |24.1 |47.7 |610 |
|resnetrs350.tf_in1k|288 |84.3 |96.94|164.0 |43.7 |87.1 |333 |
|resnext101_32x8d.fb_swsl_ig1b_ft_in1k|224 |84.28|97.17|88.8 |16.5 |31.2 |1100 |
|resnetrs420.tf_in1k|320 |84.24|96.86|191.9 |64.2 |126.6|228 |
|seresnext101_32x8d.ah_in1k|288 |84.19|96.87|93.6 |27.2 |51.6 |613 |
|resnext101_32x16d.fb_wsl_ig1b_ft_in1k|224 |84.18|97.19|194.0 |36.3 |51.2 |581 |
|resnetaa101d.sw_in12k_ft_in1k|288 |84.11|97.11|44.6 |15.1 |29.0 |1144 |
|resnet200d.ra2_in1k|320 |83.97|96.82|64.7 |31.2 |67.3 |518 |
|resnetrs200.tf_in1k|256 |83.87|96.75|93.2 |20.2 |43.4 |692 |
|seresnextaa101d_32x8d.ah_in1k|224 |83.86|96.65|93.6 |17.2 |34.2 |923 |
|resnetrs152.tf_in1k|320 |83.72|96.61|86.6 |24.3 |48.1 |617 |
|seresnet152d.ra2_in1k|256 |83.69|96.78|66.8 |15.4 |30.6 |943 |
|seresnext101d_32x8d.ah_in1k|224 |83.68|96.61|93.6 |16.7 |32.0 |986 |
|resnet152d.ra2_in1k|320 |83.67|96.74|60.2 |24.1 |47.7 |706 |
|resnetrs270.tf_in1k|256 |83.59|96.61|129.9 |27.1 |55.8 |526 |
|seresnext101_32x8d.ah_in1k|224 |83.58|96.4 |93.6 |16.5 |31.2 |1013 |
|