Spaces:
Sleeping
Sleeping
File size: 936 Bytes
17b5aa2 478b157 17b5aa2 478b157 17b5aa2 |
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 |
from fastai.vision.all import load_learner
import gradio as gr
cap_labels = [
'balaclava cap',
'baseball cap',
'beanie cap',
'boater hat',
'bowler hat',
'bucket hat',
'cowboy hat',
'fedora cap',
'flat cap',
'ivy cap',
'kepi cap',
'newsboy cap',
'pork pie hat',
'rasta cap',
'sun hat',
'taqiyah cap',
'top hat',
'trucker cap',
'turban cap',
'visor cap'
]
model = load_learner("models/cap_recognizer_v0.pkl")
def recognize_image(image):
pred, idx, probs = model.predict(image)
return dict(zip(cap_labels, map(float,probs)))
image = gr.Image()
label = gr.Label()
examples = [
'test_images/unknown_00.jpg',
'test_images/unknown_01.jpg',
'test_images/unknown_02.jpg',
'test_images/unknown_03.jpg']
demo = gr.Interface(fn=recognize_image, inputs="image", outputs="label", examples = examples)
demo.launch(inline = False, share = True)
|