patrickvonplaten commited on
Commit
418d8b5
1 Parent(s): 37bfdc5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Paint-By-Example
2
+
3
+ ## Overview
4
+
5
+ [Paint by Example: Exemplar-based Image Editing with Diffusion Models](https://arxiv.org/abs/2211.13227) by Binxin Yang, Shuyang Gu, Bo Zhang, Ting Zhang, Xuejin Chen, Xiaoyan Sun, Dong Chen, Fang Wen
6
+
7
+ The abstract of the paper is the following:
8
+
9
+ *Language-guided image editing has achieved great success recently. In this paper, for the first time, we investigate exemplar-guided image editing for more precise control. We achieve this goal by leveraging self-supervised training to disentangle and re-organize the source image and the exemplar. However, the naive approach will cause obvious fusing artifacts. We carefully analyze it and propose an information bottleneck and strong augmentations to avoid the trivial solution of directly copying and pasting the exemplar image. Meanwhile, to ensure the controllability of the editing process, we design an arbitrary shape mask for the exemplar image and leverage the classifier-free guidance to increase the similarity to the exemplar image. The whole framework involves a single forward of the diffusion model without any iterative optimization. We demonstrate that our method achieves an impressive performance and enables controllable editing on in-the-wild images with high fidelity.*
10
+
11
+ The original codebase can be found [here](https://github.com/Fantasy-Studio/Paint-by-Example).
12
+
13
+ ## Available Pipelines:
14
+
15
+ | Pipeline | Tasks | Colab
16
+ |---|---|:---:|
17
+ | [pipeline_paint_by_example.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py) | *Image-Guided Image Painting* | - |
18
+
19
+ ## Tips
20
+
21
+ - [Fantasy-Studio/Paint-by-Example](https://huggingface.co/Fantasy-Studio/Paint-by-Example) has been warm-started from the [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4) and with the objective to inpaint partly masked images conditioned on example / reference images
22
+ - To quickly demo *PaintByExample*, please have a look at [this demo](https://huggingface.co/spaces/Fantasy-Studio/Paint-by-Example).
23
+ - You can run the following code snippet as an example:
24
+
25
+ ```python
26
+ # !pip install diffusers transformers
27
+
28
+ import PIL
29
+ import requests
30
+ import torch
31
+ from io import BytesIO
32
+ from diffusers import DiffusionPipeline
33
+
34
+
35
+ def download_image(url):
36
+ response = requests.get(url)
37
+ return PIL.Image.open(BytesIO(response.content)).convert("RGB")
38
+
39
+
40
+ img_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/image/example_1.png"
41
+ mask_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/mask/example_1.png"
42
+ example_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/reference/example_1.jpg"
43
+
44
+ init_image = download_image(img_url).resize((512, 512))
45
+ mask_image = download_image(mask_url).resize((512, 512))
46
+ example_image = download_image(example_url).resize((512, 512))
47
+
48
+ pipe = DiffusionPipeline.from_pretrained(
49
+ "patrickvonplaten/new_inpaint_test",
50
+ torch_dtype=torch.float16,
51
+ )
52
+ pipe = pipe.to("cuda")
53
+
54
+ image = pipe(image=init_image, mask_image=mask_image, example_image=example_image).images[0]
55
+ image
56
+ ```