ResNet model pre-trained on ImageNet-1k at resolution 224x224. It was introduced in the paper
Deep Residual Learning for Image Recognition by He et al.
Disclaimer: The team releasing ResNet did not write a model card for this model so this model card has been written by the Hugging Face team.
ResNet (Residual Network) is a convolutional neural network that democratized the concepts of residual learning and skip connections. This enables to train much deeper models.
This is ResNet v1.5, which differs from the original model: in the bottleneck blocks which require downsampling, v1 has stride = 2 in the first 1x1 convolution, whereas v1.5 has stride = 2 in the 3x3 convolution. This difference makes ResNet50 v1.5 slightly more accurate (~0.5% top1) than v1, but comes with a small performance drawback (~5% imgs/sec) according to
Nvidia.
You can use the raw model for image classification. See the
model hub to look for
fine-tuned versions on a task that interests you.
Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
1from transformers import AutoFeatureExtractor, ResNetForImageClassification
2import torch
3from datasets import load_dataset
4
5dataset = load_dataset("huggingface/cats-image")
6image = dataset["test"]["image"][0]
7
8feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-152")
9model = ResNetForImageClassification.from_pretrained("microsoft/resnet-152")
10
11inputs = feature_extractor(image, return_tensors="pt")
12
13with torch.no_grad():
14 logits = model(**inputs).logits
15
16# model predicts one of the 1000 ImageNet classes
17predicted_label = logits.argmax(-1).item()
18print(model.config.id2label[predicted_label])
For more code examples, we refer to the
documentation.
1@inproceedings{he2016deep,
2 title={Deep residual learning for image recognition},
3 author={He, Kaiming and Zhang, Xiangyu and Ren, Shaoqing and Sun, Jian},
4 booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
5 pages={770--778},
6 year={2016}
7}