weaponFinder / app.py
dpaliwa
Added app.py
0c98f9c
raw
history blame
600 Bytes
from fastai.vision.all import *
import gradio as gr
def is_holdingweapon(x):
return parent_label(x)
learn = load_learner('weapon_finder_model.pkl')
categories = ('Human holding Weapon','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)