Spaces:
Runtime error
Runtime error
Om-Alve
commited on
Commit
·
4739d3e
1
Parent(s):
96a6539
Initial commit
Browse files- quickdraw.h5 +3 -0
- requirements.txt +3 -0
- run.py +381 -0
quickdraw.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b6cfa034f67b78907cbc9f741996318e91b5198cecb5b855b3ef8d0f447740c6
|
| 3 |
+
size 30093304
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
pillow
|
run.py
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
labels = ['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 bat',
|
| 18 |
+
'baseball',
|
| 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 |
+
'cell phone',
|
| 68 |
+
'cello',
|
| 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 hose',
|
| 129 |
+
'garden',
|
| 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 plant',
|
| 155 |
+
'house',
|
| 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 |
+
'paint can',
|
| 207 |
+
'paintbrush',
|
| 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 |
+
't-shirt',
|
| 303 |
+
'table',
|
| 304 |
+
'teapot',
|
| 305 |
+
'teddy-bear',
|
| 306 |
+
'telephone',
|
| 307 |
+
'television',
|
| 308 |
+
'tennis racquet',
|
| 309 |
+
'tent',
|
| 310 |
+
'The Eiffel Tower',
|
| 311 |
+
'The Great Wall of China',
|
| 312 |
+
'The Mona Lisa',
|
| 313 |
+
'tiger',
|
| 314 |
+
'toaster',
|
| 315 |
+
'toe',
|
| 316 |
+
'toilet',
|
| 317 |
+
'tooth',
|
| 318 |
+
'toothbrush',
|
| 319 |
+
'toothpaste',
|
| 320 |
+
'tornado',
|
| 321 |
+
'tractor',
|
| 322 |
+
'traffic light',
|
| 323 |
+
'train',
|
| 324 |
+
'tree',
|
| 325 |
+
'triangle',
|
| 326 |
+
'trombone',
|
| 327 |
+
'truck',
|
| 328 |
+
'trumpet',
|
| 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']
|
| 346 |
+
|
| 347 |
+
from PIL import Image
|
| 348 |
+
import numpy as np
|
| 349 |
+
import tensorflow as tf
|
| 350 |
+
|
| 351 |
+
imgs = []
|
| 352 |
+
def predict(img):
|
| 353 |
+
img = img['layers'][0][:,:,3]
|
| 354 |
+
imgs.append(img)
|
| 355 |
+
image_pil = Image.fromarray(img)
|
| 356 |
+
|
| 357 |
+
# Resize the image using PIL
|
| 358 |
+
new_size = (28, 28) # Set the new size (e.g., 100x100)
|
| 359 |
+
resized_image_pil = image_pil.resize(new_size)
|
| 360 |
+
|
| 361 |
+
# Convert the resized PIL image back to a NumPy array
|
| 362 |
+
resized_image_np = np.array(resized_image_pil)
|
| 363 |
+
# imgs.append(img)
|
| 364 |
+
img = np.array(resized_image_np).reshape(1, 28, 28,1)
|
| 365 |
+
out = model.predict(img);
|
| 366 |
+
top5 = np.argsort(out[0])[::-1][:5]
|
| 367 |
+
label = labels
|
| 368 |
+
|
| 369 |
+
# Create a dictionary with label-probability pairs for the top 5 predictions
|
| 370 |
+
probabilities = {label[i]: float(out[0][i]) for i in top5}
|
| 371 |
+
|
| 372 |
+
return probabilities
|
| 373 |
+
|
| 374 |
+
model = tf.keras.models.load_model('quickdraw.h5', compile=False)
|
| 375 |
+
|
| 376 |
+
import gradio as gr
|
| 377 |
+
|
| 378 |
+
gr.Interface(fn=predict,
|
| 379 |
+
inputs=gr.Sketchpad(),
|
| 380 |
+
outputs="label",
|
| 381 |
+
live=True).launch()
|