kmewhort commited on
Commit
c47ace8
1 Parent(s): bb03d9a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +53 -2
README.md CHANGED
@@ -362,6 +362,57 @@ dataset_info:
362
  download_size: 62877590
363
  dataset_size: 64950879.933217384
364
  ---
365
- # Dataset Card for "quickdraw-bins-1pct-sample"
366
 
367
- [More Information needed](https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  download_size: 62877590
363
  dataset_size: 64950879.933217384
364
  ---
365
+ # Quick!Draw! 1pct Sample (per-row bin format)
366
 
367
+ This is a sample 1-percent of the entire 50M-row [QuickDraw! dataset](https://github.com/googlecreativelab/quickdraw-dataset). The row for each drawing contains a byte-encoded packed representation of the drawing and data, which you can unpack using the following snippet:
368
+
369
+ ```
370
+ def unpack_drawing(file_handle):
371
+ key_id, = unpack('Q', file_handle.read(8))
372
+ country_code, = unpack('2s', file_handle.read(2))
373
+ recognized, = unpack('b', file_handle.read(1))
374
+ timestamp, = unpack('I', file_handle.read(4))
375
+ n_strokes, = unpack('H', file_handle.read(2))
376
+ image = []
377
+ n_bytes = 17
378
+ for i in range(n_strokes):
379
+ n_points, = unpack('H', file_handle.read(2))
380
+ fmt = str(n_points) + 'B'
381
+ x = unpack(fmt, file_handle.read(n_points))
382
+ y = unpack(fmt, file_handle.read(n_points))
383
+ image.append((x, y))
384
+ n_bytes += 2 + 2*n_points
385
+ result = {
386
+ 'key_id': key_id,
387
+ 'country_code': country_code,
388
+ 'recognized': recognized,
389
+ 'timestamp': timestamp,
390
+ 'image': image,
391
+ }
392
+ return result
393
+ ```
394
+
395
+ The `image` in the above is still in line vector format. To convert render this to a raster image (I recommend you do this on-the-fly in a pre-processor):
396
+
397
+ ```
398
+ # packed bin -> RGB PIL
399
+ def binToPIL(packed_drawing):
400
+ padding = 8
401
+ radius = 7
402
+ scale = (224.0-(2*padding)) / 256
403
+
404
+ unpacked = unpack_drawing(io.BytesIO(packed_drawing))
405
+ unpacked_image = unpacked['image']
406
+ image = np.full((224,224), 255, np.uint8)
407
+ for stroke in unpacked['image']:
408
+ prevX = round(stroke[0][0]*scale)
409
+ prevY = round(stroke[1][0]*scale)
410
+ for i in range(1, len(stroke[0])):
411
+ x = round(stroke[0][i]*scale)
412
+ y = round(stroke[1][i]*scale)
413
+ cv2.line(image, (padding+prevX, padding+prevY), (padding+x, padding+y), 0, radius, -1)
414
+ prevX = x
415
+ prevY = y
416
+ pilImage = Image.fromarray(image).convert("RGB")
417
+ return pilImage
418
+ ```