Home

Awesome

VectorFusion: Text-to-SVG by Abstracting Pixel-Based Diffusion Models

In this work, the authors show that a text-conditioned diffusion model trained on pixel representations of images can be used to generate SVG-exportable vector graphics.

official website: https://vectorfusion.github.io/

<div align="center"> <img src="./img/vectorfusion_64paths_72videos_encode2p5k.gif" style="width: 100%; height: auto;" alt="VF video"> <p>VectorFusion rendering process. (64paths, 72videos, 5k)</p> </div>

Updates

Installation

Step by step

Create a new conda environment:

conda create --name vf python=3.10
conda activate vf

Install pytorch and the following libraries:

conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
pip install omegaconf BeautifulSoup4
pip install shapely
pip install opencv-python scikit-image matplotlib visdom wandb
pip install triton numba
pip install numpy scipy timm scikit-fmm einops
pip install accelerate transformers safetensors datasets

Install CLIP:

pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git

Install diffusers:

pip install diffusers==0.20.2

Install xformers (require python=3.10):

conda install xformers -c xformers

Install diffvg:

git clone https://github.com/BachiLi/diffvg.git
cd diffvg
git submodule update --init --recursive
conda install -y -c anaconda cmake
conda install -y -c conda-forge ffmpeg
pip install svgwrite svgpathtools cssutils torch-tools
python setup.py install

Docker Usage

docker run --name vectorfusion --gpus all -it --ipc=host ximingxing/svgrender:v1 /bin/bash

Quickstart

Case: Sydney Opera House

Prompt: the Sydney Opera House.<br/> Style: iconography <br/> Preview:

<img src="./img/Icon-SydneyOperaHouse/sample.png" style="width: 250px; height: 250px;"><img src="./img/Icon-SydneyOperaHouse/live.svg" style="width: 250px; height: 250px;"><img src="./img/Icon-SydneyOperaHouse/finetune.svg" style="width: 250px; height: 250px;">
(a) Sample raster image with Stable Diffusion(b) Convert raster image to a vector via LIVE(c) VectorFusion: Fine tune by LSDS

LIVE Rendering Process:

iter 0iter 500iter 1000iter 1500iter 2500iter 3500
<img src="./img/Icon-SydneyOperaHouse/svg_iter0.svg"><img src="./img/Icon-SydneyOperaHouse/svg_iter500.svg"><img src="./img/Icon-SydneyOperaHouse/svg_iter1000.svg"><img src="./img/Icon-SydneyOperaHouse/svg_iter1500.svg"><img src="./img/Icon-SydneyOperaHouse/svg_iter2500.svg"><img src="./img/Icon-SydneyOperaHouse/svg_iter3500.svg">

VectorFusion Rendering Process:

iter 0iter 100iter 300iter 400iter 700iter 1000
<img src="./img/Icon-SydneyOperaHouse/ft_iter0.svg"><img src="./img/Icon-SydneyOperaHouse/ft_iter100.svg"><img src="./img/Icon-SydneyOperaHouse/ft_iter300.svg"><img src="./img/Icon-SydneyOperaHouse/ft_iter400.svg"><img src="./img/Icon-SydneyOperaHouse/ft_iter700.svg"><img src="./img/Icon-SydneyOperaHouse/finetune.svg">

Script:

python run_painterly_render.py \ 
  -c vectorfusion.yaml \
  -pt "the Sydney Opera House. minimal flat 2d vector icon. lineal color. on a white background. trending on artstation" \
  -save_step 50 \ 
  -update "K=6" \ 
  -respath ./workdir/SydneyOperaHouse \
  -d 15486 \
  --download

optional:

Case: Ming Dynasty Vase

Prompt: A photo of a Ming Dynasty vase on a leather topped table. <br/> Style: iconography <br/> Preview:

<img src="./img/Icon-MingVase/sample.png" style="width: 250px; height: 250px;"><img src="./img/Icon-MingVase/live.svg" style="width: 250px; height: 250px;"><img src="./img/Icon-MingVase/finetune.svg" style="width: 250px; height: 250px;">
(a) Sample raster image with Stable Diffusion(b) Convert raster image to a vector via LIVE(c) VectorFusion: Fine tune by LSDS

