Spaces:
Runtime error
Runtime error
File size: 1,308 Bytes
73dfc5e b3c8ec7 73dfc5e b3c8ec7 |
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 |
from transformers import AutoFeatureExtractor, RegNetForImageClassification
import torch
import gradio as gr
try:
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.inpu, outputs="text",title=title,description=description,examples=examples)
iface.launch(enable_queue=True,cache_examples=True)
except Exception as e:
print("Oops got an error: Create an issue/PR at github.com/satpalsr/space-repo")
print( "Error: %s" % str(e) ) |