模型:

frgfm/resnet34

英文

ResNet-34模型

预训练于 ImageNette 。ResNet架构是在 this paper 中引入的。

模型描述

作者的核心思想是通过添加跳跃连接来帮助梯度在多个层之间传播。

安装

前提条件

需要Python 3.6(或更高版本)和 pip / conda 来安装Holocron。

最新稳定版本

您可以使用 pypi 安装软件包的最新稳定版本,如下所示:

pip install pylocron

或者使用 conda :

conda install -c frgfm pylocron

开发者模式

或者,如果您希望使用项目的最新功能,但这些功能尚未在发布版本中提供,您可以从源代码(先安装 Git )安装软件包:

git clone https://github.com/frgfm/Holocron.git
pip install -e Holocron/.

使用说明

from PIL import Image
from torchvision.transforms import Compose, ConvertImageDtype, Normalize, PILToTensor, Resize
from torchvision.transforms.functional import InterpolationMode
from holocron.models import model_from_hf_hub

model = model_from_hf_hub("frgfm/resnet34").eval()

img = Image.open(path_to_an_image).convert("RGB")

# Preprocessing
config = model.default_cfg
transform = Compose([
    Resize(config['input_shape'][1:], interpolation=InterpolationMode.BILINEAR),
    PILToTensor(),
    ConvertImageDtype(torch.float32),
    Normalize(config['mean'], config['std'])
])

input_tensor = transform(img).unsqueeze(0)

# Inference
with torch.inference_mode():
    output = model(input_tensor)
probs = output.squeeze(0).softmax(dim=0)

引用

原始论文

@article{DBLP:journals/corr/HeZRS15,
  author    = {Kaiming He and
               Xiangyu Zhang and
               Shaoqing Ren and
               Jian Sun},
  title     = {Deep Residual Learning for Image Recognition},
  journal   = {CoRR},
  volume    = {abs/1512.03385},
  year      = {2015},
  url       = {http://arxiv.org/abs/1512.03385},
  eprinttype = {arXiv},
  eprint    = {1512.03385},
  timestamp = {Wed, 17 Apr 2019 17:23:45 +0200},
  biburl    = {https://dblp.org/rec/journals/corr/HeZRS15.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}

此实现的来源

@software{Fernandez_Holocron_2020,
author = {Fernandez, François-Guillaume},
month = {5},
title = {{Holocron}},
url = {https://github.com/frgfm/Holocron},
year = {2020}
}