Deep Residual Learning for Image Recognition
Paper
•
1512.03385
•
Published
•
12
ResNet-50 model from Deep Residual Learning for Image Recognition paper.
Follow this link to see the original implementation.
You can use the base model that returns last_hidden_state.
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.
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))