File size: 2,135 Bytes
ed24caa
 
 
 
cd569e9
ed24caa
cd569e9
ed24caa
cd569e9
 
 
1cb0b53
 
ed24caa
 
cd569e9
ed24caa
3de3cfb
ed24caa
3de3cfb
ed24caa
3de3cfb
ed24caa
3de3cfb
ed24caa
 
 
cd569e9
ed24caa
cd569e9
ed24caa
cd569e9
 
 
 
 
ed24caa
34ca664
ed24caa
cd569e9
 
 
 
ed24caa
cd569e9
 
ed24caa
cd569e9
 
 
 
 
 
 
 
 
ed24caa
cd569e9
ed24caa
 
 
cd569e9
ed24caa
cd569e9
 
 
 
 
 
 
ed24caa
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
---
library_name: diffusers
---

# Paint by Inpaint: Learning to Add Image Objects by Removing Them First

The model is designed for instruction-following object addition to images.

We offer four different models:
- Trained on the PIPE dataset, specifically designed for object addition.
- The object addition model fine-tuned on a MagicBrush addition subset.
- Trained on the combined PIPE and InstructPix2Pix datasets, intended for general editing.
- **The general model fine-tuned on the full MagicBrush dataset (This one).**


## Resources

- ๐Ÿ’ป [**Visit Project Page**](https://rotsteinnoam.github.io/Paint-by-Inpaint/)

- ๐Ÿ“ [**Read the Paper**](https://arxiv.org/abs/2404.18212)

- ๐Ÿš€ [**Try Our Demo**](https://huggingface.co/spaces/paint-by-inpaint/demo)

- ๐Ÿ—‚๏ธ [**Use PIPE Dataset**](https://huggingface.co/datasets/paint-by-inpaint/PIPE)



#### Running the model

The model is simple to run using the InstructPix2Pix pipeline:

```python
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
import torch
import requests
from io import BytesIO

model_name = "paint-by-inpaint/general-finetuned-mb"

diffusion_steps = 50
device = "cuda"
image_url = "https://paint-by-inpaint-demo.hf.space/file=/tmp/gradio/99cd3a15aa9bdd3220b4063ebc3ac05e07a611b8/messi.jpeg"
image = Image.open(BytesIO(requests.get(image_url).content)).resize((512, 512))

pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_name, torch_dtype=torch.float16, safety_checker=None).to(device)
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)

# Generate the modified image
out_images = pipe(
    "Add a royal silver crown", 
    image=image, 
    guidance_scale=7, 
    image_guidance_scale=1.5, 
    num_inference_steps=diffusion_steps,
    num_images_per_prompt=1
).images

```



## BibTeX

``` Citation
@article{wasserman2024paint,
  title={Paint by Inpaint: Learning to Add Image Objects by Removing Them First},
  author={Wasserman, Navve and Rotstein, Noam and Ganz, Roy and Kimmel, Ron},
  journal={arXiv preprint arXiv:2404.18212},
  year={2024}
}