File size: 1,074 Bytes
4ccdd76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e51e936
4ccdd76
 
 
 
 
 
 
 
 
 
 
 
c2ac254
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
48
49
from fastai.vision.all import *
import gradio as gr

#import pathlib
#temp = pathlib.PosixPath
#pathlib.PosixPath = pathlib.WindowsPath

sportballs_labels = (
    'American Football',
    'Base Ball', 
    'Basket Ball', 
    'Beach Ball', 
    'Bowling Ball', 
    'Cricket Ball',
    'Golf Ball', 
    'Hockey Puck',
    'Lawn Bowls', 
    'Pool Ball', 
    'Sepak Takraw', 
    'Shuttlecock', 
    'Soccer Ball', 
    'Squash Ball', 
    'Table Tennis Ball', 
    'Tennis Ball', 
    'Volley Ball', 
    'Waterpolo Ball',
    'Wiffle Ball'
)

model = load_learner('sportballs-recognizer-v2.pkl')

def recognize_image(image):
    pred, idx, probs = model.predict(image)
    return dict(zip(sportballs_labels, map(float, probs)))

image = gr.Image(width=224,height=224)
label = gr.Label(num_top_classes=5)
examples = [
    'unknown_00.jpg',
    'unknown_01.jpg',
    'unknown_02.jpg',
    'unknown_03.jpg',
    'unknown_04.jpg',
    'unknown_05.jpg'

    ]

iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False)