File size: 639 Bytes
848643d
ba68f7a
2ad859f
 
 
ba68f7a
0c98f9c
 
 
 
50b4d78
0c98f9c
 
49a6344
0c98f9c
 
 
 
 
 
 
 
 
 
 
 
50b4d78
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


import gradio as gr
from fastai import *
from fastai.vision.all import *

def is_holdingweapon(x):
    return parent_label(x)


learn = load_learner('model_resnet34.pkl')


categories = ('Human holding Weapon','No Weapon detected','Weapon')

def classify_image(img):
    pred,idx,probs = learn.predict(img)
    return dict(zip(categories,map(float,probs)))   #float because gradio doesnt take tensors


image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()

examples = ['human_weapon1.jpg','weapon22.jpg']

intf = gr.Interface(fn = classify_image,inputs = image,outputs=label,examples=examples)
intf.launch(inline = False)