Git Product home page Git Product logo

handwriting-synthesis's Introduction

Handwriting generation using LSTM

Implementing this paper by Alex Graves using pytorch.

Training

Use train.py script for training the models.

$ python train.py -h
usage: train.py [-h] [--uncond] [--batch_size BATCH_SIZE] [--resume RESUME]
                [--logdir LOGDIR] [--n_data N_DATA]

Train a handwriting generation model

optional arguments:
  -h, --help            show this help message and exit
  --uncond              If want to train the unconditional model
  --batch_size BATCH_SIZE
                        Batch size for training
  --resume RESUME       model path from which to resume training
  --logdir LOGDIR       Directory to be used for logging
  --n_data N_DATA       count of strokes to take from data

Generating samples

Use generate.py for generating from models using saved state_dict files.

$ python generate.py -h
usage: generate.py [-h] [--uncond] --model_path MODEL_PATH
                   [--text TEXT [TEXT ...]] [--sample_length SAMPLE_LENGTH]
                   [--num_sample NUM_SAMPLE] [--seed SEED]

optional arguments:
  -h, --help            show this help message and exit
  --uncond              If want to generate using the unconditional model.
                        Default is conditional
  --model_path MODEL_PATH
                        path to the saved sate_dict file to be used for
                        generating samples
  --text TEXT [TEXT ...]
                        text for which handwriting to be synthesized (for
                        conditional model)
  --sample_length SAMPLE_LENGTH
                        sample length for unconditional model
  --num_sample NUM_SAMPLE
                        number of samples to generate from unconditional model
  --seed SEED

Example command for generating from the saved best conditional model:

python generate.py --model_path data/model_files/handwriting_cond_best.pt --text "Hello world" "Welcome to Lyrebird"

Example command for generating from the saved best unconditional model:

python generate.py --uncond --model_path data/model_files/handwriting_uncond_best.pt --sample_length 600 --num_sample 4

Samples

Smaples from conditional model

"Hello World" Hello World

"Welcome to Lyrebird" Welcome to Lyrebird

"Welcome to Lyrebird" Welcome to Lyrebird

Smaples from conditional model

Random sample 1 Random sample 1

Random sample 2 Random sample 2

Random sample 3 Random sample 3

Random sample 4 Random sample 4

Known issues

Implementation of stopping criteria for generation from conditional is not so robust and this may cause model to return empty stroke sequence. In this case just try with a different seed or with higher bias value and it will work fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.