/quickdraw_python

An API for using the Google Quick, Draw! Data

Primary LanguagePythonMIT LicenseMIT

quickdraw

Latest Version Docs

Quick Draw is a drawing game which is training a neural network to recognise doodles.

quickdraw

quickdraw is an API for accessing the Quick Draw data - it downloads the data files as and when needed, caches them locally and interprets them so they can be used.

quickdraw_preview

Created by Martin O'Hanlon (@martinohanlon, stuffaboutco.de).

Getting started

Install the quickdraw python library using pip.

  • Windows
pip install quickdraw
  • macOS
pip3 install quickdraw
  • Linux / Raspberry Pi
sudo pip3 install quickdraw

Use

Here are some examples of how to use quickdraw but be sure to also checkout the API documentation for more information.

Open the Quick Draw data using QuickDrawData and pull back a drawing of an anvil.

from quickdraw import QuickDrawData
qd = QuickDrawData()
anvil = qd.get_drawing("anvil")

print(anvil)

quickdraw will download the anvil.bin data file and return the data for a random drawing of an anvil (well a doodle of an anvil anyway).

Drawings are returned as QuickDrawing objects which exposes the properties of the drawing.

print(anvil.name)
print(anvil.key_id)
print(anvil.countrycode)
print(anvil.recognized)
print(anvil.timestamp)
print(anvil.no_of_strokes)
print(anvil.image_data)
print(anvil.strokes)

You can save the drawing using the image property.

anvil.image.save("my_anvil.gif")

quickdraw_preview

You can open a group of Quick Draw drawings using QuickDrawDataGroup passing the name of the drawing ("anvil", "aircraft", "baseball", etc).

from quickdraw import QuickDrawDataGroup

anvils = QuickDrawDataGroup("anvil")
print(anvils.drawing_count)
print(anvils.get_drawing())

By default only 1000 drawings are opened, you can change this by modifying the max_drawings parameter of QuickDrawDataGroup, setting it to None will open all the drawings in that group.

from quickdraw import QuickDrawDataGroup

anvils = QuickDrawDataGroup("anvil", max_drawings=None)
print(anvils.drawing_count)

To iterate through all the drawings in a group use the drawings generator.

from quickdraw import QuickDrawDataGroup

qdg = QuickDrawDataGroup("anvil")
for drawing in qdg.drawings:
    print(drawing)

You can get a list of all the drawing names using the drawing_names property of QuickDrawData.

from quickdraw import QuickDrawData

qd = QuickDrawData()
print(qd.drawing_names)

Examples

Code examples can be found in the quickdraw GitHub repository.

Documentation

API documentation can be found at quickdraw.readthedocs.io

Warning

The drawings have been moderated but there is no guarantee it'll actually be a picture of what you are asking it for (although in my experience they are)!

Status

Beta - stable, under active dev, the API may change.