OpenAccess[pdf][supp] Arxiv[pdf]
Code release for DualVector: Unsupervised Vector Font Synthesis with Dual-Part Representation (CVPR 2023)
Update
- 2023.10.11: We release the pretrained models for font reconstruction and generation.
In general, other versions of the packages listed below may also work, but are not tested.
Important python related packages
- python 3.8
- pytorch 1.9.0
- torchvision 0.10.0
- diffvg (Note: please first replace the original
diffvg/pydiffvg/save_svg.pywith DeepVecFont's save_svg.py, and the originalparse_svg.pywith our parse_svg.py and then install.) - svgpathtools (We use version 1.4.4 and make several modifications. Please replace the source code with our modified version. Basically we add a
forceZoption to ensure a closed path.)
We recommend you to install these dependencies with pip. You can refer to requirements.txt for all the packages' version but some of them may not be used in code.
Javascript related packages
- npm 8.5.5
- node v17.9.0
- Paper.js
If NPM is already installed, just run
cd js
npm installPlease download it from here and extract it to data/dvf_png.
The dataset is the same as that used in DeepVecFont, a subset from SVG-VAE. But because some of the fonts' lowercase letters are not fully contained by the images, we re-render them to images with a resolution of 1536*1024. The training data required for Multi-Implicits is also included.
We provide the pretrained models for font reconstruction and generation. You can download them and replace the checkpoint path following with their path.
Font Reconstruction
python train.py --config configs/reconstruct.yaml --name recon --gpu 0This will save the training records under save/recon, including the source code, tensorboard log, image visualization at the validation epoch and the checkpoint.
Font Generation (Font Style Transfer)
Replace the following path in generation_latent_guide.yaml with the reconstruction checkpoint:
submodule_config:
-
ckpt: ./save/recon/ckpt/epoch-last.pth # replace this line with your checkpoint
ckpt_key: [encoder, img_decoder, decoder, encoder]
module_name: [latent_encoder, img_decoder, decoder, img_encoder]
freeze: [true, true, true, true]Then train a model with the latent guidance:
python train.py --config configs/generation_latent_guide.yaml --name gen_latent --gpu 0Finally resume from this checkpoint and train the whole model. Please select config if said Model/Optimizer configs are different.
python train.py --config configs/generation.yaml --name gen --gpu 0 --resume save/gen_latent/ckpt/epoch-last.pth
Font reconstruction
First synthesize the reconstructed image and initial SVG:
python eval/eval_reconstruction.py --resume save/recon/ckpt/epoch-last.pth --outdir eval/save/test_recon # initial SVGThen run the contour refinement:
python eval/post_refinement.py --outdir eval/save/test_recon/refined --input eval/save/test_recon/rec_init/ --fmin 0 --fmax 200 # refinementFont generation
Similar with font reconstruction, run the following two steps:
python eval/eval_generation_multiref.py --outdir eval/save/test_gen/ --resume save/gen/ckpt/epoch-last.pth # initial SVG
python eval/post_refinement.py --outdir eval/save/test_gen/refined --input eval/save/test_gen/rec_init/ --fmin 0 --fmax 200 # refinementSampling new fonts
Specify the number of fonts you want:
python eval/sample_dvf.py --outdir eval/save/test_sample/svg --n-sample 10 # initial SVGThen refine it:
python eval/post_refinement.py --outdir eval/save/test_sample/refined --input eval/save/test_sample/svg/ --fmin 0 --fmax 20 # refinementEvaluate the metrics
Take the font reconstruction as an example. To render the glyph with a resolution of 256*256 and evaluate the L1-error, SSIM and s-IOU, run:
cd eval
python run_metrics.py --name ours --pred_lowercase --pred save/test_recon/refined --ff {0:02d}_p4.svg --fontmin 0 --fontmax 200 --glyph 52 --res 256The result will be saved at eval/eval/save/.
If you find DualVector helpful, please consider citing:
@InProceedings{dualvector,
author = {Liu, Ying-Tian and Zhang, Zhifei and Guo, Yuan-Chen and Fisher, Matthew and Wang, Zhaowen and Zhang, Song-Hai},
title = {DualVector: Unsupervised Vector Font Synthesis With Dual-Part Representation},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2023},
pages = {14193-14202}
}