|
from transformers import AutoImageProcessor, ResNetForImageClassification |
|
import torch |
|
from datasets import load_dataset |
|
|
|
dataset = load_dataset("huggingface/cats-image") |
|
image = dataset["test"]["image"][0] |
|
|
|
processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50") |
|
model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50") |
|
|
|
inputs = processor(image, return_tensors="pt") |
|
|
|
with torch.no_grad(): |
|
logits = model(**inputs).logits |
|
|
|
|
|
predicted_label = logits.argmax(-1).item() |
|
print(model.config.id2label[predicted_label]) |