Home

Awesome

MIT LICENSE python 3.8

πŸ”₯ Disentangling Writer and Character Styles for Handwriting Generation

<p align='center'> <b> <a href="https://arxiv.org/abs/2303.14736">ArXiv</a> | <a href="https://github.com/dailenson/SDT/blob/master/static/Poster_SDT.pdf">Poster</a> | <a href="https://youtu.be/mKbYLEwa4dI">Video</a> | <a href="https://cvpr2023.thecvf.com/virtual/2023/poster/20954">Project</a> </b> </p>

πŸ“’ Introduction

<div style="display: flex; flex-direction: column; align-items: center; "> <img src="static/overview_sdt.jpg" style="width: 100%;"> </div> <p align="center" style="margin-bottom: 10px;"> Overview of our SDT </p> <div style="display: flex; justify-content: center;"> <img src="static/duo_loop.gif" style="width: 33.33%;"><img src="static/mo_loop.gif" style="width: 33.33%;"><img src="static/tai_loop.gif" style="width: 33.33%;"> </div> <p align="center"> Three samples of online characters with writing orders </p>

πŸ“… News

πŸ“Ί Handwriting generation results

πŸ”¨ Requirements

conda create -n sdt python=3.8 -y
conda activate sdt
# install all dependencies
conda env create -f environment.yml

πŸ“‚ Folder Structure

SDT/
β”‚
β”œβ”€β”€ train.py - main script to start training
β”œβ”€β”€ test.py - generate characters via trained model
β”œβ”€β”€ evaluate.py - evaluation of generated samples
β”‚
β”œβ”€β”€ configs/*.yml - holds configuration for training
β”œβ”€β”€ parse_config.py - class to handle config file
β”‚
β”œβ”€β”€ data_loader/ - anything about data loading goes here
β”‚   └── loader.py
β”‚
β”œβ”€β”€ model_zoo/ - pre-trained content encoder model
β”‚
β”œβ”€β”€ data/ - default directory for storing experimental datasets
β”‚
β”œβ”€β”€ model/ - networks, models and losses
β”‚   β”œβ”€β”€ encoder.py
β”‚   β”œβ”€β”€ gmm.py
β”‚   β”œβ”€β”€ loss.py
β”‚   β”œβ”€β”€ model.py
β”‚   └── transformer.py
β”‚
β”œβ”€β”€ saved/
β”‚   β”œβ”€β”€ models/ - trained models are saved here
β”‚   β”œβ”€β”€ tborad/ - tensorboard visualization
β”‚   └── samples/ - visualization samples in the training process
β”‚
β”œβ”€β”€ trainer/ - trainers
β”‚   └── trainer.py
β”‚  
└── utils/ - small utility functions
    β”œβ”€β”€ util.py
    └── logger.py - set log dir for tensorboard and logging output

πŸ’Ώ Datasets

We provide Chinese, Japanese and English datasets in Google Drive | Baidu Netdisk PW:xu9u. Please download these datasets, uzip them and move the extracted files to /data.

πŸ” Pre-trained model

ModelGoogle DriveBaidu Netdisk
Well-trained SDTGoogle DriveBaidu Netdisk
Content encoderGoogle DriveBaidu Netdisk
Content ScoreGoogle DriveBaidu Netdisk
Style ScoreGoogle DriveBaidu Netdisk

Note: Please download these weights, and move them to /model_zoo.

πŸš€ Training & Test

Training

python train.py --cfg configs/CHINESE_CASIA.yml --log Chinese_log
python train.py --cfg configs/Japanese_TUATHANDS.yml --log Japanese_log
python train.py --cfg configs/English_CASIA.yml --log English_log

Qualitative Test

python test.py --pretrained_model checkpoint_path --store_type online --sample_size 500 --dir Generated/Chinese
python test.py --pretrained_model checkpoint_path --store_type offline --sample_size 500 --dir Generated_img/Chinese
python test.py --pretrained_model checkpoint_path --store_type online --sample_size 500 --dir Generated/Japanese
python test.py --pretrained_model checkpoint_path --store_type offline --sample_size 500 --dir Generated_img/Japanese
python test.py --pretrained_model checkpoint_path --store_type online --sample_size 500 --dir Generated/English
python test.py --pretrained_model checkpoint_path --store_type offline --sample_size 500 --dir Generated_img/English

Quantitative Evaluation

python evaluate.py --data_path Generated/Chinese --metric DTW
python evaluate.py --data_path Generated/Chinese --metric Content_score --pretrained_model model_zoo/chinese_content_iter30k_acc95.pth
python evaluate.py --data_path Generated_img/Chinese --metric Style_score --pretrained_model models_zoo/chinese_style_iter60k_acc999.pth

🏰 Practical Application

We are delighted to discover that P0etry-rain has proposed a pipeline that involves initially converting the generated results by our SDT to TTF format, followed by the development of software to enable flexible adjustments in spacing between paragraphs, lines, and characters. Below, we present TTF files, software interface and the printed results. More details can be seen in #78.

❀️ Citation

If you find our work inspiring or use our codebase in your research, please cite our work:

@inproceedings{dai2023disentangling,
  title={Disentangling Writer and Character Styles for Handwriting Generation},
  author={Dai, Gang and Zhang, Yifan and Wang, Qingfeng and Du, Qing and Yu, Zhuliang and Liu, Zhuoman and Huang, Shuangping},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition,
  pages={5977--5986},
  year={2023}
}

⭐ StarGraph

Star History Chart