{"id":19731709,"url":"https://github.com/clovaai/lffont","last_synced_at":"2025-10-06T16:30:45.582Z","repository":{"id":41562298,"uuid":"297926027","full_name":"clovaai/lffont","owner":"clovaai","description":"Official PyTorch implementation of LF-Font (Few-shot Font Generation with Localized Style Representations and Factorization) AAAI 2021","archived":false,"fork":false,"pushed_at":"2023-11-21T04:01:12.000Z","size":57951,"stargazers_count":169,"open_issues_count":0,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-05T21:51:12.729Z","etag":null,"topics":["aaai2021","deep-learning","font","font-generation","generative-models","lf-font","machine-learning","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clovaai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-23T09:53:57.000Z","updated_at":"2025-03-25T01:24:32.000Z","dependencies_parsed_at":"2025-01-25T04:01:30.862Z","dependency_job_id":null,"html_url":"https://github.com/clovaai/lffont","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clovaai/lffont","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clovaai%2Flffont","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clovaai%2Flffont/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clovaai%2Flffont/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clovaai%2Flffont/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clovaai","download_url":"https://codeload.github.com/clovaai/lffont/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clovaai%2Flffont/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278643288,"owners_count":26021076,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aaai2021","deep-learning","font","font-generation","generative-models","lf-font","machine-learning","pytorch"],"created_at":"2024-11-12T00:22:44.849Z","updated_at":"2025-10-06T16:30:40.572Z","avatar_url":"https://github.com/clovaai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Few-shot Font Generation with Localized Style Representations and Factorization (AAAI 2021)\n\n**NOTICE: We release the unified few-shot font generation repository ([clovaai/fewshot-font-generation](https://github.com/clovaai/fewshot-font-generation)). If you are interested in using our implementation, please visit the unified repository.**\n\nOfficial PyTorch implementation of LF-Font | [paper](https://arxiv.org/abs/2009.11042) | [paper (PAMI extension)](https://arxiv.org/abs/2112.11895)\n\nSong Park\u003csup\u003e1*\u003c/sup\u003e, Sanghyuk Chun\u003csup\u003e2*\u003c/sup\u003e, Junbum Cha\u003csup\u003e2\u003c/sup\u003e,\nBado Lee\u003csup\u003e2\u003c/sup\u003e, Hyunjung Shim\u003csup\u003e1\u003c/sup\u003e\u003cbr\u003e\n\u003csub\u003e\\* Equal contribution\u003c/sub\u003e\n\n\u003csup\u003e1\u003c/sup\u003e \u003csub\u003eSchool of Integrated Technology, Yonsei University\u003c/sub\u003e  \n\u003csup\u003e2\u003c/sup\u003e \u003csub\u003eClova AI Research, NAVER Corp.\u003c/sub\u003e\n\nAutomatic 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.\n\nYou can find more related projects on the few-shot font generation at the following links:\n\n- [clovaai/dmfont](https://github.com/clovaai/dmfont) (ECCV'20) | [paper](https://arxiv.org/abs/2005.10510)\n- [clovaai/lffont](https://github.com/clovaai/lffont) (AAAI'21) | [paper](https://arxiv.org/abs/2009.11042)\n- [clovaai/mxfont](https://github.com/clovaai/mxfont) (ICCV'21) | [paper](https://arxiv.org/abs/2104.00887)\n- [clovaai/fewshot-font-generation](https://github.com/clovaai/fewshot-font-generation) The unified few-shot font generation repository\n\n## Introduction\n\nPytorch implementation of ***Few-shot Font Generation with Localized Style Representations and Factorization***.\n\n* * *\n\n## Prerequisites\n\n* **Python \u003e 3.6**\n\n  Using conda is recommended: [https://docs.anaconda.com/anaconda/install/linux/](https://docs.anaconda.com/anaconda/install/linux/)\n* **pytorch \u003e= 1.1** (recommended: 1.1)\n\n\tTo install: [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/)\n\t\n* sconf\n\n\tTo install: [https://github.com/khanrc/sconf](https://github.com/khanrc/sconf)\n\t\n* numpy, tqdm, lmdb, yaml, jsonlib, msgpack\n\n```\nconda install numpy tqdm lmdb ruamel.yaml jsonlib-python3 msgpack\n```\n\n\n## Usage\n### Prepare datasets\n#### Build meta file to dump lmdb environment\n\n* To build a dataset with your own truetype font files (*.ttf*), a json-format meta file is needed:\n\t* **structure**: *dict*\n\t* **format**: {fontname: {\"path\": path/to/.ttf\", \"charlist\": [chars to dump.]}}\n\t* **example**: {\"font1\": {\"path\": \"./fonts/font1.ttf\", \"charlist\": [\"春\", \"夏\", \"秋\", \"冬\"]}}\n\t\nThe font file we used as the _content font_ can be accessed [here](https://chinesefontdesign.com/font-housekeeper-song-ming-typeface-chinese-font-simplified-chinese-fonts.html).\n\n#### Run script\n```\npython build_dataset.py \\\n    --lmdb_path path/to/dump/lmdb \\\n    --meta_path path/to/meta/file \\\n    --json_path path/to/save/dict\n```\n\n* **arguments**\n\t* \\-\\-lmdb_path: path to save lmdb environment.\n\t* \\-\\-meta_path: path to meta file of built meta file.\n\t* \\-\\-json_path: path to save *json* file, which contains information of available fonts and characters. \n\t\t* saved *json* file has format like this: {fontname: [saved character list in unicode format]}\n\n#### Build meta file to train and test\n* **train meta** (*dict, json format*)\n\t* should have keys; \"train\", \"valid\", \"avail\"\n\t* \"train\": {font: list of characters} pairs for training, *dict*\n\t\t* key: font name / value: list of chars in the key font.\n\t\t* example: {\"font1\": [\"4E00\", \"4E01\"...], \"font2\": [\"4E00\", \"4E01\"...]}\n\t* \"avail\": {font: list of characters} pairs which are accessible in lmdb, *dict*\n\t\t* same format with \"train\"\n\t* \"valid\": list of font and list characters for validation, *dict*\n\t\t* should have keys: \"seen_fonts\", \"unseen_fonts\", \"seen_unis\", \"unseen_unis\"\n\t\t* seen fonts(unis) : list of fonts(chars in unicode) in training set.\n\t\t* unseen fonts(unis): list of fonts(chars in unicode) not in training set, for validation.\n\t* An example of train meta file is in `meta/train.json`.\n\n* **test meta** (*dict, json format*)\n\t* should have keys; \"gen_fonts\", \"gen_unis\", \"ref_unis\"\n\t* \"gen_fonts\": list of fonts to generate.\n\t* \"gen_unis\": list of chars to generate, in *unicode*\n\t* \"ref_unis\": list of chars to use as reference chars, in *unicode* \n\t* An example of test meta file is in `meta/test.json`.\n\n### Modify the configuration file\nWe recommend to modify `cfgs/custom.yaml` rather than `cfgs/default.yaml`, `cfgs/combined.yaml`, or `cfgs/factorize.yaml`.\n\n**keys**\n* use_half\n\t* whether to use half tensor. (*apex* is needed)\n* use_ddp\n\t* whether to use DataDistributedParallel, for multi-gpus.\n* work_dir\n\t* the root directory for saved results.\n* data_path\n\t* path to data lmdb environment.\n* data_meta\n\t* path to train meta file.\n* content_font\n\t* the name of font you want to use as source font.\n* other values are hyperparameters for training.\n\n### Train\n```\n# Phase 1 training\npython train.py \\\n    NAME_phase1 \\\n    cfgs/custom.yaml cfgs/combined.yaml \n\n# Phase 2 training\npython train.py \\\n    NAME_phase2 \\\n    cfgs/custom.yaml cfgs/factorize.yaml \\\n    --resume ./result/checkpoints/NAME_phase1/800000-NAME_phase1.pth\n```\n* **arguments**\n\t* NAME (first argument): name for the experiment.\n\t\t* the (checkpoints, validation images, logs) are saved in ./results/(checkpoints, images, logs)/NAME\n\t* path/to/config (second argument): path to configration file.\n\t\t* multiple values are allowed, but their keys should not be repeated.\n\t\t* cfgs/combined.yaml : for phase 1 training.\n\t\t* cfgs/factorize.yaml: for phase 2 training.\n\t* \\-\\-resume (optional) : path to checkpoint to resume.\n\n\n### Test\n```\npython evaluator.py \\\n    cfgs/factorize.yaml \\\n    --weight weight/generator.pth \\\n    --img_dir path/to/save/images \\\n    --test_meta meta/test.json \\\n    --data_path path/to/data\n```\n* **arguments**\n  * path/to/config (first argument): path to configration file.\n  * \\-\\-weight : path to saved weight to test.\n  * \\-\\-img_dir: path to save generated images.\n  * \\-\\-test_meta: path to test meta file.\n  * \\-\\-data_path: path to lmdb dataset which contatins the reference images.\n\n## Code license\n\nThis project is distributed under [MIT license](LICENSE), except [modules.py](models/modules/modules.py) which is adopted from https://github.com/NVlabs/FUNIT.\n\n```\nLF-Font\nCopyright (c) 2020-present NAVER Corp.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n\n## Acknowledgement\n\nThis project is based on [clovaai/dmfont](https://github.com/clovaai/dmfont).\n\n## How to cite\n\n```\n@inproceedings{park2021lffont,\n    title={Few-shot Font Generation with Localized Style Representations and Factorization},\n    author={Park, Song and Chun, Sanghyuk and Cha, Junbum and Lee, Bado and Shim, Hyunjung},\n    year={2021},\n    booktitle={AAAI Conference on Artificial Intelligence},\n}\n\n@article{park2022lffont_extension,\n    author={Park, Song and Chun, Sanghyuk and Cha, Junbum and Lee, Bado and Shim, Hyunjung},\n    journal = {IEEE Transactions on Pattern Analysis \u0026amp; Machine Intelligence},\n    title = {Few-shot Font Generation with Weakly Supervised Localized Representations},\n    year = {5555},\n    volume = {},\n    number = {01},\n    issn = {1939-3539},\n    pages = {1-17},\n    keywords = {},\n    doi = {10.1109/TPAMI.2022.3196675},\n    publisher = {IEEE Computer Society},\n    address = {Los Alamitos, CA, USA},\n    month = {aug}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclovaai%2Flffont","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclovaai%2Flffont","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclovaai%2Flffont/lists"}