File size: 997 Bytes
bc4b84e
 
 
 
 
 
 
 
 
 
 
 
 
 
4d15e2b
bc4b84e
 
 
 
 
 
 
 
 
 
a7b036c
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
import torch
import gradio as gr
from torch import nn
from torch.nn import functional as F
import torchvision
from PIL import Image
from torchvision import transforms

transformer = transforms.Compose([
    transforms.ToPILImage(),
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
model_best=torch.jit.load('model_scriptedd.pt',map_location=torch.device('cpu'))
classes=['Good luck','Love','Ok','Thumb up','Victory']

def predict(inp):
  inp=transformer(inp).unsqueeze(0)
  with torch.no_grad():
    prediction =F.softmax(model_best(inp)[0], dim=0)
    confidences = {classes[i]: float(prediction[i]) for i in range(5)}    
  return confidences
  
gr.Interface(predict,inputs=gr.inputs.Image(label="Input Image"),outputs='label').launch(debug='True')
#gr.Interface(predict,inputs=[gr.inputs.Image(label="Input Image", source="webcam"),gr.inputs.Image(label="Input Image")],outputs='label').launch(debug='True')