Update README.md
Browse files
README.md
CHANGED
@@ -26,45 +26,45 @@ pip install diffusers transformers accelerate
|
|
26 |
### Text Guided Inpainting Generation
|
27 |
|
28 |
```python
|
29 |
-
from diffusers import
|
30 |
from diffusers.utils import load_image
|
31 |
import torch
|
32 |
import numpy as np
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
)
|
37 |
-
pipe_prior.to("cuda")
|
38 |
|
39 |
prompt = "a hat"
|
40 |
-
|
41 |
-
|
42 |
-
pipe = KandinskyInpaintPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-inpaint", torch_dtype=torch.float16)
|
43 |
-
pipe.to("cuda")
|
44 |
|
45 |
-
|
46 |
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
|
47 |
)
|
48 |
|
49 |
-
mask = np.
|
50 |
# Let's mask out an area above the cat's head
|
51 |
-
mask[:250, 250:-250] =
|
52 |
-
|
53 |
-
out = pipe(
|
54 |
-
prompt,
|
55 |
-
image=init_image,
|
56 |
-
mask_image=mask,
|
57 |
-
**prior_output,
|
58 |
-
height=768,
|
59 |
-
width=768,
|
60 |
-
num_inference_steps=150,
|
61 |
-
)
|
62 |
|
63 |
-
|
|
|
64 |
image.save("cat_with_hat.png")
|
65 |
```
|
66 |

|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
## Model Architecture
|
70 |
|
|
|
26 |
### Text Guided Inpainting Generation
|
27 |
|
28 |
```python
|
29 |
+
from diffusers import AutoPipelineForInpainting
|
30 |
from diffusers.utils import load_image
|
31 |
import torch
|
32 |
import numpy as np
|
33 |
|
34 |
+
pipe = AutoPipelineForInpainting.from_pretrained("kandinsky-community/kandinsky-2-1-inpaint", torch_dtype=torch.float16)
|
35 |
+
pipe.enable_model_cpu_offload()
|
|
|
|
|
36 |
|
37 |
prompt = "a hat"
|
38 |
+
negative_prompt = "low quality, bad quality"
|
|
|
|
|
|
|
39 |
|
40 |
+
original_image = load_image(
|
41 |
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
|
42 |
)
|
43 |
|
44 |
+
mask = np.zeros((768, 768), dtype=np.float32)
|
45 |
# Let's mask out an area above the cat's head
|
46 |
+
mask[:250, 250:-250] = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
|
49 |
+
image = pipe(prompt=prompt, image=original_image, mask_image=mask).images[0]
|
50 |
image.save("cat_with_hat.png")
|
51 |
```
|
52 |

|
53 |
|
54 |
+
__<font color=red>Breaking change on the mask input:</font>__
|
55 |
+
|
56 |
+
We introduced a breaking change for Kandinsky inpainting pipeline in the following pull request: https://github.com/huggingface/diffusers/pull/4207. Previously we accepted a mask format where black pixels represent the masked-out area. We have changed to use white pixels to represent masks instead in order to have a unified mask format across all our pipelines.
|
57 |
+
Please upgrade your inpainting code to follow the above. If you are using Kandinsky Inpaint in production. You now need to change the mask to:
|
58 |
+
|
59 |
+
```python
|
60 |
+
# For PIL input
|
61 |
+
import PIL.ImageOps
|
62 |
+
mask = PIL.ImageOps.invert(mask)
|
63 |
+
|
64 |
+
# For PyTorch and Numpy input
|
65 |
+
mask = 1 - mask
|
66 |
+
```
|
67 |
+
|
68 |
|
69 |
## Model Architecture
|
70 |
|