Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DiffSketcher
|
| 2 |
+
|
| 3 |
+
This is a Hugging Face implementation of [DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models](https://github.com/ximinng/DiffSketcher).
|
| 4 |
+
|
| 5 |
+
## Model Description
|
| 6 |
+
|
| 7 |
+
DiffSketcher is a novel approach for synthesizing vector sketches from text prompts by leveraging the power of latent diffusion models. It extracts cross-attention maps from a pre-trained text-to-image diffusion model and uses them to guide the optimization of vector sketches.
|
| 8 |
+
|
| 9 |
+
## Usage
|
| 10 |
+
|
| 11 |
+
```python
|
| 12 |
+
from diffusers import DiffusionPipeline
|
| 13 |
+
|
| 14 |
+
# Load the pipeline
|
| 15 |
+
pipeline = DiffusionPipeline.from_pretrained("jree423/diffsketcher")
|
| 16 |
+
|
| 17 |
+
# Generate a vector sketch
|
| 18 |
+
result = pipeline(
|
| 19 |
+
prompt="A beautiful sunset over the mountains",
|
| 20 |
+
negative_prompt="ugly, blurry",
|
| 21 |
+
num_paths=96,
|
| 22 |
+
token_ind=4,
|
| 23 |
+
num_iter=800,
|
| 24 |
+
guidance_scale=7.5,
|
| 25 |
+
width=1.5,
|
| 26 |
+
seed=42
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Access the SVG string and rendered image
|
| 30 |
+
svg_string = result["svg"]
|
| 31 |
+
image = result["image"]
|
| 32 |
+
|
| 33 |
+
# Save the SVG
|
| 34 |
+
with open("sunset_sketch.svg", "w") as f:
|
| 35 |
+
f.write(svg_string)
|
| 36 |
+
|
| 37 |
+
# Save the image
|
| 38 |
+
image.save("sunset_sketch.png")
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Parameters
|
| 42 |
+
|
| 43 |
+
- `prompt` (str): The text prompt to guide the sketch generation.
|
| 44 |
+
- `negative_prompt` (str, optional): Negative text prompt for guidance.
|
| 45 |
+
- `num_paths` (int, optional): Number of paths to use in the sketch. Default is 96.
|
| 46 |
+
- `token_ind` (int, optional): Token index for attention. Default is 4.
|
| 47 |
+
- `num_iter` (int, optional): Number of optimization iterations. Default is 800.
|
| 48 |
+
- `guidance_scale` (float, optional): Scale for classifier-free guidance. Default is 7.5.
|
| 49 |
+
- `width` (float, optional): Stroke width. Default is 1.5.
|
| 50 |
+
- `seed` (int, optional): Random seed for reproducibility.
|
| 51 |
+
- `return_dict` (bool, optional): Whether to return a dict or tuple. Default is True.
|
| 52 |
+
- `output_type` (str, optional): Output type, one of "pil", "np", or "svg". Default is "pil".
|
| 53 |
+
|
| 54 |
+
## Citation
|
| 55 |
+
|
| 56 |
+
```bibtex
|
| 57 |
+
@article{xing2023diffsketcher,
|
| 58 |
+
title={DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models},
|
| 59 |
+
author={Xing, Ximing and Xie, Chuang and Qiao, Yu and Xu, Hongteng},
|
| 60 |
+
journal={arXiv preprint arXiv:2306.14685},
|
| 61 |
+
year={2023}
|
| 62 |
+
}
|
| 63 |
+
```
|