SketchRnn

AI generated cat drawings

Description

SketchRNN is a recurrent neural network model trained on millions of doodles collected from the Quick, Draw! game. The SketchRNN model can create new drawings (from a list of categories) based on an initial path.

This original paper and implementation of SketchRNN was made in TensorFlow and ported to Magenta.js by David Ha. The ml5.js implementation was ported by Reiichiro Nakano.

The ml5 library includes a list of supported SketchRNN models.

Quickstart

  1. // Create a new SketchRNN Instance
  2. const model = ml5.sketchRNN('cat', modelReady);
  3. // When the model is loaded
  4. function modelReady() {
  5. console.log('SketchRNN Model Loaded!');
  6. }
  7. // Reset the model's current stat
  8. model.reset();
  9. // Generate a new stroke
  10. model.generate(gotSketch);
  11. function gotSketch(err, result) {
  12. // Do something with the result
  13. }

Usage

Initialize

  1. const sketchrnn = ml5.sketchRNN(model, ?callback);

Parameters

  • model: The name of the model to use.
  • callback: Optional. A function to be called once the model is loaded. If no callback is provided, it will return a promise that will be resolved once the model has loaded.

Properties


.ready

Boolean. Boolean value that specifies if the model has loaded.


Methods


.reset()

Reset the model’s current state

  1. sketchrnn.reset();

📥 Inputs

  • n/a

📤 Outputs

  • n/a


.generate()

Generates a new sample with the current state.

  1. sketchrnn.generate(?seed, ?options, ?callback);

📥 Inputs

  • seed: Optional. A seed to be passed to the model before generating a new stroke.
  • options: Optional. An object describing the options of the model.
  • callback: Optional. A function that will return a generated stroke. If no callback is provided, it will return a promise that will be resolved with a generated stroke.

📤 Outputs

  • Object: an object with the x and y location, if the pen is down, up, or if it has ended {s.dx, s.dy, down, up, end}.

Examples

p5.js

p5 web editor

plain javascript

Demo

No demos yet - contribute one today!

Tutorials

No tutorials yet - contribute one today!

Acknowledgements

Contributors:

  • Name 1
  • Name 2

Credits:

  • Paper Reference | Website URL | Github Repo | Book reference | etc

Source Code