Views
No views yet

1import torch
2from datasets import load_dataset
3from transformers import EfficientNetImageProcessor, EfficientNetForImageClassification
4
5dataset = load_dataset("huggingface/cats-image")
6image = dataset["test"]["image"][0]
7
8preprocessor = EfficientNetImageProcessor.from_pretrained("google/efficientnet-b2")
9model = EfficientNetForImageClassification.from_pretrained("google/efficientnet-b2")
10
11inputs = preprocessor(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]),1@article{Tan2019EfficientNetRM,
2 title={EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks},
3 author={Mingxing Tan and Quoc V. Le},
4 journal={ArXiv},
5 year={2019},
6 volume={abs/1905.11946}
7}