Spaces:
Sleeping
Sleeping
File size: 1,140 Bytes
d957918 6388886 d957918 761f68b d957918 |
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 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
from model import model_classification
import torch,os
path = 'efficient_cat_dog.pth'
class_names = ['cat','dog']
model,transforms = model_classification()
model.load_state_dict(torch.load(path,map_location=torch.device('cpu')))
def predict(img):
img = transforms(img).unsqueeze(0)
model.eval()
with torch.inference_mode():
logits = model(img)
pred_probs = torch.softmax(logits,dim=1)
pred_label_and_probs = {class_names[i]: float(pred_probs[0][i]) for i in range(len(class_names))}
return pred_label_and_probs
title = 'Cat and Dog classification'
description = 'An EfficientNetB0 feature extractor computert vision model to classify the cats and dogs'
example_list = [["examples/" + example] for example in os.listdir("examples")]
demo = gr.Interface(fn=predict,
inputs=gr.Image(type='pil'),
outputs=gr.Label(num_top_classes=2,label='Predictions'),
title=title,
examples=example_list,
description=description,
)
demo.launch(share=True)
|