Views
No views yet
1from transformers import AutoFeatureExtractor, AutoModelForImageClassification
2from datasets import load_dataset
3import torch
4
5feature_extractor = AutoFeatureExtractor.from_pretrained("fxmarty/tiny-testing-remote-code")
6
7model = AutoModelForImageClassification.from_pretrained("fxmarty/tiny-testing-remote-code", trust_remote_code=True)
8
9dataset = load_dataset("huggingface/cats-image")
10image = dataset["test"]["image"][0]
11
12inputs = feature_extractor(image, return_tensors="pt")
13
14with torch.no_grad():
15 logits = model(**inputs).logits
16
17# model predicts one of the 1000 ImageNet classes
18predicted_label = logits.argmax(-1).item()
19print(model.config.id2label[predicted_label])