Spaces:
Sleeping
Sleeping
File size: 4,203 Bytes
31726e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# diffvg
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
```
git submodule update --init --recursive
conda install -y pytorch torchvision -c pytorch
conda install -y numpy
conda install -y scikit-image
conda install -y -c anaconda cmake
conda install -y -c conda-forge ffmpeg
pip install svgwrite
pip install svgpathtools
pip install cssutils
pip install numba
pip install torch-tools
pip install visdom
python setup.py install
```
# Install using poetry
## prerequisite
install python 3.7, poetry and ffmpeg
```
# install poetry (mac, linux)
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
# install ffmpeg
(macos)
brew install ffmpeg
(linux)
sudo apt install ffmpeg
or use conda
conda install -y -c conda-forge ffmpeg
```
## Install python packages
```
# install all python dependencies
poetry install
# install pydiffvg
poetry run python setup.py install
```
Now to run the apps, just add `poetry run` before each of the commands below, e.g.
```
poetry run python single_circle.py
```
# Building in debug mode
```
python setup.py build --debug install
```
# Run
```
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}
}
```
|