Differentiable Rasterizer for Vector Graphics https://people.csail.mit.edu/tzumao/diffvg
diffvg is a differentiable rasterizer for 2D vector graphics. See the webpage for more info.
- Install Python 3.10 from the Microsoft Store
- Install the CUDA Toolkit
- Install ffmpeg. Make sure ffmpeg is added to your
PATH
environment variable (Eg.C:\FFmpeg\bin
)
> git clone https://github.com/benbaker76/diffvg
> cd diffvg
> git submodule update --init --recursive
> git -m venv .venv
> ./.venv/Scripts/activate
> pip install torch==2.4.0+cu124 torchvision==0.19.0+cu124 --index-url https://download.pytorch.org/whl/cu124
> pip install -r requirements.txt
> set LIBDIR=.\.venv\Lib\site-packages
> python setup.py bdist_wheel
> pip install dist/diffvg-0.0.1-cp310-cp310-win_amd64.whl
# Test it's working
> python apps\refine_svg.py
usage: refine_svg.py [-h] [--use_lpips_loss] [--num_iter NUM_ITER] svg target
refine_svg.py: error: the following arguments are required: svg, target
cd apps
Optimizing a single circle to a target.
python single_circle.py
Finite difference comparison.
finite_difference_comp.py [-h] [--size_scale SIZE_SCALE]
[--clamping_factor CLAMPING_FACTOR]
[--use_prefiltering USE_PREFILTERING]
svg_file
e.g.,
python finite_difference_comp.py imgs/tiger.svg
Interactive editor
python svg_brush.py
Painterly rendering
painterly_rendering.py [-h] [--num_paths NUM_PATHS]
[--max_width MAX_WIDTH] [--use_lpips_loss]
[--num_iter NUM_ITER] [--use_blob]
target
e.g.,
python painterly_rendering.py imgs/fallingwater.jpg --num_paths 2048 --max_width 4.0 --use_lpips_loss
Image vectorization
python refine_svg.py [-h] [--use_lpips_loss] [--num_iter NUM_ITER] svg target
e.g.,
python refine_svg.py imgs/flower.svg imgs/flower.jpg
Seam carving
python seam_carving.py [-h] [--svg SVG] [--optim_steps OPTIM_STEPS]
e.g.,
python seam_carving.py imgs/hokusai.svg
Vector variational autoencoder & vector GAN:
For the GAN models, see apps/generative_models/train_gan.py
. Generate samples from a pretrained using apps/generative_models/eval_gan.py
.
For the VAE models, see apps/generative_models/mnist_vae.py
.
If you use diffvg in your academic work, please cite
@article{Li:2020:DVG,
title = {Differentiable Vector Graphics Rasterization for Editing and Learning},
author = {Li, Tzu-Mao and Luk\'{a}\v{c}, Michal and Gharbi Micha\"{e}l and Jonathan Ragan-Kelley},
journal = {ACM Trans. Graph. (Proc. SIGGRAPH Asia)},
volume = {39},
number = {6},
pages = {193:1--193:15},
year = {2020}
}