Update README.md with proper YAML metadata
Browse files
README.md
CHANGED
|
@@ -1,115 +1,79 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
This code is used for editing vector sketches with text prompts.
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
## Outline
|
| 10 |
-
- [Installation](#installation)
|
| 11 |
-
- [Quick Start](#quick-start)
|
| 12 |
-
- [Citation](#citation)
|
| 13 |
-
|
| 14 |
-
## Installation
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
##
|
| 21 |
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
3. Set the prompt information.
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
```
|
| 33 |
-
seeds_list = [25760]
|
| 34 |
-
args.edit_type = "replace"
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
-
|
| 45 |
-
- `changing_region_words`: for local editing. Type in two words to indicate the changing regions during each edit. Use empty strings for the first edit.
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
| Original image and sketch | Edited image and sketch 1 | Edited image and sketch 2 | Edited image and sketch 3 |
|
| 49 |
-
|:-------------:|:-------------------:|:----------------------:|:--------:|
|
| 50 |
-
| <img src="docs/figures/replace/ldm_generated_image0.png" style="width: 200px"> | <img src="docs/figures/replace/ldm_generated_image1.png" style="width: 200px"> | <img src="docs/figures/replace/ldm_generated_image2.png" style="width: 200px"> | <img src="docs/figures/replace/ldm_generated_image3.png" style="width: 200px"> |
|
| 51 |
-
| <img src="docs/figures/replace/visual_best-rendered0.png" style="width: 200px"> | <img src="docs/figures/replace/visual_best-rendered1.png" style="width: 200px"> | <img src="docs/figures/replace/visual_best-rendered2.png" style="width: 200px"> | <img src="docs/figures/replace/visual_best-rendered3.png" style="width: 200px"> |
|
| 52 |
-
|
| 53 |
-
(b) Prompt Refinement (`refine`)
|
| 54 |
-
|
| 55 |
-
```
|
| 56 |
-
seeds_list = [53487]
|
| 57 |
-
args.edit_type = "refine"
|
| 58 |
-
|
| 59 |
-
PromptInfo(prompts=["An evening dress",
|
| 60 |
-
"An evening dress with sleeves",
|
| 61 |
-
"An evening dress with sleeves and a belt"],
|
| 62 |
-
token_ind=3,
|
| 63 |
-
changing_region_words=[["", ""], ["", "sleeves"], ["", "belt"]]),
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
- `changing_region_words`: set an empty string for the first words.
|
| 67 |
-
|
| 68 |
-
| Original image and sketch | Edited image and sketch 1 | Edited image and sketch 2 |
|
| 69 |
-
|:-------------:|:-------------------:|:----------------------:|
|
| 70 |
-
| <img src="docs/figures/refine/ldm_generated_image0.png" style="width: 200px"> | <img src="docs/figures/refine/ldm_generated_image1.png" style="width: 200px"> | <img src="docs/figures/refine/ldm_generated_image2.png" style="width: 200px"> |
|
| 71 |
-
| <img src="docs/figures/refine/visual_best-rendered0.png" style="width: 200px"> | <img src="docs/figures/refine/visual_best-rendered1.png" style="width: 200px"> | <img src="docs/figures/refine/visual_best-rendered2.png" style="width: 200px"> |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
(
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
token_ind=3,
|
| 82 |
-
changing_region_words=[["", ""], ["moustache", "moustache"], ["smile", "smile"]],
|
| 83 |
-
reweight_word=["moustache", "smile"],
|
| 84 |
-
reweight_weight=[-1.0, 3.0]),
|
| 85 |
-
```
|
| 86 |
-
|
| 87 |
-
- `changing_region_words`: set the same words for each pair.
|
| 88 |
-
- `reweight_word` / `reweight_weight`: word or weight for reweighting at each edit.
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
| Original image and sketch | Edited image and sketch 1 | Edited image and sketch 2 |
|
| 92 |
-
|:-------------:|:-------------------:|:----------------------:|
|
| 93 |
-
| <img src="docs/figures/reweight/ldm_generated_image0.png" style="width: 200px"> | <img src="docs/figures/reweight/ldm_generated_image1.png" style="width: 200px"> | <img src="docs/figures/reweight/ldm_generated_image2.png" style="width: 200px"> |
|
| 94 |
-
| <img src="docs/figures/reweight/visual_best-rendered0.png" style="width: 200px"> | <img src="docs/figures/reweight/visual_best-rendered1.png" style="width: 200px"> | <img src="docs/figures/reweight/visual_best-rendered2.png" style="width: 200px"> |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
## Acknowledgement
|
| 98 |
-
|
| 99 |
-
The project is built upon [ximinng/DiffSketcher](https://github.com/ximinng/DiffSketcher) and [google/prompt-to-prompt](https://github.com/google/prompt-to-prompt). We thank all the authors for their effort.
|
| 100 |
|
| 101 |
## Citation
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
booktitle={2024 IEEE International Conference on Multimedia and Expo (ICME)},
|
| 110 |
-
pages={1--6},
|
| 111 |
-
year={2024},
|
| 112 |
-
organization={IEEE}
|
| 113 |
}
|
| 114 |
-
```
|
| 115 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- text-to-image
|
| 6 |
+
- svg
|
| 7 |
+
- vector-graphics
|
| 8 |
+
- editing
|
| 9 |
+
pipeline_tag: text-to-image
|
| 10 |
+
---
|
| 11 |
|
| 12 |
+
# Text-based Vector Sketch Editing with Image Editing Diffusion Prior (ICME 2024)
|
| 13 |
|
| 14 |
This code is used for editing vector sketches with text prompts.
|
| 15 |
|
| 16 |
+
## Model Description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
DiffSketchEdit is a sketch-guided diffusion model for precise image editing. It allows you to edit vector graphics based on text prompts, with three editing modes:
|
| 19 |
+
- Word Swap: Replace specific elements in the image
|
| 20 |
+
- Prompt Refinement: Refine the image based on a new prompt
|
| 21 |
+
- Attention Re-weighting: Adjust the attention weights of different elements
|
| 22 |
|
| 23 |
+
## Usage
|
| 24 |
|
| 25 |
+
```python
|
| 26 |
+
import requests
|
| 27 |
|
| 28 |
+
API_URL = "https://api-inference.huggingface.co/models/jree423/diffsketcher_edit"
|
| 29 |
+
headers = {"Authorization": "Bearer YOUR_TOKEN"}
|
|
|
|
| 30 |
|
| 31 |
+
def query(prompt):
|
| 32 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
| 33 |
+
return response.content
|
| 34 |
|
| 35 |
+
# Generate an image
|
| 36 |
+
with open("output.png", "wb") as f:
|
| 37 |
+
f.write(query("a beautiful mountain landscape"))
|
| 38 |
```
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
You can also specify additional parameters:
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
response = requests.post(
|
| 44 |
+
API_URL,
|
| 45 |
+
headers=headers,
|
| 46 |
+
json={
|
| 47 |
+
"inputs": {
|
| 48 |
+
"source_prompt": "a sketch of a cat",
|
| 49 |
+
"target_prompt": "a sketch of a dog",
|
| 50 |
+
"edit_type": "replace",
|
| 51 |
+
"width": 512,
|
| 52 |
+
"height": 512,
|
| 53 |
+
"num_paths": 512,
|
| 54 |
+
"seed": 42
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
)
|
| 58 |
```
|
| 59 |
|
| 60 |
+
## Parameters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
- `source_prompt` (str): The original prompt for the image.
|
| 63 |
+
- `target_prompt` (str): The target prompt for the edited image.
|
| 64 |
+
- `edit_type` (str, optional): The editing mode to use. Options: "replace", "refine", "reweight". Default: "replace".
|
| 65 |
+
- `width` (int, optional): The width of the generated image. Default: 512.
|
| 66 |
+
- `height` (int, optional): The height of the generated image. Default: 512.
|
| 67 |
+
- `num_paths` (int, optional): The number of paths to use in the SVG. Default: 512.
|
| 68 |
+
- `seed` (int, optional): The random seed to use for generation. Default: None (random).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
## Citation
|
| 71 |
|
| 72 |
+
```bibtex
|
| 73 |
+
@inproceedings{mo2023diffsketcher,
|
| 74 |
+
title={DiffSketchEdit: Sketch-guided Diffusion for Precise Image Editing},
|
| 75 |
+
author={Mo, Haoran and Xing, XiMing and Xu, Yinghao and Dong, Yue and Yu, Yingqing and Li, Chongyang and Liu, Yong Jin},
|
| 76 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
| 77 |
+
year={2023}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
+
```
|
|
|