jerilseb commited on
Commit
c3e75ac
1 Parent(s): 63debe3

update stuff

Browse files
Files changed (4) hide show
  1. app.py +45 -4
  2. classes.txt +345 -0
  3. model.pth +3 -0
  4. requirements.txt +3 -0
app.py CHANGED
@@ -1,7 +1,48 @@
 
 
 
 
 
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
+ import torch
2
+ from torch import nn
3
+ import torchvision.transforms as transforms
4
+ import torch.nn.functional as F
5
+ from pathlib import Path
6
  import gradio as gr
7
+ from PIL import Image
8
+ import numpy as np
9
 
 
 
10
 
11
+ LABELS = Path('classes.txt').read_text().splitlines()
12
+ num_classes = len(LABELS)
13
+
14
+ model = nn.Sequential(
15
+ nn.Conv2d(1, 64, 3, padding='same'),
16
+ nn.ReLU(),
17
+ nn.MaxPool2d(2),
18
+ nn.Conv2d(64, 128, 3, padding='same'),
19
+ nn.ReLU(),
20
+ nn.MaxPool2d(2),
21
+ nn.Conv2d(128, 256, 3, padding='same'),
22
+ nn.ReLU(),
23
+ nn.MaxPool2d(2),
24
+ nn.Flatten(),
25
+ nn.Linear(2304, 512),
26
+ nn.ReLU(),
27
+ nn.Linear(512, num_classes),
28
+ )
29
+
30
+ state_dict = torch.load('model.pth', map_location='cpu')
31
+ model.load_state_dict(state_dict, strict=False)
32
+ model.eval()
33
+
34
+ def predict(im):
35
+ x = torch.tensor(im, dtype=torch.float32).unsqueeze(0).unsqueeze(0) / 255.
36
+
37
+ with torch.no_grad():
38
+ out = model(x)
39
+
40
+ probabilities = F.softmax(out[0], dim=0)
41
+
42
+ values, indices = torch.topk(probabilities, 5)
43
+
44
+ return {LABELS[i]: v.item() for i, v in zip(indices, values)}
45
+
46
+
47
+ interface = gr.Interface(predict, inputs='sketchpad', outputs='label', live=True)
48
+ interface.launch(debug=True)
classes.txt ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aircraft carrier
2
+ airplane
3
+ alarm clock
4
+ ambulance
5
+ angel
6
+ animal migration
7
+ ant
8
+ anvil
9
+ apple
10
+ arm
11
+ asparagus
12
+ axe
13
+ backpack
14
+ banana
15
+ bandage
16
+ barn
17
+ baseball
18
+ baseball bat
19
+ basket
20
+ basketball
21
+ bat
22
+ bathtub
23
+ beach
24
+ bear
25
+ beard
26
+ bed
27
+ bee
28
+ belt
29
+ bench
30
+ bicycle
31
+ binoculars
32
+ bird
33
+ birthday cake
34
+ blackberry
35
+ blueberry
36
+ book
37
+ boomerang
38
+ bottlecap
39
+ bowtie
40
+ bracelet
41
+ brain
42
+ bread
43
+ bridge
44
+ broccoli
45
+ broom
46
+ bucket
47
+ bulldozer
48
+ bus
49
+ bush
50
+ butterfly
51
+ cactus
52
+ cake
53
+ calculator
54
+ calendar
55
+ camel
56
+ camera
57
+ camouflage
58
+ campfire
59
+ candle
60
+ cannon
61
+ canoe
62
+ car
63
+ carrot
64
+ castle
65
+ cat
66
+ ceiling fan
67
+ cello
68
+ cell phone
69
+ chair
70
+ chandelier
71
+ church
72
+ circle
73
+ clarinet
74
+ clock
75
+ cloud
76
+ coffee cup
77
+ compass
78
+ computer
79
+ cookie
80
+ cooler
81
+ couch
82
+ cow
83
+ crab
84
+ crayon
85
+ crocodile
86
+ crown
87
+ cruise ship
88
+ cup
89
+ diamond
90
+ dishwasher
91
+ diving board
92
+ dog
93
+ dolphin
94
+ donut
95
+ door
96
+ dragon
97
+ dresser
98
+ drill
99
+ drums
100
+ duck
101
+ dumbbell
102
+ ear
103
+ elbow
104
+ elephant
105
+ envelope
106
+ eraser
107
+ eye
108
+ eyeglasses
109
+ face
110
+ fan
111
+ feather
112
+ fence
113
+ finger
114
+ fire hydrant
115
+ fireplace
116
+ firetruck
117
+ fish
118
+ flamingo
119
+ flashlight
120
+ flip flops
121
+ floor lamp
122
+ flower
123
+ flying saucer
124
+ foot
125
+ fork
126
+ frog
127
+ frying pan
128
+ garden
129
+ garden hose
130
+ giraffe
131
+ goatee
132
+ golf club
133
+ grapes
134
+ grass
135
+ guitar
136
+ hamburger
137
+ hammer
138
+ hand
139
+ harp
140
+ hat
141
+ headphones
142
+ hedgehog
143
+ helicopter
144
+ helmet
145
+ hexagon
146
+ hockey puck
147
+ hockey stick
148
+ horse
149
+ hospital
150
+ hot air balloon
151
+ hot dog
152
+ hot tub
153
+ hourglass
154
+ house
155
+ house plant
156
+ hurricane
157
+ ice cream
158
+ jacket
159
+ jail
160
+ kangaroo
161
+ key
162
+ keyboard
163
+ knee
164
+ knife
165
+ ladder
166
+ lantern
167
+ laptop
168
+ leaf
169
+ leg
170
+ light bulb
171
+ lighter
172
+ lighthouse
173
+ lightning
174
+ line
175
+ lion
176
+ lipstick
177
+ lobster
178
+ lollipop
179
+ mailbox
180
+ map
181
+ marker
182
+ matches
183
+ megaphone
184
+ mermaid
185
+ microphone
186
+ microwave
187
+ monkey
188
+ moon
189
+ mosquito
190
+ motorbike
191
+ mountain
192
+ mouse
193
+ moustache
194
+ mouth
195
+ mug
196
+ mushroom
197
+ nail
198
+ necklace
199
+ nose
200
+ ocean
201
+ octagon
202
+ octopus
203
+ onion
204
+ oven
205
+ owl
206
+ paintbrush
207
+ paint can
208
+ palm tree
209
+ panda
210
+ pants
211
+ paper clip
212
+ parachute
213
+ parrot
214
+ passport
215
+ peanut
216
+ pear
217
+ peas
218
+ pencil
219
+ penguin
220
+ piano
221
+ pickup truck
222
+ picture frame
223
+ pig
224
+ pillow
225
+ pineapple
226
+ pizza
227
+ pliers
228
+ police car
229
+ pond
230
+ pool
231
+ popsicle
232
+ postcard
233
+ potato
234
+ power outlet
235
+ purse
236
+ rabbit
237
+ raccoon
238
+ radio
239
+ rain
240
+ rainbow
241
+ rake
242
+ remote control
243
+ rhinoceros
244
+ rifle
245
+ river
246
+ roller coaster
247
+ rollerskates
248
+ sailboat
249
+ sandwich
250
+ saw
251
+ saxophone
252
+ school bus
253
+ scissors
254
+ scorpion
255
+ screwdriver
256
+ sea turtle
257
+ see saw
258
+ shark
259
+ sheep
260
+ shoe
261
+ shorts
262
+ shovel
263
+ sink
264
+ skateboard
265
+ skull
266
+ skyscraper
267
+ sleeping bag
268
+ smiley face
269
+ snail
270
+ snake
271
+ snorkel
272
+ snowflake
273
+ snowman
274
+ soccer ball
275
+ sock
276
+ speedboat
277
+ spider
278
+ spoon
279
+ spreadsheet
280
+ square
281
+ squiggle
282
+ squirrel
283
+ stairs
284
+ star
285
+ steak
286
+ stereo
287
+ stethoscope
288
+ stitches
289
+ stop sign
290
+ stove
291
+ strawberry
292
+ streetlight
293
+ string bean
294
+ submarine
295
+ suitcase
296
+ sun
297
+ swan
298
+ sweater
299
+ swing set
300
+ sword
301
+ syringe
302
+ table
303
+ teapot
304
+ teddy-bear
305
+ telephone
306
+ television
307
+ tennis racquet
308
+ tent
309
+ The Eiffel Tower
310
+ The Great Wall of China
311
+ The Mona Lisa
312
+ tiger
313
+ toaster
314
+ toe
315
+ toilet
316
+ tooth
317
+ toothbrush
318
+ toothpaste
319
+ tornado
320
+ tractor
321
+ traffic light
322
+ train
323
+ tree
324
+ triangle
325
+ trombone
326
+ truck
327
+ trumpet
328
+ t-shirt
329
+ umbrella
330
+ underwear
331
+ van
332
+ vase
333
+ violin
334
+ washing machine
335
+ watermelon
336
+ waterslide
337
+ whale
338
+ wheel
339
+ windmill
340
+ wine bottle
341
+ wine glass
342
+ wristwatch
343
+ yoga
344
+ zebra
345
+ zigzag
model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:217879299736265e793d5c72f21acc9b8646fa926f51fb3c31c46400e6bfe32c
3
+ size 6910492
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ torchvision
3
+ Pillow