File size: 1,575 Bytes
27e0aca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
language:
- en
tags:
- ResNet-50
---

# ResNet-50

## Model Description

ResNet-50 model from [Deep Residual Learning for Image Recognition](https://arxiv.org/abs/1512.03385) paper.

## Original implementation

Follow [this link](https://huggingface.co/microsoft/resnet-50) to see the original implementation.

# How to use

You can use the `base` model that returns `last_hidden_state`.
```python
from transformers import AutoFeatureExtractor
from onnxruntime import InferenceSession
from datasets import load_dataset

# load image
dataset = load_dataset("huggingface/cats-image")
image = dataset["test"]["image"][0]

# load model
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50")
session = InferenceSession("onnx/model.onnx")

# ONNX Runtime expects NumPy arrays as input
inputs = feature_extractor(image, return_tensors="np")
outputs = session.run(output_names=["last_hidden_state"], input_feed=dict(inputs))
```

Or you can use the model with classification head that returns `logits`.
```python
from transformers import AutoFeatureExtractor
from onnxruntime import InferenceSession
from datasets import load_dataset

# load image
dataset = load_dataset("huggingface/cats-image")
image = dataset["test"]["image"][0]

# load model
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50")
session = InferenceSession("onnx/model_cls.onnx")

# ONNX Runtime expects NumPy arrays as input
inputs = feature_extractor(image, return_tensors="np")
outputs = session.run(output_names=["logits"], input_feed=dict(inputs))
```