Spaces:
Sleeping
Sleeping
File size: 1,030 Bytes
ab3729c 45be467 a10fbfa 45be467 ab3729c a10fbfa ab3729c |
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 |
from fastai.vision.all import *
import gradio as gr
import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
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-v1.pkl')
def recognize_image(image):
pred, idx, probs = model.predict(image)
return dict(zip(cap_labels, map(float, probs)))
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label(num_top_classes=5)
examples = [
'unknown_00.jpg',
'unknown_01.jpg',
'unknown_02.jpg',
'unknown_03.jpg'
]
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False) |