nateraw commited on
Commit
545613a
1 Parent(s): e5a6962

Create quickdraw.py

Browse files
Files changed (1) hide show
  1. quickdraw.py +432 -0
quickdraw.py ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Quick, Draw! Data Set"""
2
+
3
+
4
+ import numpy as np
5
+
6
+ import datasets
7
+ from datasets.tasks import ImageClassification
8
+
9
+
10
+ _CITATION = """\
11
+ @article{DBLP:journals/corr/HaE17,
12
+ author = {David Ha and
13
+ Douglas Eck},
14
+ title = {A Neural Representation of Sketch Drawings},
15
+ journal = {CoRR},
16
+ volume = {abs/1704.03477},
17
+ year = {2017},
18
+ url = {http://arxiv.org/abs/1704.03477},
19
+ archivePrefix = {arXiv},
20
+ eprint = {1704.03477},
21
+ timestamp = {Mon, 13 Aug 2018 16:48:30 +0200},
22
+ biburl = {https://dblp.org/rec/bib/journals/corr/HaE17},
23
+ bibsource = {dblp computer science bibliography, https://dblp.org}
24
+ }
25
+ """
26
+
27
+ _DESCRIPTION = """\
28
+ The Quick Draw Dataset is a collection of 50 million drawings across 345 categories, contributed by players of the game Quick, Draw!.
29
+ """
30
+
31
+ _URL = "https://storage.googleapis.com/quickdraw_dataset/full/numpy_bitmap/"
32
+ _CLASSES = [
33
+ "aircraft carrier",
34
+ "airplane",
35
+ "alarm clock",
36
+ "ambulance",
37
+ "angel",
38
+ "animal migration",
39
+ "ant",
40
+ "anvil",
41
+ "apple",
42
+ "arm",
43
+ "asparagus",
44
+ "axe",
45
+ "backpack",
46
+ "banana",
47
+ "bandage",
48
+ "barn",
49
+ "baseball",
50
+ "baseball bat",
51
+ "basket",
52
+ "basketball",
53
+ "bat",
54
+ "bathtub",
55
+ "beach",
56
+ "bear",
57
+ "beard",
58
+ "bed",
59
+ "bee",
60
+ "belt",
61
+ "bench",
62
+ "bicycle",
63
+ "binoculars",
64
+ "bird",
65
+ "birthday cake",
66
+ "blackberry",
67
+ "blueberry",
68
+ "book",
69
+ "boomerang",
70
+ "bottlecap",
71
+ "bowtie",
72
+ "bracelet",
73
+ "brain",
74
+ "bread",
75
+ "bridge",
76
+ "broccoli",
77
+ "broom",
78
+ "bucket",
79
+ "bulldozer",
80
+ "bus",
81
+ "bush",
82
+ "butterfly",
83
+ "cactus",
84
+ "cake",
85
+ "calculator",
86
+ "calendar",
87
+ "camel",
88
+ "camera",
89
+ "camouflage",
90
+ "campfire",
91
+ "candle",
92
+ "cannon",
93
+ "canoe",
94
+ "car",
95
+ "carrot",
96
+ "castle",
97
+ "cat",
98
+ "ceiling fan",
99
+ "cello",
100
+ "cell phone",
101
+ "chair",
102
+ "chandelier",
103
+ "church",
104
+ "circle",
105
+ "clarinet",
106
+ "clock",
107
+ "cloud",
108
+ "coffee cup",
109
+ "compass",
110
+ "computer",
111
+ "cookie",
112
+ "cooler",
113
+ "couch",
114
+ "cow",
115
+ "crab",
116
+ "crayon",
117
+ "crocodile",
118
+ "crown",
119
+ "cruise ship",
120
+ "cup",
121
+ "diamond",
122
+ "dishwasher",
123
+ "diving board",
124
+ "dog",
125
+ "dolphin",
126
+ "donut",
127
+ "door",
128
+ "dragon",
129
+ "dresser",
130
+ "drill",
131
+ "drums",
132
+ "duck",
133
+ "dumbbell",
134
+ "ear",
135
+ "elbow",
136
+ "elephant",
137
+ "envelope",
138
+ "eraser",
139
+ "eye",
140
+ "eyeglasses",
141
+ "face",
142
+ "fan",
143
+ "feather",
144
+ "fence",
145
+ "finger",
146
+ "fire hydrant",
147
+ "fireplace",
148
+ "firetruck",
149
+ "fish",
150
+ "flamingo",
151
+ "flashlight",
152
+ "flip flops",
153
+ "floor lamp",
154
+ "flower",
155
+ "flying saucer",
156
+ "foot",
157
+ "fork",
158
+ "frog",
159
+ "frying pan",
160
+ "garden",
161
+ "garden hose",
162
+ "giraffe",
163
+ "goatee",
164
+ "golf club",
165
+ "grapes",
166
+ "grass",
167
+ "guitar",
168
+ "hamburger",
169
+ "hammer",
170
+ "hand",
171
+ "harp",
172
+ "hat",
173
+ "headphones",
174
+ "hedgehog",
175
+ "helicopter",
176
+ "helmet",
177
+ "hexagon",
178
+ "hockey puck",
179
+ "hockey stick",
180
+ "horse",
181
+ "hospital",
182
+ "hot air balloon",
183
+ "hot dog",
184
+ "hot tub",
185
+ "hourglass",
186
+ "house",
187
+ "house plant",
188
+ "hurricane",
189
+ "ice cream",
190
+ "jacket",
191
+ "jail",
192
+ "kangaroo",
193
+ "key",
194
+ "keyboard",
195
+ "knee",
196
+ "knife",
197
+ "ladder",
198
+ "lantern",
199
+ "laptop",
200
+ "leaf",
201
+ "leg",
202
+ "light bulb",
203
+ "lighter",
204
+ "lighthouse",
205
+ "lightning",
206
+ "line",
207
+ "lion",
208
+ "lipstick",
209
+ "lobster",
210
+ "lollipop",
211
+ "mailbox",
212
+ "map",
213
+ "marker",
214
+ "matches",
215
+ "megaphone",
216
+ "mermaid",
217
+ "microphone",
218
+ "microwave",
219
+ "monkey",
220
+ "moon",
221
+ "mosquito",
222
+ "motorbike",
223
+ "mountain",
224
+ "mouse",
225
+ "moustache",
226
+ "mouth",
227
+ "mug",
228
+ "mushroom",
229
+ "nail",
230
+ "necklace",
231
+ "nose",
232
+ "ocean",
233
+ "octagon",
234
+ "octopus",
235
+ "onion",
236
+ "oven",
237
+ "owl",
238
+ "paintbrush",
239
+ "paint can",
240
+ "palm tree",
241
+ "panda",
242
+ "pants",
243
+ "paper clip",
244
+ "parachute",
245
+ "parrot",
246
+ "passport",
247
+ "peanut",
248
+ "pear",
249
+ "peas",
250
+ "pencil",
251
+ "penguin",
252
+ "piano",
253
+ "pickup truck",
254
+ "picture frame",
255
+ "pig",
256
+ "pillow",
257
+ "pineapple",
258
+ "pizza",
259
+ "pliers",
260
+ "police car",
261
+ "pond",
262
+ "pool",
263
+ "popsicle",
264
+ "postcard",
265
+ "potato",
266
+ "power outlet",
267
+ "purse",
268
+ "rabbit",
269
+ "raccoon",
270
+ "radio",
271
+ "rain",
272
+ "rainbow",
273
+ "rake",
274
+ "remote control",
275
+ "rhinoceros",
276
+ "rifle",
277
+ "river",
278
+ "roller coaster",
279
+ "rollerskates",
280
+ "sailboat",
281
+ "sandwich",
282
+ "saw",
283
+ "saxophone",
284
+ "school bus",
285
+ "scissors",
286
+ "scorpion",
287
+ "screwdriver",
288
+ "sea turtle",
289
+ "see saw",
290
+ "shark",
291
+ "sheep",
292
+ "shoe",
293
+ "shorts",
294
+ "shovel",
295
+ "sink",
296
+ "skateboard",
297
+ "skull",
298
+ "skyscraper",
299
+ "sleeping bag",
300
+ "smiley face",
301
+ "snail",
302
+ "snake",
303
+ "snorkel",
304
+ "snowflake",
305
+ "snowman",
306
+ "soccer ball",
307
+ "sock",
308
+ "speedboat",
309
+ "spider",
310
+ "spoon",
311
+ "spreadsheet",
312
+ "square",
313
+ "squiggle",
314
+ "squirrel",
315
+ "stairs",
316
+ "star",
317
+ "steak",
318
+ "stereo",
319
+ "stethoscope",
320
+ "stitches",
321
+ "stop sign",
322
+ "stove",
323
+ "strawberry",
324
+ "streetlight",
325
+ "string bean",
326
+ "submarine",
327
+ "suitcase",
328
+ "sun",
329
+ "swan",
330
+ "sweater",
331
+ "swing set",
332
+ "sword",
333
+ "syringe",
334
+ "table",
335
+ "teapot",
336
+ "teddy-bear",
337
+ "telephone",
338
+ "television",
339
+ "tennis racquet",
340
+ "tent",
341
+ "The Eiffel Tower",
342
+ "The Great Wall of China",
343
+ "The Mona Lisa",
344
+ "tiger",
345
+ "toaster",
346
+ "toe",
347
+ "toilet",
348
+ "tooth",
349
+ "toothbrush",
350
+ "toothpaste",
351
+ "tornado",
352
+ "tractor",
353
+ "traffic light",
354
+ "train",
355
+ "tree",
356
+ "triangle",
357
+ "trombone",
358
+ "truck",
359
+ "trumpet",
360
+ "t-shirt",
361
+ "umbrella",
362
+ "underwear",
363
+ "van",
364
+ "vase",
365
+ "violin",
366
+ "washing machine",
367
+ "watermelon",
368
+ "waterslide",
369
+ "whale",
370
+ "wheel",
371
+ "windmill",
372
+ "wine bottle",
373
+ "wine glass",
374
+ "wristwatch",
375
+ "yoga",
376
+ "zebra",
377
+ "zigzag",
378
+ ]
379
+
380
+
381
+ class QuickDraw(datasets.GeneratorBasedBuilder):
382
+ """QuickDraw Data Set"""
383
+
384
+ BUILDER_CONFIGS = [
385
+ datasets.BuilderConfig(
386
+ name="quickdraw",
387
+ version=datasets.Version("1.0.0"),
388
+ description=_DESCRIPTION,
389
+ )
390
+ ]
391
+
392
+ def _info(self):
393
+ return datasets.DatasetInfo(
394
+ description=_DESCRIPTION,
395
+ features=datasets.Features(
396
+ {
397
+ "image": datasets.Image(),
398
+ "label": datasets.features.ClassLabel(names=_CLASSES),
399
+ }
400
+ ),
401
+ supervised_keys=("image", "label"),
402
+ homepage="https://github.com/googlecreativelab/quickdraw-dataset",
403
+ citation=_CITATION,
404
+ task_templates=[
405
+ ImageClassification(
406
+ image_column="image",
407
+ label_column="label",
408
+ )
409
+ ],
410
+ )
411
+
412
+ def _split_generators(self, dl_manager):
413
+ urls_to_download = {c: _URL + c + ".npy" for c in _CLASSES}
414
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
415
+ return [
416
+ datasets.SplitGenerator(
417
+ name=datasets.Split.TRAIN,
418
+ gen_kwargs={
419
+ "filepaths": [downloaded_files[c] for c in _CLASSES],
420
+ "labels": _CLASSES
421
+ }
422
+ )
423
+ ]
424
+
425
+ def _generate_examples(self, filepaths, labels):
426
+ """This function returns the examples in the raw form."""
427
+
428
+ for filepath, label in zip(filepaths, labels):
429
+ data = np.load(filepath, mmap_mode='r')
430
+
431
+ for i, ex in enumerate(data):
432
+ yield i, {"image": ex.reshape(28, 28), "label": label}