Datasets:

Languages:
English
ArXiv:
License:
mariosasko commited on
Commit
ff61db4
1 Parent(s): 655c620

Add QuickDraw dataset (#3592)

Browse files

* Add QuickDraw dataset

* Style

* Add infos file, dummy data, improve script

* Add info and dummy data

* Test readme

* Finish readme

* Delete generate_dummy.py

* Remove whitespace

Commit from https://github.com/huggingface/datasets/commit/1c1eaf96d5ef4623e36c9124d49e88ab476dd655

README.md ADDED
@@ -0,0 +1,709 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - machine-generated
4
+ language_creators:
5
+ - crowdsourced
6
+ languages:
7
+ - en
8
+ licenses:
9
+ - cc-by-4.0
10
+ multilinguality:
11
+ - monolingual
12
+ size_categories:
13
+ - 10M<n<100M
14
+ source_datasets:
15
+ - original
16
+ task_categories:
17
+ - image-classification
18
+ task_ids:
19
+ - multi-class-image-classification
20
+ paperswithcode_id: quick-draw-dataset
21
+ pretty_name: Quick, Draw!
22
+ ---
23
+
24
+ # Dataset Card for Quick, Draw!
25
+
26
+ ## Table of Contents
27
+ - [Table of Contents](#table-of-contents)
28
+ - [Dataset Description](#dataset-description)
29
+ - [Dataset Summary](#dataset-summary)
30
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
31
+ - [Languages](#languages)
32
+ - [Dataset Structure](#dataset-structure)
33
+ - [Data Instances](#data-instances)
34
+ - [Data Fields](#data-fields)
35
+ - [Data Splits](#data-splits)
36
+ - [Dataset Creation](#dataset-creation)
37
+ - [Curation Rationale](#curation-rationale)
38
+ - [Source Data](#source-data)
39
+ - [Annotations](#annotations)
40
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
41
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
42
+ - [Social Impact of Dataset](#social-impact-of-dataset)
43
+ - [Discussion of Biases](#discussion-of-biases)
44
+ - [Other Known Limitations](#other-known-limitations)
45
+ - [Additional Information](#additional-information)
46
+ - [Dataset Curators](#dataset-curators)
47
+ - [Licensing Information](#licensing-information)
48
+ - [Citation Information](#citation-information)
49
+ - [Contributions](#contributions)
50
+
51
+ ## Dataset Description
52
+
53
+ - **Homepage:** [Quick, Draw! homepage](https://quickdraw.withgoogle.com/data)
54
+ - **Repository:** [Quick, Draw! repository](https://github.com/googlecreativelab/quickdraw-dataset)
55
+ - **Paper:** [A Neural Representation of Sketch Drawings](https://arxiv.org/abs/1704.03477v4)
56
+ - **Leaderboard:** [Quick, Draw! Doodle Recognition Challenge](https://www.kaggle.com/competitions/quickdraw-doodle-recognition/leaderboard)
57
+ - **Point of Contact:** [Quick, Draw! support](mailto:quickdraw-support@google.com)
58
+
59
+ ### Dataset Summary
60
+
61
+ The Quick Draw Dataset is a collection of 50 million drawings across 345 categories, contributed by players of the game Quick, Draw!. The drawings were captured as timestamped vectors, tagged with metadata including what the player was asked to draw and in which country the player was located.
62
+
63
+ ### Supported Tasks and Leaderboards
64
+
65
+ - `image-classification`: The goal of this task is to classify a given sketch into one of 345 classes.
66
+ The (closed) leaderboard for this task is available [here](https://www.kaggle.com/competitions/quickdraw-doodle-recognition/leaderboard).
67
+
68
+ ### Languages
69
+
70
+ English.
71
+
72
+ ## Dataset Structure
73
+
74
+ ### Data Instances
75
+
76
+ #### `raw`
77
+
78
+ A data point comprises a drawing and its metadata.
79
+
80
+ ```
81
+ {
82
+ 'key_id': '5475678961008640',
83
+ 'word': 0,
84
+ 'recognized': True,
85
+ 'timestamp': datetime.datetime(2017, 3, 28, 13, 28, 0, 851730),
86
+ 'countrycode': 'MY',
87
+ 'drawing': {
88
+ 'x': [[379.0, 380.0, 381.0, 381.0, 381.0, 381.0, 382.0], [362.0, 368.0, 375.0, 380.0, 388.0, 393.0, 399.0, 404.0, 409.0, 410.0, 410.0, 405.0, 397.0, 392.0, 384.0, 377.0, 370.0, 363.0, 356.0, 348.0, 342.0, 336.0, 333.0], ..., [477.0, 473.0, 471.0, 469.0, 468.0, 466.0, 464.0, 462.0, 461.0, 469.0, 475.0, 483.0, 491.0, 499.0, 510.0, 521.0, 531.0, 540.0, 548.0, 558.0, 566.0, 576.0, 583.0, 590.0, 595.0, 598.0, 597.0, 596.0, 594.0, 592.0, 590.0, 589.0, 588.0, 586.0]],
89
+ 'y': [[1.0, 7.0, 15.0, 21.0, 27.0, 32.0, 32.0], [17.0, 17.0, 17.0, 17.0, 16.0, 16.0, 16.0, 16.0, 18.0, 23.0, 29.0, 32.0, 32.0, 32.0, 29.0, 27.0, 25.0, 23.0, 21.0, 19.0, 17.0, 16.0, 14.0], ..., [151.0, 146.0, 139.0, 131.0, 125.0, 119.0, 113.0, 107.0, 102.0, 99.0, 98.0, 98.0, 98.0, 98.0, 98.0, 98.0, 98.0, 98.0, 98.0, 98.0, 98.0, 100.0, 102.0, 104.0, 105.0, 110.0, 115.0, 121.0, 126.0, 131.0, 137.0, 142.0, 148.0, 150.0]],
90
+ 't': [[0, 84, 100, 116, 132, 148, 260], [573, 636, 652, 660, 676, 684, 701, 724, 796, 838, 860, 956, 973, 979, 989, 995, 1005, 1012, 1020, 1028, 1036, 1053, 1118], ..., [8349, 8446, 8468, 8484, 8500, 8516, 8541, 8557, 8573, 8685, 8693, 8702, 8710, 8718, 8724, 8732, 8741, 8748, 8757, 8764, 8773, 8780, 8788, 8797, 8804, 8965, 8996, 9029, 9045, 9061, 9076, 9092, 9109, 9167]]
91
+ }
92
+ }
93
+ ```
94
+
95
+ #### `preprocessed_simplified_drawings`
96
+
97
+ The simplified version of the dataset generated from the `raw` data with the simplified vectors, removed timing information, and the data positioned and scaled into a 256x256 region.
98
+ The simplification process was:
99
+ 1.Align the drawing to the top-left corner, to have minimum values of 0.
100
+ 2.Uniformly scale the drawing, to have a maximum value of 255.
101
+ 3.Resample all strokes with a 1 pixel spacing.
102
+ 4.Simplify all strokes using the [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm) with an epsilon value of 2.0.
103
+
104
+ ```
105
+ {
106
+ 'key_id': '5475678961008640',
107
+ 'word': 0,
108
+ 'recognized': True,
109
+ 'timestamp': datetime.datetime(2017, 3, 28, 15, 28),
110
+ 'countrycode': 'MY',
111
+ 'drawing': {
112
+ 'x': [[31, 32], [27, 37, 38, 35, 21], [25, 28, 38, 39], [33, 34, 32], [5, 188, 254, 251, 241, 185, 45, 9, 0], [35, 35, 43, 125, 126], [35, 76, 80, 77], [53, 50, 54, 80, 78]],
113
+ 'y': [[0, 7], [4, 4, 6, 7, 3], [5, 10, 10, 7], [4, 33, 44], [50, 50, 54, 83, 86, 90, 86, 77, 52], [85, 91, 92, 96, 90], [35, 37, 41, 47], [34, 23, 22, 23, 34]]
114
+ }
115
+ }
116
+ ```
117
+
118
+ #### `preprocessed_bitmaps` (default configuration)
119
+
120
+ This configuration contains the 28x28 grayscale bitmap images that were generated from the simplified data, but are aligned to the center of the drawing's bounding box rather than the top-left corner. The code that was used for generation is available [here](https://github.com/googlecreativelab/quickdraw-dataset/issues/19#issuecomment-402247262).
121
+
122
+ ```
123
+ {
124
+ 'image': <PIL.PngImagePlugin.PngImageFile image mode=L size=28x28 at 0x10B5B102828>,
125
+ 'label': 0
126
+ }
127
+ ```
128
+
129
+ #### `sketch_rnn` and `sketch_rnn_full`
130
+
131
+ The `sketch_rnn_full` configuration stores the data in the format suitable for inputs into a recurrent neural network and was used for for training the [Sketch-RNN](https://arxiv.org/abs/1704.03477) model. Unlike `sketch_rnn` where the samples have been randomly selected from each category, the `sketch_rnn_full` configuration contains the full data for each category.
132
+
133
+ ```
134
+ {
135
+ 'word': 0,
136
+ 'drawing': [[132, 0, 0], [23, 4, 0], [61, 1, 0], [76, 0, 0], [22, -4, 0], [152, 0, 0], [50, -5, 0], [36, -10, 0], [8, 26, 0], [0, 69, 0], [-2, 11, 0], [-8, 10, 0], [-56, 24, 0], [-23, 14, 0], [-99, 40, 0], [-45, 6, 0], [-21, 6, 0], [-170, 2, 0], [-81, 0, 0], [-29, -9, 0], [-94, -19, 0], [-48, -24, 0], [-6, -16, 0], [2, -36, 0], [7, -29, 0], [23, -45, 0], [13, -6, 0], [41, -8, 0], [42, -2, 1], [392, 38, 0], [2, 19, 0], [11, 33, 0], [13, 0, 0], [24, -9, 0], [26, -27, 0], [0, -14, 0], [-8, -10, 0], [-18, -5, 0], [-14, 1, 0], [-23, 4, 0], [-21, 12, 1], [-152, 18, 0], [10, 46, 0], [26, 6, 0], [38, 0, 0], [31, -2, 0], [7, -2, 0], [4, -6, 0], [-10, -21, 0], [-2, -33, 0], [-6, -11, 0], [-46, 1, 0], [-39, 18, 0], [-19, 4, 1], [-122, 0, 0], [-2, 38, 0], [4, 16, 0], [6, 4, 0], [78, 0, 0], [4, -8, 0], [-8, -36, 0], [0, -22, 0], [-6, -2, 0], [-32, 14, 0], [-58, 13, 1], [-96, -12, 0], [-10, 27, 0], [2, 32, 0], [102, 0, 0], [1, -7, 0], [-27, -17, 0], [-4, -6, 0], [-1, -34, 0], [-64, 8, 1], [129, -138, 0], [-108, 0, 0], [-8, 12, 0], [-1, 15, 0], [12, 15, 0], [20, 5, 0], [61, -3, 0], [24, 6, 0], [19, 0, 0], [5, -4, 0], [2, 14, 1]]
137
+ }
138
+ ```
139
+
140
+ ### Data Fields
141
+
142
+ #### `raw`
143
+
144
+ - `key_id`: A unique identifier across all drawings.
145
+ - `word`: Category the player was prompted to draw.
146
+ - `recognized`: Whether the word was recognized by the game.
147
+ - `timestamp`: When the drawing was created.
148
+ - `countrycode`: A two letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)) of where the player was located.
149
+ - `drawing`: A dictionary where `x` and `y` are the pixel coordinates, and `t` is the time in milliseconds since the first point. `x` and `y` are real-valued while `t` is an integer. `x`, `y` and `t` match in lenght and are represented as lists of lists where each sublist corresponds to a single stroke. The raw drawings can have vastly different bounding boxes and number of points due to the different devices used for display and input.
150
+
151
+ #### `preprocessed_simplified_drawings`
152
+
153
+ - `key_id`: A unique identifier across all drawings.
154
+ - `word`: Category the player was prompted to draw.
155
+ - `recognized`: Whether the word was recognized by the game.
156
+ - `timestamp`: When the drawing was created.
157
+ - `countrycode`: A two letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)) of where the player was located.
158
+ - `drawing`: A simplified drawing represented as a dictionary where `x` and `y` are the pixel coordinates. The simplification processed is described in the `Data Instances` section.
159
+
160
+ #### `preprocessed_bitmaps` (default configuration)
161
+
162
+ - `image`: A `PIL.Image.Image` object containing the 28x28 grayscale bitmap. Note that when accessing the image column: `dataset[0]["image"]` the image file is automatically decoded. Decoding of a large number of image files might take a significant amount of time. Thus it is important to first query the sample index before the `"image"` column, *i.e.* `dataset[0]["image"]` should **always** be preferred over `dataset["image"][0]`.
163
+ - `label`: Category the player was prompted to draw.
164
+
165
+ <details>
166
+ <summary>
167
+ Click here to see the full class labels mapping:
168
+ </summary>
169
+
170
+ |id|class|
171
+ |---|---|
172
+ |0|aircraft carrier|
173
+ |1|airplane|
174
+ |2|alarm clock|
175
+ |3|ambulance|
176
+ |4|angel|
177
+ |5|animal migration|
178
+ |6|ant|
179
+ |7|anvil|
180
+ |8|apple|
181
+ |9|arm|
182
+ |10|asparagus|
183
+ |11|axe|
184
+ |12|backpack|
185
+ |13|banana|
186
+ |14|bandage|
187
+ |15|barn|
188
+ |16|baseball bat|
189
+ |17|baseball|
190
+ |18|basket|
191
+ |19|basketball|
192
+ |20|bat|
193
+ |21|bathtub|
194
+ |22|beach|
195
+ |23|bear|
196
+ |24|beard|
197
+ |25|bed|
198
+ |26|bee|
199
+ |27|belt|
200
+ |28|bench|
201
+ |29|bicycle|
202
+ |30|binoculars|
203
+ |31|bird|
204
+ |32|birthday cake|
205
+ |33|blackberry|
206
+ |34|blueberry|
207
+ |35|book|
208
+ |36|boomerang|
209
+ |37|bottlecap|
210
+ |38|bowtie|
211
+ |39|bracelet|
212
+ |40|brain|
213
+ |41|bread|
214
+ |42|bridge|
215
+ |43|broccoli|
216
+ |44|broom|
217
+ |45|bucket|
218
+ |46|bulldozer|
219
+ |47|bus|
220
+ |48|bush|
221
+ |49|butterfly|
222
+ |50|cactus|
223
+ |51|cake|
224
+ |52|calculator|
225
+ |53|calendar|
226
+ |54|camel|
227
+ |55|camera|
228
+ |56|camouflage|
229
+ |57|campfire|
230
+ |58|candle|
231
+ |59|cannon|
232
+ |60|canoe|
233
+ |61|car|
234
+ |62|carrot|
235
+ |63|castle|
236
+ |64|cat|
237
+ |65|ceiling fan|
238
+ |66|cell phone|
239
+ |67|cello|
240
+ |68|chair|
241
+ |69|chandelier|
242
+ |70|church|
243
+ |71|circle|
244
+ |72|clarinet|
245
+ |73|clock|
246
+ |74|cloud|
247
+ |75|coffee cup|
248
+ |76|compass|
249
+ |77|computer|
250
+ |78|cookie|
251
+ |79|cooler|
252
+ |80|couch|
253
+ |81|cow|
254
+ |82|crab|
255
+ |83|crayon|
256
+ |84|crocodile|
257
+ |85|crown|
258
+ |86|cruise ship|
259
+ |87|cup|
260
+ |88|diamond|
261
+ |89|dishwasher|
262
+ |90|diving board|
263
+ |91|dog|
264
+ |92|dolphin|
265
+ |93|donut|
266
+ |94|door|
267
+ |95|dragon|
268
+ |96|dresser|
269
+ |97|drill|
270
+ |98|drums|
271
+ |99|duck|
272
+ |100|dumbbell|
273
+ |101|ear|
274
+ |102|elbow|
275
+ |103|elephant|
276
+ |104|envelope|
277
+ |105|eraser|
278
+ |106|eye|
279
+ |107|eyeglasses|
280
+ |108|face|
281
+ |109|fan|
282
+ |110|feather|
283
+ |111|fence|
284
+ |112|finger|
285
+ |113|fire hydrant|
286
+ |114|fireplace|
287
+ |115|firetruck|
288
+ |116|fish|
289
+ |117|flamingo|
290
+ |118|flashlight|
291
+ |119|flip flops|
292
+ |120|floor lamp|
293
+ |121|flower|
294
+ |122|flying saucer|
295
+ |123|foot|
296
+ |124|fork|
297
+ |125|frog|
298
+ |126|frying pan|
299
+ |127|garden hose|
300
+ |128|garden|
301
+ |129|giraffe|
302
+ |130|goatee|
303
+ |131|golf club|
304
+ |132|grapes|
305
+ |133|grass|
306
+ |134|guitar|
307
+ |135|hamburger|
308
+ |136|hammer|
309
+ |137|hand|
310
+ |138|harp|
311
+ |139|hat|
312
+ |140|headphones|
313
+ |141|hedgehog|
314
+ |142|helicopter|
315
+ |143|helmet|
316
+ |144|hexagon|
317
+ |145|hockey puck|
318
+ |146|hockey stick|
319
+ |147|horse|
320
+ |148|hospital|
321
+ |149|hot air balloon|
322
+ |150|hot dog|
323
+ |151|hot tub|
324
+ |152|hourglass|
325
+ |153|house plant|
326
+ |154|house|
327
+ |155|hurricane|
328
+ |156|ice cream|
329
+ |157|jacket|
330
+ |158|jail|
331
+ |159|kangaroo|
332
+ |160|key|
333
+ |161|keyboard|
334
+ |162|knee|
335
+ |163|knife|
336
+ |164|ladder|
337
+ |165|lantern|
338
+ |166|laptop|
339
+ |167|leaf|
340
+ |168|leg|
341
+ |169|light bulb|
342
+ |170|lighter|
343
+ |171|lighthouse|
344
+ |172|lightning|
345
+ |173|line|
346
+ |174|lion|
347
+ |175|lipstick|
348
+ |176|lobster|
349
+ |177|lollipop|
350
+ |178|mailbox|
351
+ |179|map|
352
+ |180|marker|
353
+ |181|matches|
354
+ |182|megaphone|
355
+ |183|mermaid|
356
+ |184|microphone|
357
+ |185|microwave|
358
+ |186|monkey|
359
+ |187|moon|
360
+ |188|mosquito|
361
+ |189|motorbike|
362
+ |190|mountain|
363
+ |191|mouse|
364
+ |192|moustache|
365
+ |193|mouth|
366
+ |194|mug|
367
+ |195|mushroom|
368
+ |196|nail|
369
+ |197|necklace|
370
+ |198|nose|
371
+ |199|ocean|
372
+ |200|octagon|
373
+ |201|octopus|
374
+ |202|onion|
375
+ |203|oven|
376
+ |204|owl|
377
+ |205|paint can|
378
+ |206|paintbrush|
379
+ |207|palm tree|
380
+ |208|panda|
381
+ |209|pants|
382
+ |210|paper clip|
383
+ |211|parachute|
384
+ |212|parrot|
385
+ |213|passport|
386
+ |214|peanut|
387
+ |215|pear|
388
+ |216|peas|
389
+ |217|pencil|
390
+ |218|penguin|
391
+ |219|piano|
392
+ |220|pickup truck|
393
+ |221|picture frame|
394
+ |222|pig|
395
+ |223|pillow|
396
+ |224|pineapple|
397
+ |225|pizza|
398
+ |226|pliers|
399
+ |227|police car|
400
+ |228|pond|
401
+ |229|pool|
402
+ |230|popsicle|
403
+ |231|postcard|
404
+ |232|potato|
405
+ |233|power outlet|
406
+ |234|purse|
407
+ |235|rabbit|
408
+ |236|raccoon|
409
+ |237|radio|
410
+ |238|rain|
411
+ |239|rainbow|
412
+ |240|rake|
413
+ |241|remote control|
414
+ |242|rhinoceros|
415
+ |243|rifle|
416
+ |244|river|
417
+ |245|roller coaster|
418
+ |246|rollerskates|
419
+ |247|sailboat|
420
+ |248|sandwich|
421
+ |249|saw|
422
+ |250|saxophone|
423
+ |251|school bus|
424
+ |252|scissors|
425
+ |253|scorpion|
426
+ |254|screwdriver|
427
+ |255|sea turtle|
428
+ |256|see saw|
429
+ |257|shark|
430
+ |258|sheep|
431
+ |259|shoe|
432
+ |260|shorts|
433
+ |261|shovel|
434
+ |262|sink|
435
+ |263|skateboard|
436
+ |264|skull|
437
+ |265|skyscraper|
438
+ |266|sleeping bag|
439
+ |267|smiley face|
440
+ |268|snail|
441
+ |269|snake|
442
+ |270|snorkel|
443
+ |271|snowflake|
444
+ |272|snowman|
445
+ |273|soccer ball|
446
+ |274|sock|
447
+ |275|speedboat|
448
+ |276|spider|
449
+ |277|spoon|
450
+ |278|spreadsheet|
451
+ |279|square|
452
+ |280|squiggle|
453
+ |281|squirrel|
454
+ |282|stairs|
455
+ |283|star|
456
+ |284|steak|
457
+ |285|stereo|
458
+ |286|stethoscope|
459
+ |287|stitches|
460
+ |288|stop sign|
461
+ |289|stove|
462
+ |290|strawberry|
463
+ |291|streetlight|
464
+ |292|string bean|
465
+ |293|submarine|
466
+ |294|suitcase|
467
+ |295|sun|
468
+ |296|swan|
469
+ |297|sweater|
470
+ |298|swing set|
471
+ |299|sword|
472
+ |300|syringe|
473
+ |301|t-shirt|
474
+ |302|table|
475
+ |303|teapot|
476
+ |304|teddy-bear|
477
+ |305|telephone|
478
+ |306|television|
479
+ |307|tennis racquet|
480
+ |308|tent|
481
+ |309|The Eiffel Tower|
482
+ |310|The Great Wall of China|
483
+ |311|The Mona Lisa|
484
+ |312|tiger|
485
+ |313|toaster|
486
+ |314|toe|
487
+ |315|toilet|
488
+ |316|tooth|
489
+ |317|toothbrush|
490
+ |318|toothpaste|
491
+ |319|tornado|
492
+ |320|tractor|
493
+ |321|traffic light|
494
+ |322|train|
495
+ |323|tree|
496
+ |324|triangle|
497
+ |325|trombone|
498
+ |326|truck|
499
+ |327|trumpet|
500
+ |328|umbrella|
501
+ |329|underwear|
502
+ |330|van|
503
+ |331|vase|
504
+ |332|violin|
505
+ |333|washing machine|
506
+ |334|watermelon|
507
+ |335|waterslide|
508
+ |336|whale|
509
+ |337|wheel|
510
+ |338|windmill|
511
+ |339|wine bottle|
512
+ |340|wine glass|
513
+ |341|wristwatch|
514
+ |342|yoga|
515
+ |343|zebra|
516
+ |344|zigzag|
517
+
518
+ </details>
519
+
520
+ #### `sketch_rnn` and `sketch_rnn_full`
521
+
522
+ - `word`: Category the player was prompted to draw.
523
+ - `drawing`: An array of strokes. Strokes are represented as 3-tuples consisting of x-offset, y-offset, and a binary variable which is 1 if the pen is lifted between this position and the next, and 0 otherwise.
524
+
525
+ <details>
526
+ <summary>
527
+ Click here to see the code for visualizing drawings in Jupyter Notebook or Google Colab:
528
+ </summary>
529
+
530
+ ```python
531
+ import numpy as np
532
+ import svgwrite # pip install svgwrite
533
+ from IPython.display import SVG, display
534
+
535
+ def draw_strokes(drawing, factor=0.045):
536
+ """Displays vector drawing as SVG.
537
+
538
+ Args:
539
+ drawing: a list of strokes represented as 3-tuples
540
+ factor: scaling factor. The smaller the scaling factor, the bigger the SVG picture and vice versa.
541
+
542
+ """
543
+ def get_bounds(data, factor):
544
+ """Return bounds of data."""
545
+ min_x = 0
546
+ max_x = 0
547
+ min_y = 0
548
+ max_y = 0
549
+
550
+ abs_x = 0
551
+ abs_y = 0
552
+ for i in range(len(data)):
553
+ x = float(data[i, 0]) / factor
554
+ y = float(data[i, 1]) / factor
555
+ abs_x += x
556
+ abs_y += y
557
+ min_x = min(min_x, abs_x)
558
+ min_y = min(min_y, abs_y)
559
+ max_x = max(max_x, abs_x)
560
+ max_y = max(max_y, abs_y)
561
+
562
+ return (min_x, max_x, min_y, max_y)
563
+
564
+ data = np.array(drawing)
565
+ min_x, max_x, min_y, max_y = get_bounds(data, factor)
566
+ dims = (50 + max_x - min_x, 50 + max_y - min_y)
567
+ dwg = svgwrite.Drawing(size=dims)
568
+ dwg.add(dwg.rect(insert=(0, 0), size=dims,fill='white'))
569
+ lift_pen = 1
570
+ abs_x = 25 - min_x
571
+ abs_y = 25 - min_y
572
+ p = "M%s,%s " % (abs_x, abs_y)
573
+ command = "m"
574
+ for i in range(len(data)):
575
+ if (lift_pen == 1):
576
+ command = "m"
577
+ elif (command != "l"):
578
+ command = "l"
579
+ else:
580
+ command = ""
581
+ x = float(data[i,0])/factor
582
+ y = float(data[i,1])/factor
583
+ lift_pen = data[i, 2]
584
+ p += command+str(x)+","+str(y)+" "
585
+ the_color = "black"
586
+ stroke_width = 1
587
+ dwg.add(dwg.path(p).stroke(the_color,stroke_width).fill("none"))
588
+ display(SVG(dwg.tostring()))
589
+ ```
590
+
591
+ </details>
592
+
593
+
594
+ > **Note**: Sketch-RNN takes for input strokes represented as 5-tuples with drawings padded to a common maximum length and prefixed by the special start token `[0, 0, 1, 0, 0]`. The 5-tuple representation consists of x-offset, y-offset, and p_1, p_2, p_3, a binary one-hot vector of 3 possible pen states: pen down, pen up, end of sketch. More precisely, the first two elements are the offset distance in the x and y directions of the pen from the previous point. The last 3 elements represents a binary one-hot vector of 3 possible states. The first pen state, p1, indicates that the pen is currently touching the paper, and that a line will be drawn connecting the next point with the current point. The second pen state, p2, indicates that the pen will be lifted from the paper after the current point, and that no line will be drawn next. The final pen state, p3, indicates that the drawing has ended, and subsequent points, including the current point, will not be rendered.
595
+ ><details>
596
+ > <summary>
597
+ > Click here to see the code for converting drawings to Sketch-RNN input format:
598
+ > </summary>
599
+ >
600
+ > ```python
601
+ > def to_sketch_rnn_format(drawing, max_len):
602
+ > """Converts a drawing to Sketch-RNN input format.
603
+ >
604
+ > Args:
605
+ > drawing: a list of strokes represented as 3-tuples
606
+ > max_len: maximum common length of all drawings
607
+ >
608
+ > Returns:
609
+ > NumPy array
610
+ > """
611
+ > drawing = np.array(drawing)
612
+ > result = np.zeros((max_len, 5), dtype=float)
613
+ > l = len(drawing)
614
+ > assert l <= max_len
615
+ > result[0:l, 0:2] = drawing[:, 0:2]
616
+ > result[0:l, 3] = drawing[:, 2]
617
+ > result[0:l, 2] = 1 - result[0:l, 3]
618
+ > result[l:, 4] = 1
619
+ > # Prepend special start token
620
+ > result = np.vstack([[0, 0, 1, 0, 0], result])
621
+ > return result
622
+ > ```
623
+ >
624
+ ></details>
625
+
626
+ ### Data Splits
627
+
628
+ In the configurations `raw`, `preprocessed_simplified_drawings` and `preprocessed_bitamps` (default configuration), all the data is contained in the training set, which has 50426266 examples.
629
+
630
+ `sketch_rnn` and `sketch_rnn_full` have the data split into training, validation and test split. In the `sketch_rnn` configuration, 75K samples (70K Training, 2.5K Validation, 2.5K Test) have been randomly selected from each category. Therefore, the training set contains 24150000 examples, the validation set 862500 examples and the test set 862500 examples. The `sketch_rnn_full` configuration has the full (training) data for each category, which leads to the training set having 43988874 examples, the validation set 862500 and the test set 862500 examples.
631
+
632
+ ## Dataset Creation
633
+
634
+ ### Curation Rationale
635
+
636
+ From the GitHub repository:
637
+
638
+ > The Quick Draw Dataset is a collection of 50 million drawings across [345 categories](categories.txt), contributed by players of the game [Quick, Draw!](https://quickdraw.withgoogle.com). The drawings were captured as timestamped vectors, tagged with metadata including what the player was asked to draw and in which country the player was located. You can browse the recognized drawings on [quickdraw.withgoogle.com/data](https://quickdraw.withgoogle.com/data).
639
+ >
640
+ > We're sharing them here for developers, researchers, and artists to explore, study, and learn from
641
+
642
+ ### Source Data
643
+
644
+ #### Initial Data Collection and Normalization
645
+
646
+ This dataset contains vector drawings obtained from [Quick, Draw!](https://quickdraw.withgoogle.com/), an online game where the players are asked to draw objects belonging to a particular object class in less than 20 seconds.
647
+
648
+ #### Who are the source language producers?
649
+
650
+ The participants in the [Quick, Draw!](https://quickdraw.withgoogle.com/) game.
651
+
652
+ ### Annotations
653
+
654
+ #### Annotation process
655
+
656
+ The annotations are machine-generated and match the category the player was prompted to draw.
657
+
658
+ #### Who are the annotators?
659
+
660
+ The annotations are machine-generated.
661
+
662
+ ### Personal and Sensitive Information
663
+
664
+ Some sketches are known to be problematic (see https://github.com/googlecreativelab/quickdraw-dataset/issues/74 and https://github.com/googlecreativelab/quickdraw-dataset/issues/18).
665
+
666
+ ## Considerations for Using the Data
667
+
668
+ ### Social Impact of Dataset
669
+
670
+ [More Information Needed]
671
+
672
+ ### Discussion of Biases
673
+
674
+ [More Information Needed]
675
+
676
+ ### Other Known Limitations
677
+
678
+ ## Additional Information
679
+
680
+ ### Dataset Curators
681
+
682
+ Jonas Jongejan, Henry Rowley, Takashi Kawashima, Jongmin Kim and Nick Fox-Gieg.
683
+
684
+ ### Licensing Information
685
+
686
+ The data is made available by Google, Inc. under the [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/) license.
687
+
688
+ ### Citation Information
689
+
690
+ ```bibtex
691
+ @article{DBLP:journals/corr/HaE17,
692
+ author = {David Ha and
693
+ Douglas Eck},
694
+ title = {A Neural Representation of Sketch Drawings},
695
+ journal = {CoRR},
696
+ volume = {abs/1704.03477},
697
+ year = {2017},
698
+ url = {http://arxiv.org/abs/1704.03477},
699
+ archivePrefix = {arXiv},
700
+ eprint = {1704.03477},
701
+ timestamp = {Mon, 13 Aug 2018 16:48:30 +0200},
702
+ biburl = {https://dblp.org/rec/bib/journals/corr/HaE17},
703
+ bibsource = {dblp computer science bibliography, https://dblp.org}
704
+ }
705
+ ```
706
+
707
+ ### Contributions
708
+
709
+ Thanks to [@mariosasko](https://github.com/mariosasko) for adding this dataset.
dataset_infos.json ADDED
The diff for this file is too large to render. See raw diff
 
dummy/preprocessed_bitmaps/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59b69fcd6da440330622a095d6c86539355f80658c0a307da29f711d02a68438
3
+ size 84726
dummy/preprocessed_simplified_drawings/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:39e44207fbf8657364f4cd331385fd20dd92e7fcea68d24cba9f6b284c012ab7
3
+ size 81293
dummy/raw/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0c968655ace72b2b19c0561971d4144b20551adca8b4981f5c897c023d6b0af9
3
+ size 372128
dummy/sketch_rnn/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:30f2173760d47802b4d5df629a2aae01d9ac47cbdf74c60fd51639c342be85eb
3
+ size 321584
dummy/sketch_rnn_full/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c1a1724e7b043f151739a2340ee15a347a7167bc7d8d22803579e6e1fee8e55
3
+ size 335384
quickdraw.py ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Quickdraw dataset"""
16
+
17
+ import io
18
+ import json
19
+ import os
20
+ import struct
21
+ import textwrap
22
+ from datetime import datetime
23
+
24
+ import numpy as np
25
+
26
+ import datasets
27
+ from datasets.tasks import ImageClassification
28
+
29
+
30
+ _CITATION = """\
31
+ @article{DBLP:journals/corr/HaE17,
32
+ author = {David Ha and
33
+ Douglas Eck},
34
+ title = {A Neural Representation of Sketch Drawings},
35
+ journal = {CoRR},
36
+ volume = {abs/1704.03477},
37
+ year = {2017},
38
+ url = {http://arxiv.org/abs/1704.03477},
39
+ archivePrefix = {arXiv},
40
+ eprint = {1704.03477},
41
+ timestamp = {Mon, 13 Aug 2018 16:48:30 +0200},
42
+ biburl = {https://dblp.org/rec/bib/journals/corr/HaE17},
43
+ bibsource = {dblp computer science bibliography, https://dblp.org}
44
+ }
45
+ """
46
+
47
+ _DESCRIPTION = """\
48
+ The Quick Draw Dataset is a collection of 50 million drawings across 345 categories, contributed by players of the game Quick, Draw!.
49
+ The drawings were captured as timestamped vectors, tagged with metadata including what the player was asked to draw and in which country the player was located.
50
+ """
51
+
52
+ _HOMEPAGE = "https://quickdraw.withgoogle.com/data"
53
+
54
+ _LICENSE = "CC BY 4.0"
55
+
56
+ _NAMES = """\
57
+ aircraft carrier,airplane,alarm clock,ambulance,angel
58
+ animal migration,ant,anvil,apple,arm
59
+ asparagus,axe,backpack,banana,bandage
60
+ barn,baseball bat,baseball,basket,basketball
61
+ bat,bathtub,beach,bear,beard
62
+ bed,bee,belt,bench,bicycle
63
+ binoculars,bird,birthday cake,blackberry,blueberry
64
+ book,boomerang,bottlecap,bowtie,bracelet
65
+ brain,bread,bridge,broccoli,broom
66
+ bucket,bulldozer,bus,bush,butterfly
67
+ cactus,cake,calculator,calendar,camel
68
+ camera,camouflage,campfire,candle,cannon
69
+ canoe,car,carrot,castle,cat
70
+ ceiling fan,cell phone,cello,chair,chandelier
71
+ church,circle,clarinet,clock,cloud
72
+ coffee cup,compass,computer,cookie,cooler
73
+ couch,cow,crab,crayon,crocodile
74
+ crown,cruise ship,cup,diamond,dishwasher
75
+ diving board,dog,dolphin,donut,door
76
+ dragon,dresser,drill,drums,duck
77
+ dumbbell,ear,elbow,elephant,envelope
78
+ eraser,eye,eyeglasses,face,fan
79
+ feather,fence,finger,fire hydrant,fireplace
80
+ firetruck,fish,flamingo,flashlight,flip flops
81
+ floor lamp,flower,flying saucer,foot,fork
82
+ frog,frying pan,garden hose,garden,giraffe
83
+ goatee,golf club,grapes,grass,guitar
84
+ hamburger,hammer,hand,harp,hat
85
+ headphones,hedgehog,helicopter,helmet,hexagon
86
+ hockey puck,hockey stick,horse,hospital,hot air balloon
87
+ hot dog,hot tub,hourglass,house plant,house
88
+ hurricane,ice cream,jacket,jail,kangaroo
89
+ key,keyboard,knee,knife,ladder
90
+ lantern,laptop,leaf,leg,light bulb
91
+ lighter,lighthouse,lightning,line,lion
92
+ lipstick,lobster,lollipop,mailbox,map
93
+ marker,matches,megaphone,mermaid,microphone
94
+ microwave,monkey,moon,mosquito,motorbike
95
+ mountain,mouse,moustache,mouth,mug
96
+ mushroom,nail,necklace,nose,ocean
97
+ octagon,octopus,onion,oven,owl
98
+ paint can,paintbrush,palm tree,panda,pants
99
+ paper clip,parachute,parrot,passport,peanut
100
+ pear,peas,pencil,penguin,piano
101
+ pickup truck,picture frame,pig,pillow,pineapple
102
+ pizza,pliers,police car,pond,pool
103
+ popsicle,postcard,potato,power outlet,purse
104
+ rabbit,raccoon,radio,rain,rainbow
105
+ rake,remote control,rhinoceros,rifle,river
106
+ roller coaster,rollerskates,sailboat,sandwich,saw
107
+ saxophone,school bus,scissors,scorpion,screwdriver
108
+ sea turtle,see saw,shark,sheep,shoe
109
+ shorts,shovel,sink,skateboard,skull
110
+ skyscraper,sleeping bag,smiley face,snail,snake
111
+ snorkel,snowflake,snowman,soccer ball,sock
112
+ speedboat,spider,spoon,spreadsheet,square
113
+ squiggle,squirrel,stairs,star,steak
114
+ stereo,stethoscope,stitches,stop sign,stove
115
+ strawberry,streetlight,string bean,submarine,suitcase
116
+ sun,swan,sweater,swing set,sword
117
+ syringe,t-shirt,table,teapot,teddy-bear
118
+ telephone,television,tennis racquet,tent,The Eiffel Tower
119
+ The Great Wall of China,The Mona Lisa,tiger,toaster,toe
120
+ toilet,tooth,toothbrush,toothpaste,tornado
121
+ tractor,traffic light,train,tree,triangle
122
+ trombone,truck,trumpet,umbrella,underwear
123
+ van,vase,violin,washing machine,watermelon
124
+ waterslide,whale,wheel,windmill,wine bottle
125
+ wine glass,wristwatch,yoga,zebra,zigzag
126
+ """
127
+ _NAMES = [name for line in _NAMES.strip().splitlines() for name in line.strip().split(",")]
128
+
129
+ _CONFIG_NAME_TO_BASE_URL = {
130
+ "raw": "https://storage.googleapis.com/quickdraw_dataset/full/raw/{}.ndjson",
131
+ "preprocessed_simplified_drawings": "https://storage.googleapis.com/quickdraw_dataset/full/binary/{}.bin",
132
+ "preprocessed_bitmaps": "https://storage.googleapis.com/quickdraw_dataset/full/numpy_bitmap/{}.npy",
133
+ "sketch_rnn": "https://storage.googleapis.com/quickdraw_dataset/sketchrnn/{}.npz",
134
+ "sketch_rnn_full": "https://storage.googleapis.com/quickdraw_dataset/sketchrnn/{}.full.npz",
135
+ }
136
+
137
+
138
+ class Quickdraw(datasets.GeneratorBasedBuilder):
139
+ """Quickdraw dataset"""
140
+
141
+ VERSION = datasets.Version("1.0.0")
142
+
143
+ BUILDER_CONFIGS = [
144
+ datasets.BuilderConfig(name="raw", version=VERSION, description="The raw moderated dataset"),
145
+ datasets.BuilderConfig(
146
+ name="preprocessed_simplified_drawings",
147
+ version=VERSION,
148
+ description=textwrap.dedent(
149
+ """\
150
+ The simplified version of the dataset with the simplified vectors, removed timing information, and the data positioned and scaled into a 256x256 region.
151
+ The simplification process was:
152
+ 1.Align the drawing to the top-left corner, to have minimum values of 0.
153
+ 2.Uniformly scale the drawing, to have a maximum value of 255.
154
+ 3.Resample all strokes with a 1 pixel spacing.
155
+ 4.Simplify all strokes using the Ramer-Douglas-Peucker algorithm with an epsilon value of 2.0.
156
+ """
157
+ ),
158
+ ),
159
+ datasets.BuilderConfig(
160
+ name="preprocessed_bitmaps",
161
+ version=VERSION,
162
+ description="The preprocessed dataset where all the simplified drawings have been rendered into a 28x28 grayscale bitmap.",
163
+ ),
164
+ datasets.BuilderConfig(
165
+ name="sketch_rnn",
166
+ version=VERSION,
167
+ description=textwrap.dedent(
168
+ """\
169
+ This dataset was used for training the Sketch-RNN model from the paper https://arxiv.org/abs/1704.03477.
170
+ In this dataset, 75K samples (70K Training, 2.5K Validation, 2.5K Test) has been randomly selected from each category,
171
+ processed with RDP line simplification with an epsilon parameter of 2.0
172
+ """
173
+ ),
174
+ ),
175
+ datasets.BuilderConfig(
176
+ name="sketch_rnn_full",
177
+ version=VERSION,
178
+ description="Compared to the `sketch_rnn` config, this version provides the full data for each category for training more complex models.",
179
+ ),
180
+ ]
181
+
182
+ DEFAULT_CONFIG_NAME = "preprocessed_bitmaps"
183
+
184
+ def _info(self):
185
+ if self.config.name == "raw":
186
+ features = datasets.Features(
187
+ {
188
+ "key_id": datasets.Value("string"),
189
+ "word": datasets.ClassLabel(names=_NAMES),
190
+ "recognized": datasets.Value("bool"),
191
+ "timestamp": datasets.Value("timestamp[us, tz=UTC]"),
192
+ "countrycode": datasets.Value("string"),
193
+ "drawing": datasets.Sequence(
194
+ {
195
+ "x": datasets.Sequence(datasets.Value("float32")),
196
+ "y": datasets.Sequence(datasets.Value("float32")),
197
+ "t": datasets.Sequence(datasets.Value("int32")),
198
+ }
199
+ ),
200
+ }
201
+ )
202
+ elif self.config.name == "preprocessed_simplified_drawings":
203
+ features = datasets.Features(
204
+ {
205
+ "key_id": datasets.Value("string"),
206
+ "word": datasets.ClassLabel(names=_NAMES),
207
+ "recognized": datasets.Value("bool"),
208
+ "timestamp": datasets.Value("timestamp[us, tz=UTC]"),
209
+ "countrycode": datasets.Value("string"),
210
+ "drawing": datasets.Sequence(
211
+ {
212
+ "x": datasets.Sequence(datasets.Value("uint8")),
213
+ "y": datasets.Sequence(datasets.Value("uint8")),
214
+ }
215
+ ),
216
+ }
217
+ )
218
+ elif self.config.name == "preprocessed_bitmaps":
219
+ features = datasets.Features(
220
+ {
221
+ "image": datasets.Image(),
222
+ "label": datasets.ClassLabel(names=_NAMES),
223
+ }
224
+ )
225
+ else: # sketch_rnn, sketch_rnn_full
226
+ features = datasets.Features(
227
+ {
228
+ "word": datasets.ClassLabel(names=_NAMES),
229
+ "drawing": datasets.Array2D(shape=(None, 3), dtype="int16"),
230
+ }
231
+ )
232
+ return datasets.DatasetInfo(
233
+ description=_DESCRIPTION,
234
+ features=features,
235
+ homepage=_HOMEPAGE,
236
+ license=_LICENSE,
237
+ citation=_CITATION,
238
+ task_templates=[ImageClassification(image_column="image", label_column="label")]
239
+ if self.config.name == "preprocessed_bitmaps"
240
+ else None,
241
+ )
242
+
243
+ def _split_generators(self, dl_manager):
244
+ base_url = _CONFIG_NAME_TO_BASE_URL[self.config.name]
245
+ if not self.config.name.startswith("sketch_rnn"):
246
+ files = dl_manager.download(
247
+ {name: url for name, url in zip(_NAMES, [base_url.format(name) for name in _NAMES])}
248
+ )
249
+ return [
250
+ datasets.SplitGenerator(
251
+ name=datasets.Split.TRAIN,
252
+ gen_kwargs={
253
+ "files": files,
254
+ "split": "train",
255
+ },
256
+ ),
257
+ ]
258
+ else:
259
+ files = dl_manager.download_and_extract(
260
+ {name: url for name, url in zip(_NAMES, [base_url.format(name) for name in _NAMES])}
261
+ )
262
+ return [
263
+ datasets.SplitGenerator(
264
+ name=datasets.Split.TRAIN,
265
+ gen_kwargs={
266
+ "files": files,
267
+ "split": "train",
268
+ },
269
+ ),
270
+ datasets.SplitGenerator(
271
+ name=datasets.Split.VALIDATION,
272
+ gen_kwargs={
273
+ "files": files,
274
+ "split": "valid",
275
+ },
276
+ ),
277
+ datasets.SplitGenerator(
278
+ name=datasets.Split.TEST,
279
+ gen_kwargs={
280
+ "files": files,
281
+ "split": "test",
282
+ },
283
+ ),
284
+ ]
285
+
286
+ def _generate_examples(self, files, split):
287
+ if self.config.name == "raw":
288
+ idx = 0
289
+ for _, file in files.items():
290
+ with open(file, encoding="utf-8") as f:
291
+ for line in f:
292
+ example = json.loads(line)
293
+ example["timestamp"] = datetime.strptime(example["timestamp"], "%Y-%m-%d %H:%M:%S.%f %Z")
294
+ example["drawing"] = [{"x": x, "y": y, "t": t} for x, y, t in example["drawing"]]
295
+ yield idx, example
296
+ idx += 1
297
+ elif self.config.name == "preprocessed_simplified_drawings":
298
+ idx = 0
299
+ for label, file in files.items():
300
+ with open(file, "rb") as f:
301
+ while True:
302
+ try:
303
+ example = process_struct(f)
304
+ example["word"] = label
305
+ yield idx, example
306
+ except struct.error:
307
+ break
308
+ idx += 1
309
+ elif self.config.name == "preprocessed_bitmaps":
310
+ idx = 0
311
+ for label, file in files.items():
312
+ with open(file, "rb") as f:
313
+ images = np.load(f)
314
+ for image in images:
315
+ yield idx, {
316
+ "image": image.reshape(28, 28),
317
+ "label": label,
318
+ }
319
+ idx += 1
320
+ else: # sketch_rnn, sketch_rnn_full
321
+ idx = 0
322
+ for label, file in files.items():
323
+ with open(os.path.join(file, f"{split}.npy"), "rb") as f:
324
+ # read entire file since f.seek is not supported in the streaming mode
325
+ drawings = np.load(io.BytesIO(f.read()), encoding="latin1", allow_pickle=True)
326
+ for drawing in drawings:
327
+ yield idx, {
328
+ "word": label,
329
+ "drawing": drawing,
330
+ }
331
+ idx += 1
332
+
333
+
334
+ def process_struct(fileobj):
335
+ """
336
+ Process a struct from a binary file object.
337
+
338
+ The code for this function is borrowed from the following link:
339
+ https://github.com/googlecreativelab/quickdraw-dataset/blob/f0f3beef0fc86393b3771cdf1fc94828b76bc89b/examples/binary_file_parser.py#L19
340
+ """
341
+ (key_id,) = struct.unpack("Q", fileobj.read(8))
342
+ (country_code,) = struct.unpack("2s", fileobj.read(2))
343
+ (recognized,) = struct.unpack("b", fileobj.read(1))
344
+ (timestamp,) = struct.unpack("I", fileobj.read(4))
345
+ (n_strokes,) = struct.unpack("H", fileobj.read(2))
346
+ drawing = []
347
+ for _ in range(n_strokes):
348
+ (n_points,) = struct.unpack("H", fileobj.read(2))
349
+ fmt = str(n_points) + "B"
350
+ x = struct.unpack(fmt, fileobj.read(n_points))
351
+ y = struct.unpack(fmt, fileobj.read(n_points))
352
+ drawing.append({"x": list(x), "y": list(y)})
353
+
354
+ return {
355
+ "key_id": str(key_id),
356
+ "recognized": recognized,
357
+ "timestamp": datetime.fromtimestamp(timestamp),
358
+ "countrycode": country_code.decode("utf-8"),
359
+ "drawing": drawing,
360
+ }