ahmedtanvir47 commited on
Commit
f4e7c82
·
1 Parent(s): 50f02be

model, interface, examples added

Browse files
README.md CHANGED
@@ -11,3 +11,8 @@ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+
16
+ HuggingFace App URL: https://huggingface.co/spaces/ahmedtanvir47/sport-recognizer
17
+
18
+ Gradio App URL:
app.ipynb ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "id": "51neqepjqu_z"
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "#|default_exp app"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {
17
+ "id": "Hm8cO7PDvYZe"
18
+ },
19
+ "source": [
20
+ "# Sports Equipment Recognizer"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 2,
26
+ "metadata": {
27
+ "colab": {
28
+ "base_uri": "https://localhost:8080/"
29
+ },
30
+ "id": "cUZU1ZIavbMD",
31
+ "outputId": "7ca0248a-0cbd-4dc0-83af-4a5489da5878"
32
+ },
33
+ "outputs": [],
34
+ "source": [
35
+ "!pip install -Uqq fastai nbdev python-multipart"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 9,
41
+ "metadata": {
42
+ "id": "nmylpDsHv3D6"
43
+ },
44
+ "outputs": [],
45
+ "source": [
46
+ "!pip install -qq gradio==4.44.1\n"
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": 4,
52
+ "metadata": {
53
+ "id": "FsrcDOg2xzCf"
54
+ },
55
+ "outputs": [],
56
+ "source": [
57
+ "from fastai.vision.all import *"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": null,
63
+ "metadata": {
64
+ "colab": {
65
+ "base_uri": "https://localhost:8080/",
66
+ "height": 531
67
+ },
68
+ "id": "7WvIfcjDvgx9",
69
+ "outputId": "953a7653-7978-45b7-8d17-ed30b2d7803a"
70
+ },
71
+ "outputs": [],
72
+ "source": [
73
+ "#!export\n",
74
+ "from fastai.vision.all import load_learner\n",
75
+ "import python_multipart\n",
76
+ "import gradio as gr"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": null,
82
+ "metadata": {
83
+ "id": "dSeRJ5RU6j6A"
84
+ },
85
+ "outputs": [],
86
+ "source": [
87
+ "# from google.colab import drive\n",
88
+ "# drive.mount('/content/drive')"
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "execution_count": null,
94
+ "metadata": {
95
+ "id": "z_uKf6nl6n50"
96
+ },
97
+ "outputs": [],
98
+ "source": [
99
+ "# %cd /content/drive/My Drive/Sports Equipment"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": null,
105
+ "metadata": {
106
+ "id": "euLWl9eAvk-T"
107
+ },
108
+ "outputs": [],
109
+ "source": [
110
+ "#!export\n",
111
+ "model = load_learner('models/sport-recognizer-v3.pkl')"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 12,
117
+ "metadata": {
118
+ "id": "tzouWGYqwDvF"
119
+ },
120
+ "outputs": [],
121
+ "source": [
122
+ "#!export\n",
123
+ "equipment_labels = (\n",
124
+ " 'Archery Bow',\n",
125
+ " 'Badminton Shuttlecock',\n",
126
+ " 'Baseball Bat',\n",
127
+ " 'Basketball ball',\n",
128
+ " 'Bowling Ball',\n",
129
+ " 'Boxing Gloves',\n",
130
+ " 'Carrom board',\n",
131
+ " 'Chessboard',\n",
132
+ " 'Cricket Bat',\n",
133
+ " 'Frisbee disc',\n",
134
+ " 'Golf ball',\n",
135
+ " 'Hockey Stick',\n",
136
+ " 'Ice Skates',\n",
137
+ " 'Rugby Ball',\n",
138
+ " 'Skateboard',\n",
139
+ " 'Ski Poles',\n",
140
+ " 'Soccer ball',\n",
141
+ " 'Table Tennis Paddle',\n",
142
+ " 'Tennis Racket',\n",
143
+ " 'Volleyball ball'\n",
144
+ "\n",
145
+ ")\n",
146
+ "\n",
147
+ "def recognize_image(image):\n",
148
+ " pred, idx, probs = model.predict(image)\n",
149
+ " return dict(zip(equipment_labels, map(float, probs)))"
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": null,
155
+ "metadata": {
156
+ "id": "MdysqYkLw5PH"
157
+ },
158
+ "outputs": [],
159
+ "source": [
160
+ "img = PILImage.create(f'test_images/unknown_01.jpg')\n",
161
+ "img.thumbnail((192,192))\n",
162
+ "img"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": null,
168
+ "metadata": {
169
+ "id": "yTWEYc-3w82b"
170
+ },
171
+ "outputs": [],
172
+ "source": [
173
+ "recognize_image(img)"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "execution_count": null,
179
+ "metadata": {
180
+ "id": "sXlpu9i8zE5e"
181
+ },
182
+ "outputs": [],
183
+ "source": [
184
+ "#!export\n",
185
+ "image = gr.inputs.Image(shape=(192,192))\n",
186
+ "label = gr.outputs.Label()\n",
187
+ "examples = [\n",
188
+ " 'test_images/unknown_00.jpg',\n",
189
+ " 'test_images/unknown_01.jpg',\n",
190
+ " 'test_images/unknown_02.jpg',\n",
191
+ " 'test_images/unknown_03.jpg'\n",
192
+ " ]\n",
193
+ "\n",
194
+ "iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)\n",
195
+ "iface.launch(inline=False)"
196
+ ]
197
+ },
198
+ {
199
+ "cell_type": "markdown",
200
+ "metadata": {
201
+ "id": "3gyUlfJW2jRu"
202
+ },
203
+ "source": [
204
+ "# Notebook to Python Script Export"
205
+ ]
206
+ },
207
+ {
208
+ "cell_type": "code",
209
+ "execution_count": null,
210
+ "metadata": {
211
+ "id": "IybJQe222ikO"
212
+ },
213
+ "outputs": [],
214
+ "source": [
215
+ "from nbdev.export import notebook2script"
216
+ ]
217
+ },
218
+ {
219
+ "cell_type": "code",
220
+ "execution_count": null,
221
+ "metadata": {
222
+ "id": "85az32eq3qpJ"
223
+ },
224
+ "outputs": [],
225
+ "source": [
226
+ "notebook2script('app.ipynb')"
227
+ ]
228
+ }
229
+ ],
230
+ "metadata": {
231
+ "colab": {
232
+ "provenance": []
233
+ },
234
+ "kernelspec": {
235
+ "display_name": "Python 3",
236
+ "language": "python",
237
+ "name": "python3"
238
+ },
239
+ "language_info": {
240
+ "codemirror_mode": {
241
+ "name": "ipython",
242
+ "version": 3
243
+ },
244
+ "file_extension": ".py",
245
+ "mimetype": "text/x-python",
246
+ "name": "python",
247
+ "nbconvert_exporter": "python",
248
+ "pygments_lexer": "ipython3",
249
+ "version": "3.9.13"
250
+ },
251
+ "vscode": {
252
+ "interpreter": {
253
+ "hash": "f8f14f5a7c49a331ac7a55934b43ce13bd28be1333db14e2d71768ad3378996c"
254
+ }
255
+ }
256
+ },
257
+ "nbformat": 4,
258
+ "nbformat_minor": 0
259
+ }
app.py CHANGED
@@ -1,7 +1,53 @@
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ # import pathlib
5
+ # temp = pathlib.PosixPath
6
+ # pathlib.PosixPath = pathlib.WindowsPath
7
 
8
+
9
+
10
+ model = load_learner('models/sport-recognizer-v3.pkl')
11
+
12
+ equipment_labels = (
13
+ 'Archery Bow',
14
+ 'Badminton Shuttlecock',
15
+ 'Baseball Bat',
16
+ 'Basketball ball',
17
+ 'Bowling Ball',
18
+ 'Boxing Gloves',
19
+ 'Carrom board',
20
+ 'Chessboard',
21
+ 'Cricket Bat',
22
+ 'Frisbee disc',
23
+ 'Golf ball',
24
+ 'Hockey Stick',
25
+ 'Ice Skates',
26
+ 'Rugby Ball',
27
+ 'Skateboard',
28
+ 'Ski Poles',
29
+ 'Soccer ball',
30
+ 'Table Tennis Paddle',
31
+ 'Tennis Racket',
32
+ 'Volleyball ball'
33
+
34
+ )
35
+
36
+ def recognize_image(image):
37
+ pred, idx, probs = model.predict(image)
38
+ return dict(zip(equipment_labels, map(float, probs)))
39
+
40
+
41
+
42
+ #!export
43
+ image = gr.inputs.Image(shape=(192,192))
44
+ label = gr.outputs.Label()
45
+ examples = [
46
+ 'test_images/unknown_00.jpg',
47
+ 'test_images/unknown_01.jpg',
48
+ 'test_images/unknown_02.jpg',
49
+ 'test_images/unknown_03.jpg'
50
+ ]
51
+
52
+ iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
53
+ iface.launch(inline=False)
app_old.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def greet(name):
4
+ return "Hello " + name + "!!"
5
+
6
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ demo.launch()
models/sport-recognizer-v3.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b02cebf619eac1b1ce182155318ca3461dd1aaf8de283259c04d4741ba414c1
3
+ size 87597196
test_images/unknown_00.jpg ADDED
test_images/unknown_01.jpg ADDED
test_images/unknown_02.jpg ADDED
test_images/unknown_03.jpg ADDED