Dstd90
app rework1
348515d
raw
history blame
1.47 kB
import gradio as gr
from fastai.vision.all import load_learner
from fastai.vision.all import PILImage
shoe_labels = (
'Army boots',
'Ballet flats',
'Basketball shoes',
'Brogues',
'Chelsea Boot',
'Chuck Taylor',
'Climbing shoes',
'Cone heels',
'Court shoes',
'Cowboy boots',
'Derby shoes',
'Dress shoe',
'Flip flop',
'Golf shoes',
'High heels',
'High-tops shoes',
'Hiking boots',
'Ice-skates shoes',
'Kitten heels',
'Knee high boots',
'Laced booties',
'Lita shoe',
'Loafer',
'Mary Jane platforms',
'Moccasin',
'Mule shoes',
'Old skool',
'Oxford shoe',
'Platform heels',
'Running shoes',
'Sandal',
'Sneakers ',
'Soccer shoes',
'Uggs',
'Wedges shoe',
'Wellington boots'
)
model = load_learner('models/shoes-recognizer-v4.pkl')
def recognize_image(image):
pred, idx, probs = model.predict(image)
print(pred, probs)
return dict(zip(shoe_labels, map(float, probs)))
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label(num_top_classes=5)
examples = [
'test_image\image-01.jpg',
'test_image\image-02.jpg',
'test_image\image-03.jpg',
'test_image\image-06.jpg',
'test_image\image-07.jpg',
'test_image\image-08.jpg',
'test_image\image-09.jpg',
'test_image\image-10.jpg'
]
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False, share=True)