YiYiXu commited on
Commit
694e7bf
·
1 Parent(s): b536772

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -23
README.md CHANGED
@@ -26,45 +26,45 @@ pip install diffusers transformers accelerate
26
  ### Text Guided Inpainting Generation
27
 
28
  ```python
29
- from diffusers import KandinskyInpaintPipeline, KandinskyPriorPipeline
30
  from diffusers.utils import load_image
31
  import torch
32
  import numpy as np
33
 
34
- pipe_prior = KandinskyPriorPipeline.from_pretrained(
35
- "kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
36
- )
37
- pipe_prior.to("cuda")
38
 
39
  prompt = "a hat"
40
- prior_output = pipe_prior(prompt)
41
-
42
- pipe = KandinskyInpaintPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-inpaint", torch_dtype=torch.float16)
43
- pipe.to("cuda")
44
 
45
- init_image = load_image(
46
  "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
47
  )
48
 
49
- mask = np.ones((768, 768), dtype=np.float32)
50
  # Let's mask out an area above the cat's head
51
- mask[:250, 250:-250] = 0
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
- image = out.images[0]
 
64
  image.save("cat_with_hat.png")
65
  ```
66
  ![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/inpaint_cat_hat.png)
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
  ![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/inpaint_cat_hat.png)
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