Skip to content

Commit 8124863

Browse files
Initial docs update for new in-painting pipeline (huggingface#910)
Docs update for new in-painting pipeline. Co-authored-by: Patrick von Platen <[email protected]>
1 parent 89d1249 commit 8124863

File tree

4 files changed

+57
-48
lines changed

4 files changed

+57
-48
lines changed

README.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,16 @@ You can also run this example on colab [![Open In Colab](https://colab.research.
210210

211211
### In-painting using Stable Diffusion
212212

213-
The `StableDiffusionInpaintPipeline` lets you edit specific parts of an image by providing a mask and text prompt.
213+
The `StableDiffusionInpaintPipeline` lets you edit specific parts of an image by providing a mask and a text prompt. It uses a model optimized for this particular task, whose license you need to accept before use.
214214

215-
```python
216-
from io import BytesIO
215+
Please, visit the [model card](https://huggingface.co/runwayml/stable-diffusion-inpainting), read the license carefully and tick the checkbox if you agree. Note that this is an additional license, you need to accept it even if you accepted the text-to-image Stable Diffusion license in the past. You have to be a registered user in 🤗 Hugging Face Hub, and you'll also need to use an access token for the code to work. For more information on access tokens, please refer to [this section](https://huggingface.co/docs/hub/security-tokens) of the documentation.
217216

218-
import torch
219-
import requests
217+
218+
```python
220219
import PIL
220+
import requests
221+
import torch
222+
from io import BytesIO
221223

222224
from diffusers import StableDiffusionInpaintPipeline
223225

@@ -231,21 +233,15 @@ mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data
231233
init_image = download_image(img_url).resize((512, 512))
232234
mask_image = download_image(mask_url).resize((512, 512))
233235

234-
device = "cuda"
235-
model_id_or_path = "CompVis/stable-diffusion-v1-4"
236236
pipe = StableDiffusionInpaintPipeline.from_pretrained(
237-
model_id_or_path,
238-
revision="fp16",
237+
"runwayml/stable-diffusion-inpainting",
238+
revision="fp16",
239239
torch_dtype=torch.float16,
240240
)
241-
# or download via git clone https://huggingface.co/CompVis/stable-diffusion-v1-4
242-
# and pass `model_id_or_path="./stable-diffusion-v1-4"`.
243-
pipe = pipe.to(device)
244-
245-
prompt = "a cat sitting on a bench"
246-
images = pipe(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images
241+
pipe = pipe.to("cuda")
247242

248-
images[0].save("cat_on_bench.png")
243+
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
244+
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
249245
```
250246

251247
### Tweak prompts reusing seeds and latents

docs/source/api/pipelines/overview.mdx

+10-10
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ You can generate your own latents to reproduce results, or tweak your prompt on
151151
The `StableDiffusionInpaintPipeline` lets you edit specific parts of an image by providing a mask and text prompt.
152152

153153
```python
154-
from io import BytesIO
155-
156-
import requests
157154
import PIL
155+
import requests
156+
import torch
157+
from io import BytesIO
158158

159159
from diffusers import StableDiffusionInpaintPipeline
160160

@@ -170,15 +170,15 @@ mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data
170170
init_image = download_image(img_url).resize((512, 512))
171171
mask_image = download_image(mask_url).resize((512, 512))
172172

173-
device = "cuda"
174173
pipe = StableDiffusionInpaintPipeline.from_pretrained(
175-
"CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16
176-
).to(device)
177-
178-
prompt = "a cat sitting on a bench"
179-
images = pipe(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images
174+
"runwayml/stable-diffusion-inpainting",
175+
revision="fp16",
176+
torch_dtype=torch.float16,
177+
)
178+
pipe = pipe.to("cuda")
180179

181-
images[0].save("cat_on_bench.png")
180+
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
181+
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
182182
```
183183

184184
You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb)

docs/source/using-diffusers/inpaint.mdx

+26-11
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ specific language governing permissions and limitations under the License.
1212

1313
# Text-Guided Image-Inpainting
1414

15-
The [`StableDiffusionInpaintPipeline`] lets you edit specific parts of an image by providing a mask and text prompt.
15+
The [`StableDiffusionInpaintPipeline`] lets you edit specific parts of an image by providing a mask and a text prompt. It uses a version of Stable Diffusion specifically trained for in-painting tasks.
1616

17-
```python
18-
from io import BytesIO
17+
<Tip warning={true}>
18+
Note that this model is distributed separately from the regular Stable Diffusion model, so you have to accept its license even if you accepted the Stable Diffusion one in the past.
1919

20-
import requests
20+
Please, visit the [model card](https://huggingface.co/runwayml/stable-diffusion-inpainting), read the license carefully and tick the checkbox if you agree. You have to be a registered user in 🤗 Hugging Face Hub, and you'll also need to use an access token for the code to work. For more information on access tokens, please refer to [this section](https://huggingface.co/docs/hub/security-tokens) of the documentation.
21+
</Tip>
22+
23+
```python
2124
import PIL
25+
import requests
26+
import torch
27+
from io import BytesIO
2228

2329
from diffusers import StableDiffusionInpaintPipeline
2430

@@ -34,15 +40,24 @@ mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data
3440
init_image = download_image(img_url).resize((512, 512))
3541
mask_image = download_image(mask_url).resize((512, 512))
3642

37-
device = "cuda"
3843
pipe = StableDiffusionInpaintPipeline.from_pretrained(
39-
"CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16
40-
).to(device)
44+
"runwayml/stable-diffusion-inpainting",
45+
revision="fp16",
46+
torch_dtype=torch.float16,
47+
)
48+
pipe = pipe.to("cuda")
49+
50+
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
51+
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
52+
```
4153

42-
prompt = "a cat sitting on a bench"
43-
images = pipe(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images
54+
`image` | `mask_image` | `prompt` | **Output** |
55+
:-------------------------:|:-------------------------:|:-------------------------:|-------------------------:|
56+
<img src="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" alt="drawing" width="250"/> | <img src="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" alt="drawing" width="250"/> | ***Face of a yellow cat, high resolution, sitting on a park bench*** | <img src="https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/test.png" alt="drawing" width="250"/> |
4457

45-
images[0].save("cat_on_bench.png")
46-
```
4758

4859
You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb)
60+
61+
<Tip warning={true}>
62+
A previous experimental implementation of in-painting used a different, lower-quality process. To ensure backwards compatibility, loading a pretrained pipeline that doesn't contain the new model will still apply the old in-painting method.
63+
</Tip>

src/diffusers/pipelines/README.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ You can generate your own latents to reproduce results, or tweak your prompt on
141141
The `StableDiffusionInpaintPipeline` lets you edit specific parts of an image by providing a mask and text prompt.
142142

143143
```python
144-
from io import BytesIO
145-
146-
import requests
147144
import PIL
145+
import requests
146+
import torch
147+
from io import BytesIO
148148

149149
from diffusers import StableDiffusionInpaintPipeline
150150

@@ -158,17 +158,15 @@ mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data
158158
init_image = download_image(img_url).resize((512, 512))
159159
mask_image = download_image(mask_url).resize((512, 512))
160160

161-
device = "cuda"
162161
pipe = StableDiffusionInpaintPipeline.from_pretrained(
163-
"CompVis/stable-diffusion-v1-4",
164-
revision="fp16",
162+
"runwayml/stable-diffusion-inpainting",
163+
revision="fp16",
165164
torch_dtype=torch.float16,
166-
).to(device)
167-
168-
prompt = "a cat sitting on a bench"
169-
images = pipe(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images
165+
)
166+
pipe = pipe.to("cuda")
170167

171-
images[0].save("cat_on_bench.png")
168+
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
169+
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
172170
```
173171

174172
You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb)

0 commit comments

Comments
 (0)