GithubHelp home page GithubHelp logo

diff-font's Introduction

Diff-Font


Official code implementation based on pytorch for paper, Diff-Font: Diffusion Model for Robust One-Shot Font Generation. Arvix version

Dependencies


pytorch>=1.10.0
tqdm
opencv-python
sklearn
pillow
tensorboardX
blobfile>=1.0.5
mpi4py
attrdict
yaml

Dataset


方正字库 provides free font download for non-commercial users.

Example directory hierarchy

data_dir
    |--- font1
    |--- font2
           |--- 00000.png
           |--- 00001.png
           |--- ...
    |--- ...

Usage


Prepare dataset

python font2img.py --ttf_path ttf_folder --chara total_chn.txt --save_path save_folder --img_size 80 --chara_size 60

Conditional training

  • Modify the configuration file cfg/train_cfg.yaml

    Key setting for conditional training:

    data_dir: 'path_to_dataset/'
    chara_nums: 6625  # num of characters
    train_steps: 420000 # conditional training steps
    sty_encoder_path: './pretrained_models/chinese_styenc.ckpt' # path to pre-trained style encoder
    model_save_dir: './trained_models' # path to save trained models
    stroke_path: './chinese_stroke.txt' # encoded strokes
    classifier_free: False # False for conditional training
    resume_checkpoint: ""
  • single gpu

    python train.py --cfg_path cfg/train_cfg.yaml
  • distributed training

    mpiexec -n $NUM_GPUS python train.py --cfg_path cfg/train_cfg.yaml

Fine-tuning

After conditional training , we suggest an additional fine-tuning step.

  • Modify the configuration file cfg/train_cfg.yaml

    Key setting for fine-tuning:

    data_dir: 'path_to_dataset/'
    chara_nums: 6625  # num of characters
    model_save_dir: './trained_models' # path to save trained models
    stroke_path: './chinese_stroke.txt' # encoded strokes
    classifier_free: True  # True for fine-tuning
    total_train_steps: 800000 # total number of training steps for conditional training and fine-tuning
    resume_checkpoint: "./trained_models/model420000.pt" # path to conditional trained model, required for fine-tuning
  • single gpu

    python train.py --cfg_path cfg/train_cfg.yaml
  • distributed training

    mpiexec -n $NUM_GPUS python train.py --cfg_path cfg/train_cfg.yaml

Test

Modify the configuration file cfg/test_cfg.yaml

Key setting for testing:

chara_nums: 6625
num_samples: 10
stroke_path: './char_stroke.txt'
model_path: 'path_to_trained_model'
sty_img_path: 'path_to_reference_image'
total_txt_file: './total_chn.txt'
gen_txt_file: './gen_char.txt' # txt file for generation
img_save_path: './result' # path to save generated images
classifier_free: True 
cont_scale: 3.0 # content guidance sacle
sk_scale: 3.0 # stroke guidance sacle

, then run

python sample.py --cfg_path cfg/test_cfg.yaml

Visual display

result_img

Acknowledgements


This project is based on openai/guided-diffusion and DG-Font.

diff-font's People

Contributors

hensonchen avatar hxyz-123 avatar

Stargazers

 avatar

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.