Spaces:
Sleeping
Sleeping
File size: 1,557 Bytes
37a1151 56734ed db5e8f4 37a1151 9f50c5e 5b18dae 9f50c5e 5b18dae 9f50c5e 56734ed db5e8f4 9f50c5e db5e8f4 3bdc5a4 9f50c5e f9a56d3 |
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 |
import gradio as gr
from fastai.vision.all import *
from os import listdir
import random
title = "Who Am I? (Hockey Edition)"
desc = """<center>This app uses a 'neural network' (a type of machine learning model) to classify
an image as containing a hockey player, a hockey goalie or a hockey referee.</center>"""
art = """I built this model using about 50 hockey related images found on the web and in my own collection. I started with a pretrained `resnet18` model (resnet18 is trained on `imagenet`, a very large dataset with millions of images)
and then performed `fine tuning` of this using python and the `fast.ai` library.
The total training time for this was about 5 minutes on a basic GPU. It's impressive how accurate this quick / small model can be!"""
learn = load_learner('hockey_model.pkl')
categories = ('Hockey Goalie', 'Hockey Player', "Hockey Referee")
image = gr.Image(shape=(192, 192))
label = gr.Label()
skater_example = 'assets/skaters/' + random.choice(listdir('assets/skaters'))
ref_example = 'assets/referees/' + random.choice(listdir('assets/referees'))
goalie_example = 'assets/goalies/' + random.choice(listdir('assets/goalies'))
def classify_image(img):
pred,idx,prob = learn.predict(img)
return dict(zip(categories, map(float, prob)))
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, theme=gr.themes.Glass(),
examples=[skater_example, ref_example, goalie_example], title=title,
description=desc, article=art)
iface.launch(share=False, debug=True) |