Awesome
sketch-pix2seq
This is the reimplementation code of paper Sketch-pix2seq: a Model to Generate Sketches of Multiple Categories.
Input | Generated examples |
---|---|
Requirements
-
Python 3
-
Tensorflow (>= 1.4.0)
-
InkScape or CairoSVG (For vector sketch rendering. Choose one of them is ok.)
sudo apt-get install inkscape # or pip3 install cairosvg
Data Preparations
Follow these steps:
-
First download the
.npz
data from QuickDraw dataset. Choose one or more categories as you like. -
Place the
.npz
packages underdatasets/npz/
dir. -
Modify the hyper params in
get_default_hparams()
in model.py- Set the name(s) of the downloaded packages in
data_set
- Set the size of the raster image in
img_H
/img_W
- Set the name(s) of the downloaded packages in
-
We provide two approaches of rendering sequential data into raster images:
- Using InkScape: this approach is slower but accurate all the time
python render_svg2bitmap.py --data_base_dir='datasets' --render_mode='v1'
- Using CairoSVG: this approach is faster, but will have one-pixel misalignment problem sometimes (when setting image-width to 256, it will turn out to be 255 sometimes)
python render_svg2bitmap.py --data_base_dir='datasets' --render_mode='v2'
The raster images can be found under
datasets/
dir.
Training
Run this command for default training:
python sketch_pix2seq_train.py
You can also change the settings, e.g. image size, batch size, in get_default_hparams()
in model.py. For multi-category training, set the data_set
with a list of more than one packages' names.
Training procedure
The following figure shows the reconstruction loss during training within 60k iterations. The orange line belongs to sketch-rnn and the blue one belongs to sketch-pix2seq.
Sampling
With trained model placed under outputs/snapshot/
dir, run this command for sampling:
python sketch_pix2seq_sampling.py
And results in .svg
format can be found under outputs/sampling/
dir.
Credits
- This code is modified from repo of Sketch-RNN.