File size: 1,105 Bytes
f4e7c82
50f02be
 
f4e7c82
 
 
50f02be
f4e7c82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
from fastai.vision.all import *
import gradio as gr

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



model = load_learner('models/sport-recognizer-v3.pkl')

equipment_labels = (
    'Archery Bow',
    'Badminton Shuttlecock',
    'Baseball Bat',
    'Basketball ball',
    'Bowling Ball',
    'Boxing Gloves',
    'Carrom board',
    'Chessboard',
    'Cricket Bat',
    'Frisbee disc',
    'Golf ball',
    'Hockey Stick',
    'Ice Skates',
    'Rugby Ball',
    'Skateboard',
    'Ski Poles',
    'Soccer ball',
    'Table Tennis Paddle',
    'Tennis Racket',
    'Volleyball ball'

)

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



#!export
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = [
    'test_images/unknown_00.jpg',
    'test_images/unknown_01.jpg',
    'test_images/unknown_02.jpg',
    'test_images/unknown_03.jpg'
    ]

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