Script:

python run_painterly_render.py -c vectorfusion.yaml -pt "A photo of a Ming Dynasty vase on a leather topped table. minimal flat 2d vector icon. lineal color. on a white background. trending on artstation" -save_step 50 -respath ./workdir/vase -d 683692

Case: Astronaut

Prompt: An astronaut figure. <br/> Style: iconography <br/> Preview:

<img src="./img/Icon-Astronaut/sample.png" style="width: 250px; height: 250px;"><img src="./img/Icon-Astronaut/live.svg" style="width: 250px; height: 250px;"><img src="./img/Icon-Astronaut/finetune.svg" style="width: 250px; height: 250px;">
(a) Sample raster image with Stable Diffusion(b) Convert raster image to a vector via LIVE(c) VectorFusion: Fine tune by LSDS

Script:

python run_painterly_render.py -c vectorfusion.yaml -pt "An astronaut figure. minimal flat 2d vector icon. lineal color. on a white background. trending on artstation" -save_step 50 -respath ./workdir/astronaut -d 522178

Case: Guitar

Prompt: Electric guitar. <br/> Style: Pixel-Art <br/> Preview:

<img src="./img/Pixel-Guitar/sample.png" style="width: 250px; height: 250px;"><img src="./img/Pixel-Guitar/live.svg" style="width: 250px; height: 250px;"><img src="./img/Pixel-Guitar/finetune.svg" style="width: 250px; height: 250px;">
(a) Sample raster image with Stable Diffusion(b) Convert raster image to a vector via LIVE(c) VectorFusion: Fine tune by LSDS

Script:

python run_painterly_render.py -c vectorfusion.yaml -pt "Electric guitar. pixel art. trending on artstation" -save_step 50 -respath ./workdir/guitar -update "style=pixelart" -d 445997  

Case: Dragon

Prompt: watercolor painting of a firebreathing dragon. <br/> Style: Sketch <br/> Preview:

<img src="./img/Sketch-Dragon/svg_iter0.svg"><img src="./img/Sketch-Dragon/svg_iter500.svg"><img src="./img/Sketch-Dragon/finetune.svg">
SVG initializationVectorFusion fine-tune 500 stepVectorFusion fine-tune 1500 step

Script:

python run_painterly_render.py -c vectorfusion.yaml -pt "watercolor painting of a firebreathing dragon. minimal 2d line drawing. trending on artstation" -save_step 50 -respath ./workdir/dragon-sketch -update "style=sketch num_segments=5 radius=0.5 sds.num_iter=1500" -d 106764  

Other Cases

# Sketch style
CUDA_VISIBLE_DEVICES=0 python run_painterly_render.py -c vectorfusion.yaml -pt "watercolor painting of a firebreathing dragon. minimal 2d line drawing. trending on artstation" -save_step 50 -respath ./workdir/dragon-sketch -update "style=sketch skip_live=True num_paths=32 num_segments=5 radius=0.5 sds.num_iter=1500" -rdbz
CUDA_VISIBLE_DEVICES=0 python run_painterly_render.py -c vectorfusion.yaml -pt "A cat. minimal 2d line drawing. trending on artstation" -save_step 50 -respath ./workdir/cat-sketch -update "style=sketch skip_live=True num_paths=32 num_segments=5 radius=0.5 sds.num_iter=1500" -rdbz

More Examples:

More Scripts:

Acknowledgement

The project is built based on the following repository:

We gratefully thank the authors for their wonderful works.

Citation

If you use this code for your research, please cite the following work:

@inproceedings{jain2023vectorfusion,
  title={Vectorfusion: Text-to-svg by abstracting pixel-based diffusion models},
  author={Jain, Ajay and Xie, Amber and Abbeel, Pieter},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={1911--1920},
  year={2023}
}
@inproceedings{xing2023diffsketcher,
  title={DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models},
  author={XiMing Xing and Chuang Wang and Haitao Zhou and Jing Zhang and Qian Yu and Dong Xu},
  booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
  year={2023},
  url={https://openreview.net/forum?id=CY1xatvEQj}
}

Licence

This repo is licensed under a MIT License.