jree423 commited on
Commit
87fe160
·
verified ·
1 Parent(s): 69bd6b9

Upload DiffSketcher/README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. DiffSketcher/README.md +279 -0
DiffSketcher/README.md ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models
2
+
3
+ [![NeurIPS 2023](https://img.shields.io/badge/NeurIPS%202023-Paper-6420AA?style=for-the-badge&logo=openreview&logoColor=white)](https://openreview.net/attachment?id=CY1xatvEQj&name=pdf) [![ArXiv](https://img.shields.io/badge/arXiv-2306.14685-FF6347?style=for-the-badge&logo=arxiv&logoColor=white)](https://arxiv.org/abs/2306.14685) [![Project Website](https://img.shields.io/badge/Website-Project%20Page-4682B4?style=for-the-badge&logo=github&logoColor=white)](https://ximinng.github.io/DiffSketcher-project/) [![Demo](https://img.shields.io/badge/Demo-Gradio-00CED1?style=for-the-badge&logo=gradio&logoColor=white)](https://huggingface.co/spaces/SVGRender/DiffSketcher)
4
+
5
+ This repository contains our official implementation of the NeurIPS 2023 paper: DiffSketcher: Text Guided Vector Sketch
6
+ Synthesis through Latent Diffusion Models, which can generate high-quality vector sketches based on text prompts.
7
+
8
+ ![teaser1](./img/teaser1.png)
9
+ ![teaser2](./img/teaser2.png)
10
+
11
+ **DiffSketcher Rendering Process:**
12
+
13
+ | <img src="./img/0.gif" style="width: 200px; height: 200px;"> | <img src="./img/1.gif" style="width: 200px; height: 200px;"> | <img src="./img/2.gif" style="width: 200px; height: 200px;"> |
14
+ |-------------------------------------------------------------------------|-----------------------------------------------------------------------------|--------------------------------------------------------------|
15
+ | Prompt: Macaw full color, ultra detailed, realistic, insanely beautiful | Prompt: Very detailed masterpiece painting of baby yoda hoding a lightsaber | Prompt: Sailboat sailing in the sea on a clear day |
16
+
17
+ ## :new: Update
18
+
19
+ - [01/2024] 🔥 **We released the [SVGDreamer](https://ximinng.github.io/SVGDreamer-project/). SVGDreamer is
20
+ a novel text-guided vector graphics synthesis method. This method considers both the editing of vector graphics and
21
+ the quality of the synthesis.**
22
+ - [12/2023] 🔥 **We released the [PyTorch-SVGRender](https://github.com/ximinng/PyTorch-SVGRender). Pytorch-SVGRender is
23
+ the go-to library for state-of-the-art differentiable rendering methods for image vectorization.**
24
+ - [11/2023] We thank [@camenduru](https://github.com/camenduru) for implementing
25
+ the [DiffSketcher-colab](https://github.com/camenduru/DiffSketcher-colab).
26
+ - [10/2023] We released the DiffSketcher code.
27
+ - [10/2023] We released the [VectorFusion code](https://github.com/ximinng/VectorFusion-pytorch).
28
+
29
+ ## 📌 Installation Guide
30
+
31
+ To quickly get started with **DiffSketcher**, follow the steps below.
32
+ These instructions will help you run **quick inference locally**.
33
+
34
+ #### 🚀 **Option 1: Standard Installation**
35
+
36
+ Run the following command in the **top-level directory**:
37
+
38
+ ```shell
39
+ chmod +x script/install.sh
40
+ bash script/install.sh
41
+ ```
42
+
43
+ #### 🐳 Option 2: Using Docker
44
+
45
+ ```shell
46
+ chmod +x script/run_docker.sh
47
+ sudo bash script/run_docker.sh
48
+ ```
49
+
50
+ ## 🔥 Quickstart
51
+
52
+ ### Case: Sydney Opera House
53
+
54
+ **Preview:**
55
+
56
+ | Attention Map | Control Points Init | Strokes Initialization | 100 step | 500 step |
57
+ |:------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------:|
58
+ | <img src="./img/SydneyOperaHouse/attn-map.png" style="width: 200px; height: 200px;"> | <img src="./img/SydneyOperaHouse/points-init.png" style="width: 200px; height: 200px;"> | <img src="./img/SydneyOperaHouse/svg_iter0.svg" style="width: 200px; height: 200px;"> | <img src="./img/SydneyOperaHouse/svg_iter100.svg" style="width: 200px; height: 200px;"> | <img src="./img/SydneyOperaHouse/visual_best_96P.svg" style="width: 200px; height: 200px;"> |
59
+
60
+ **From the abstract to the concrete:**
61
+
62
+ | 16 Paths | 36 Paths | 48 Paths | 96 Paths | 128 Paths |
63
+ |:------------------------------------------------------:|:------------------------------------------------------:|:------------------------------------------------------:|:------------------------------------------------------:|:-------------------------------------------------------:|
64
+ | <img src="./img/SydneyOperaHouse/visual_best_16P.svg"> | <img src="./img/SydneyOperaHouse/visual_best_36P.svg"> | <img src="./img/SydneyOperaHouse/visual_best_48P.svg"> | <img src="./img/SydneyOperaHouse/visual_best_96P.svg"> | <img src="./img/SydneyOperaHouse/visual_best_128P.svg"> |
65
+
66
+ **Script:**
67
+
68
+ ```shell
69
+ python run_painterly_render.py \
70
+ -c diffsketcher.yaml \
71
+ -eval_step 10 -save_step 10 \
72
+ -update "token_ind=4 num_paths=96 num_iter=800" \
73
+ -pt "a photo of Sydney opera house" \
74
+ -respath ./workdir/sydney_opera_house \
75
+ -d 8019 \
76
+ --download
77
+ ```
78
+
79
+ - `-c` a.k.a `--config`: configuration file, saving in `DiffSketcher/config/`.
80
+ - `-eval_step`: the step size used to eval the method (**too frequent calls will result in longer times**).
81
+ - `-save_step`: the step size used to save the result (**too frequent calls will result in longer times**).
82
+ - `-update`: a tool for editing the hyper-params of the configuration file, so you don't need to create a new yaml.
83
+ - `-pt` a.k.a `--prompt`: text prompt.
84
+ - `-respath` a.k.a `--results_path`: the folder to save results.
85
+ - `-d` a.k.a `--seed`: random seed.
86
+ - `--download`: download models from huggingface automatically **when you first run them**.
87
+
88
+ **crucial:**
89
+
90
+ - `-update "token_ind=4"` indicates the index of cross-attn maps to init strokes.
91
+ - `-update "num_paths=96"` indicates the number of strokes.
92
+
93
+ **optional:**
94
+
95
+ - `-npt`, a.k.a `--negative_prompt`: negative text prompt.
96
+ - `-mv`, a.k.a `--make_video`: make a video of the rendering process (**it will take much longer**).
97
+ - `-frame_freq`, a.k.a `--video_frame_freq`: the interval of the number of steps to save the image.
98
+ - `-framerate`, a.k.a `--video_frame_rate`: control the playback speed of the output video.
99
+ - **Note:** [Download](https://huggingface.co/akhaliq/CLIPasso/blob/main/u2net.pth) U2Net model and place
100
+ in `checkpoint/` dir if `xdog_intersec=True`
101
+ - add `enable_xformers=True` in `-update` to enable xformers for speeding up.
102
+ - add `gradient_checkpoint=True` in `-update` to use gradient checkpoint for low VRAM.
103
+
104
+ ### Case: Sydney Opera House in ink painting style
105
+
106
+ **Preview:**
107
+
108
+ | <img src="./img/SydneyOperaHouse-ink/svg_iter0.svg"> | <img src="./img/SydneyOperaHouse-ink/svg_iter100.svg"> | <img src="./img/SydneyOperaHouse-ink/svg_iter200.svg"> | <img src="./img/SydneyOperaHouse-ink/visual_best.svg"> |
109
+ |------------------------------------------------------|--------------------------------------------------------|--------------------------------------------------------|--------------------------------------------------------|
110
+ | Strokes Initialization | 100 step | 200 step | 990 step |
111
+
112
+ **Script:**
113
+
114
+ ```shell
115
+ python run_painterly_render.py \
116
+ -c diffsketcher-width.yaml \
117
+ -eval_step 10 -save_step 10 \
118
+ -update "token_ind=4 num_paths=48 num_iter=800" \
119
+ -pt "a photo of Sydney opera house" \
120
+ -respath ./workdir/sydney_opera_house_ink \
121
+ -d 8019 \
122
+ --download
123
+ ```
124
+
125
+ ### Oil Painting
126
+
127
+ **Preview:**
128
+
129
+ | <img src="./img/LatinWomanPortrait/svg_iter0.svg"> | <img src="./img/LatinWomanPortrait/svg_iter100.svg"> | <img src="./img/LatinWomanPortrait/visual_best.svg"> |
130
+ |----------------------------------------------------|------------------------------------------------------|------------------------------------------------------|
131
+ | Strokes Initialization | 100 step | 570 step |
132
+
133
+ **Script:**
134
+
135
+ ```shell
136
+ python run_painterly_render.py \
137
+ -c diffsketcher-color.yaml \
138
+ -eval_step 10 -save_step 10 \
139
+ -update "token_ind=5 num_paths=1000 num_iter=1000 guidance_scale=7.5" \
140
+ -pt "portrait of latin woman having a spiritual awaking, eyes closed, slight smile, illuminating lights, oil painting, by Van Gogh" \
141
+ -npt "text, signature, title, heading, watermark, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, out of frame, ugly, extra limbs, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, mutated hands, fused fingers, too many fingers, long neck" \
142
+ -respath ./workdir/latin_woman_portrait -d 58548
143
+ ```
144
+
145
+ **Preview:**
146
+
147
+ | <img src="./img/WomanWithCrown/svg_iter0.svg"> | <img src="./img/WomanWithCrown/svg_iter100.svg"> | <img src="./img/WomanWithCrown/visual_best.svg"> |
148
+ |------------------------------------------------|--------------------------------------------------|--------------------------------------------------|
149
+ | Strokes Initialization | 100 step | 570 step |
150
+
151
+ **Script:**
152
+
153
+ ```shell
154
+ python run_painterly_render.py \
155
+ -c diffsketcher-color.yaml \
156
+ -eval_step 10 -save_step 10 \
157
+ -update "token_ind=5 num_paths=1000 num_iter=1000 guidance_scale=7.5" \
158
+ -pt "a painting of a woman with a crown on her head, art station front page, dynamic portrait style, many colors in the background, olpntng style, oil painting, forbidden beauty" \
159
+ -npt "2 heads, 2 faces, cropped image, out of frame, draft, deformed hands, twisted fingers, double image, malformed hands, multiple heads, extra limb, ugly, poorly drawn hands, missing limb, disfigured, cut-off, ugly, grain, low-res, Deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, floating limbs, disconnected limbs, disgusting, poorly drawn, mutilated, mangled, extra fingers, duplicate artifacts, morbid, gross proportions, missing arms, mutated hands, mutilated hands, cloned face, malformed, blur haze" \
160
+ -respath ./workdir/woman_with_crown -d 178351
161
+ ```
162
+
163
+ **Preview:**
164
+
165
+ | <img src="./img/BeautifulGirl_OilPainting/svg_iter0.svg"> | <img src="./img/BeautifulGirl_OilPainting/svg_iter100.svg"> | <img src="./img/BeautifulGirl_OilPainting/visual_best.svg"> |
166
+ |-----------------------------------------------------------|-------------------------------------------------------------|-------------------------------------------------------------|
167
+ | Strokes Initialization | 100 step | 420 step |
168
+
169
+ **Script:**
170
+
171
+ ```shell
172
+ python run_painterly_render.py \
173
+ -c diffsketcher-color.yaml \
174
+ -eval_step 10 -save_step 10 \
175
+ -update "token_ind=5 num_paths=1000 num_iter=1000 guidance_scale=7.5" \
176
+ -pt "a painting of a woman with a crown on her head, art station front page, dynamic portrait style, many colors in the background, olpntng style, oil painting, forbidden beauty" \
177
+ -npt "2 heads, 2 faces, cropped image, out of frame, draft, deformed hands, twisted fingers, double image, malformed hands, multiple heads, extra limb, ugly, poorly drawn hands, missing limb, disfigured, cut-off, ugly, grain, low-res, Deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, floating limbs, disconnected limbs, disgusting, poorly drawn, mutilated, mangled, extra fingers, duplicate artifacts, morbid, gross proportions, missing arms, mutated hands, mutilated hands, cloned face, malformed, blur haze" \
178
+ -respath ./workdir/woman_with_crown -d 178351
179
+ ```
180
+
181
+ ### Colorful Results
182
+
183
+ **Preview:**
184
+
185
+ | <img src="./img/castle-rgba/svg_iter0.svg"> | <img src="./img/castle-rgba/svg_iter100.svg"> | <img src="./img/castle-rgba/visual_best.svg"> |
186
+ |---------------------------------------------|-----------------------------------------------|-----------------------------------------------|
187
+ | Strokes Initialization | 100 step | 340 step |
188
+
189
+ **Script:**
190
+
191
+ ```shell
192
+ python run_painterly_render.py \
193
+ -c diffsketcher-color.yaml \
194
+ -eval_step 10 -save_step 10 \
195
+ -update "token_ind=5 num_paths=1000 num_iter=800 guidance_scale=7" \
196
+ -pt "a beautiful snow-covered castle, a stunning masterpiece, trees, rays of the sun, Leonid Afremov" \
197
+ -npt "poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face" \
198
+ -respath ./workdir/castle -d 370880
199
+ ```
200
+
201
+ **Preview:**
202
+
203
+ | <img src="./img/castle-rgba-2/svg_iter0.svg"> | <img src="./img/castle-rgba-2/svg_iter100.svg"> | <img src="./img/castle-rgba-2/visual_best.svg"> |
204
+ |-----------------------------------------------|-------------------------------------------------|-------------------------------------------------|
205
+ | Strokes Initialization | 100 step | 850 step |
206
+
207
+ **Script:**
208
+
209
+ ```shell
210
+ python run_painterly_render.py \
211
+ -c diffsketcher-color.yaml \
212
+ -eval_step 10 -save_step 10 \
213
+ -update "token_ind=5 num_paths=1000 num_iter=800 guidance_scale=7" \
214
+ -pt "a beautiful snow-covered castle, a stunning masterpiece, trees, rays of the sun, Leonid Afremov" \
215
+ -npt "poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face" \
216
+ -respath ./workdir/castle -d 478376
217
+ ```
218
+
219
+ ### DiffSketcher + Style Transfer
220
+
221
+ **Preview:**
222
+
223
+ | <img src="./img/FrenchRevolution-ST/generated.png" style="width: 250px; height: 250px;"> | <img src="./img/starry.jpg" style="width: 250px; height: 250px;"> | <img src="./img/FrenchRevolution-ST/french_ST.svg" style="width: 250px; height: 250px;"> |
224
+ |------------------------------------------------------------------------------------------|-------------------------------------------------------------------|------------------------------------------------------------------------------------------|
225
+ | Generated sample | Style Image | Result |
226
+
227
+ **Script:**
228
+
229
+ ```shell
230
+ python run_painterly_render.py \
231
+ -tk style-diffsketcher -c diffsketcher-style.yaml \
232
+ -eval_step 10 -save_step 10 \
233
+ -update "token_ind=4 num_paths=2000 style_warmup=0 style_strength=1 softmax_temp=0.4 sds.grad_scale=0 lr_scheduler=True num_iter=2000" \
234
+ -pt "The French Revolution, highly detailed, 8k, ornate, intricate, cinematic, dehazed, atmospheric, oil painting, by Van Gogh" \
235
+ -style ./img/starry.jpg \
236
+ -respath ./workdir/style_transfer \
237
+ -d 876809
238
+ ```
239
+
240
+ - `-style`: the path of style img place.
241
+ - `style_warmup`: add style loss after `style_warmup` step.
242
+ - `style_strength`: How strong the style should be. 100 (max) is a lot. 0 (min) is no style.
243
+
244
+ ### More Sketch Results
245
+
246
+ **check the [Examples.md](https://github.com/ximinng/DiffSketcher/blob/main/Examples.md) for more cases.**
247
+
248
+ ### TODO
249
+
250
+ - [x] Add a webUI demo.
251
+ - [x] Add support for colorful results and oil painting.
252
+
253
+ ## :books: Acknowledgement
254
+
255
+ The project is built based on the following repository:
256
+
257
+ - [BachiLi/diffvg](https://github.com/BachiLi/diffvg)
258
+ - [yael-vinker/CLIPasso](https://github.com/yael-vinker/CLIPasso)
259
+ - [huggingface/diffusers](https://github.com/huggingface/diffusers)
260
+
261
+ We gratefully thank the authors for their wonderful works.
262
+
263
+ ## :paperclip: Citation
264
+
265
+ If you use this code for your research, please cite the following work:
266
+
267
+ ```
268
+ @inproceedings{xing2023diffsketcher,
269
+ title={DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models},
270
+ author={XiMing Xing and Chuang Wang and Haitao Zhou and Jing Zhang and Qian Yu and Dong Xu},
271
+ booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
272
+ year={2023},
273
+ url={https://openreview.net/forum?id=CY1xatvEQj}
274
+ }
275
+ ```
276
+
277
+ ## :copyright: Licence
278
+
279
+ This work is licensed under a MIT License.