项目作者: rahul96rajan

项目描述 :
An online handwriting synthesizer based on Alex Graves paper - Generating Sequences With Recurrent Neural Networks. GUI built in electron.js
高级语言: Python
项目地址: git://github.com/rahul96rajan/text-2-strokes.git
创建时间: 2020-12-01T17:56:20Z
项目社区:https://github.com/rahul96rajan/text-2-strokes

开源协议:

下载


Text-2-Strokes

An attempt to implement handwriting synthesis basing the paper ‘Generating Sequences with Recurrent Neural Networks‘ by Alex Graves. GUI is built with electron.js.

Demo

GUI_workflow

Dependencies

Python libraries required:

  1. numpy==1.19.5
  2. matplotlib==3.2.2
  3. torch==1.7.1

npm dependencies:

  1. electron.js

How to use

Prerequisites : A working installation of python3 and npm.

After cloning repo, install python packages using pip install -r requirements.txt (virtual environment recommended)

And similarly install node-modules using npm install

1. Download dataset

Download IAM On-Line Handwriting Database. Place the extracted folder original-xml-part under text-2-strokes/data/.

2. Preprocess dataset

  1. python extract_data.py

This scipt searches original-xml-part directory for xml files with handwriting data > converts coordinates to offsets > saves the output as ./data/strokes.npy and ./data/sentences.txt.

3. Train model

  1. python train.py --n_epochs 100 --model synthesis --batch_size 32 --text_req

A number of arguments can be set for training if you wish to experiment with the parameters. The default values are in train.py

  1. --hidden_size #hidden states for LSTM layer
  2. --n_layers #LSTM layer
  3. --batch_size size of training batch
  4. --step_size step size for learning rate decay
  5. --n_epochs #Training epochs
  6. --lr learning rate
  7. --patience patience for early stopping
  8. --model_type train model type
  9. --data_path path to processed training data
  10. --save_path path where training weights are stored
  11. --text_req flag indicating to fetch text data also
  12. --data_aug flag to whether data augmentation required
  13. --seed random seed

4. Generate handwriting

  1. python generate.py --char_seq "input text for handwriting synthesis" --save_img --style 4

Similarly a number of arguments can be set for generation also, if you wish to experiment with the parameters. The default values are in generate.py

  1. --model type of model
  2. --model_path path to trained weights
  3. --save_path output path
  4. --seq_len length of input sequence
  5. --bias bias term
  6. --char_seq input text
  7. --text_req flag indicating to fetch text data also
  8. --seed random seed
  9. --data_path path to processed training data
  10. --style style number [0,4]
  11. --save_img save output as .png
  12. --save_gif save output as .gif

To run GUI, execute:

npm start

Examples

  1. python generate.py --char_seq "A sample of generated text" --save_gif --style 1

sample1

  1. python generate.py --char_seq "I am Rahul" --save_gif --style 4

sample2

References

[1] Alex Graves, Generating Sequences With Recurrent Neural Networks, 2014

[2] IAM On-Line Handwriting Database, Universität Bern, 2005

[3] Swechha Choudhary’s implemetation of the paper

[4] Grzegorz Opoka’s implementation of the paper

Any feedback is much appreciated :smiley: