Spaces:
Runtime error
Runtime error
File size: 1,052 Bytes
d9bf0de 235c93b d9bf0de d062c9e d9bf0de d062c9e d9bf0de |
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 |
from transformers import AutoFeatureExtractor, ResNetForImageClassification
import torch
import gradio as gr
# load model
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50")
model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50")
def predict(image):
inputs = feature_extractor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
# model predicts one of the 1000 ImageNet classes
predicted_label = logits.argmax(-1).item()
prediction = model.config.id2label[predicted_label]
return prediction
# setup Gradio interface
title = "Image classifier"
description = "Image classification with pretrained resnet50 model"
examples = ['dog.jpg']
interpretation='default'
enable_queue=True
gr.Interface(
fn=predict,
inputs=gr.inputs.Image(),
outputs=gr.outputs.Label(num_top_classes=1),
title=title,
description=description,
examples=examples,
interpretation=interpretation,
enable_queue=enable_queue
).launch()
|