Spaces:
Runtime error
Runtime error
File size: 1,078 Bytes
73dfc5e 40809e0 73dfc5e 40809e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from transformers import AutoFeatureExtractor, RegNetForImageClassification
import torch
import gradio as gr
feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/regnet-y-040")
model = RegNetForImageClassification.from_pretrained("facebook/regnet-y-040")
def inference(image):
print("Type of image", type(image))
inputs = feature_extractor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
predicted_label = logits.argmax(-1).item()
return model.config.id2label[predicted_label]
title="RegNet-image-classification"
description="This space uses RegNet Model with an image classification head on top (a linear layer on top of the pooled features). It predicts one of the 1000 ImageNet classes. Check [Docs](https://huggingface.co/docs/transformers/main/en/model_doc/regnet) for more details."
examples=[['wolf.jpg'], ['ballon.jpg'], ['fountain.jpg']]
iface = gr.Interface(inference, inputs=gr.inputs.Image(), outputs="text",title=title,description=description,examples=examples)
iface.launch(enable_queue=True) |