satpalsr/RegNet-Image-Classification
3
1from transformers import AutoFeatureExtractor, RegNetForImageClassification2import torch3import gradio as gr4 5feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/regnet-y-040")6model = RegNetForImageClassification.from_pretrained("facebook/regnet-y-040")7 8def inference(image):9 print("Type of image", type(image))10 inputs = feature_extractor(image, return_tensors="pt")11 12 with torch.no_grad():13 logits = model(**inputs).logits14 15 predicted_label = logits.argmax(-1).item()16 return model.config.id2label[predicted_label]17 18title="RegNet-image-classification"19description="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."20 21examples=[['wolf.jpg'], ['ballon.jpg'], ['fountain.jpg']]22iface = gr.Interface(inference, inputs=gr.inputs.Image(), outputs="text",title=title,description=description,examples=examples)23iface.launch(enable_queue=True)