Home

Awesome

Few-shot Font Generation with Localized Style Representations and Factorization (AAAI 2021)

NOTICE: We release the unified few-shot font generation repository (clovaai/fewshot-font-generation). If you are interested in using our implementation, please visit the unified repository.

Official PyTorch implementation of LF-Font | paper | paper (PAMI extension)

Song Park<sup>1*</sup>, Sanghyuk Chun<sup>2*</sup>, Junbum Cha<sup>2</sup>, Bado Lee<sup>2</sup>, Hyunjung Shim<sup>1</sup><br> <sub>* Equal contribution</sub>

<sup>1</sup> <sub>School of Integrated Technology, Yonsei University</sub>
<sup>2</sup> <sub>Clova AI Research, NAVER Corp.</sub>

Automatic few-shot font generation is in high demand because manual designs are expensive and sensitive to the expertise of designers. Existing methods of few-shot font generation aims to learn to disentangle the style and content element from a few reference glyphs and mainly focus on a universal style representation for each font style. However, such approach limits the model in representing diverse local styles, and thus make it unsuitable to the most complicated letter system, e.g., Chinese, whose characters consist of a varying number of components (often called "radical") with a highly complex structure. In this paper, we propose a novel font generation method by learning localized styles, namely component-wise style representations, instead of universal styles. The proposed style representations enable us to synthesize complex local details in text designs. However, learning component-wise styles solely from reference glyphs is infeasible in the few-shot font generation scenario, when a target script has a large number of components, e.g., over 200 for Chinese. To reduce the number of reference glyphs, we simplify component-wise styles by a product of component factor and style factor, inspired by low-rank matrix factorization. Thanks to the combination of strong representation and a compact factorization strategy, our method shows remarkably better few-shot font generation results (with only 8 reference glyph images) than other state-of-the-arts, without utilizing strong locality supervision, e.g., location of each component, skeleton, or strokes.

You can find more related projects on the few-shot font generation at the following links:

Introduction

Pytorch implementation of Few-shot Font Generation with Localized Style Representations and Factorization.


Prerequisites

conda install numpy tqdm lmdb ruamel.yaml jsonlib-python3 msgpack

Usage

Prepare datasets

Build meta file to dump lmdb environment

The font file we used as the content font can be accessed here.

Run script

python build_dataset.py \
    --lmdb_path path/to/dump/lmdb \
    --meta_path path/to/meta/file \
    --json_path path/to/save/dict

Build meta file to train and test

Modify the configuration file

We recommend to modify cfgs/custom.yaml rather than cfgs/default.yaml, cfgs/combined.yaml, or cfgs/factorize.yaml.

keys

Train

# Phase 1 training
python train.py \
    NAME_phase1 \
    cfgs/custom.yaml cfgs/combined.yaml 

# Phase 2 training
python train.py \
    NAME_phase2 \
    cfgs/custom.yaml cfgs/factorize.yaml \
    --resume ./result/checkpoints/NAME_phase1/800000-NAME_phase1.pth

Test

python evaluator.py \
    cfgs/factorize.yaml \
    --weight weight/generator.pth \
    --img_dir path/to/save/images \
    --test_meta meta/test.json \
    --data_path path/to/data

Code license

This project is distributed under MIT license, except modules.py which is adopted from https://github.com/NVlabs/FUNIT.

LF-Font
Copyright (c) 2020-present NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Acknowledgement

This project is based on clovaai/dmfont.

How to cite

@inproceedings{park2021lffont,
    title={Few-shot Font Generation with Localized Style Representations and Factorization},
    author={Park, Song and Chun, Sanghyuk and Cha, Junbum and Lee, Bado and Shim, Hyunjung},
    year={2021},
    booktitle={AAAI Conference on Artificial Intelligence},
}

@article{park2022lffont_extension,
    author={Park, Song and Chun, Sanghyuk and Cha, Junbum and Lee, Bado and Shim, Hyunjung},
    journal = {IEEE Transactions on Pattern Analysis &amp; Machine Intelligence},
    title = {Few-shot Font Generation with Weakly Supervised Localized Representations},
    year = {5555},
    volume = {},
    number = {01},
    issn = {1939-3539},
    pages = {1-17},
    keywords = {},
    doi = {10.1109/TPAMI.2022.3196675},
    publisher = {IEEE Computer Society},
    address = {Los Alamitos, CA, USA},
    month = {aug}
}