esalahterus commited on
Commit
ff71f2f
·
verified ·
1 Parent(s): 0914713

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -3
README.md CHANGED
@@ -26,21 +26,38 @@ Fine-tuned checkpoint of [`diffusers/stable-diffusion-xl-1.0-inpainting-0.1`](ht
26
 
27
  ```python
28
  import torch
 
29
  from diffusers import StableDiffusionXLInpaintPipeline
30
 
31
  pipe = StableDiffusionXLInpaintPipeline.from_pretrained(
32
  "esalahterus/refo", torch_dtype=torch.bfloat16
33
  ).to("cuda")
34
 
 
 
 
35
  result = pipe(
36
  prompt="a high quality photo background, a quiet beach at sunset, photorealistic, detailed, no people, no text",
37
  negative_prompt="low quality, blurry foreground, distorted subject, watermark, text",
38
- image=source_image, # source photo
39
- mask_image=mask_image, # white = background area to edit, black = subject to preserve
40
  num_inference_steps=30,
41
  guidance_scale=7.5,
42
- strength=1.0, # important: use exactly 1.0 — values like 0.99 only blend lightly instead of fully regenerating the masked area
 
43
  ).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
44
  ```
45
 
46
  ## Intended Use
 
26
 
27
  ```python
28
  import torch
29
+ from PIL import Image
30
  from diffusers import StableDiffusionXLInpaintPipeline
31
 
32
  pipe = StableDiffusionXLInpaintPipeline.from_pretrained(
33
  "esalahterus/refo", torch_dtype=torch.bfloat16
34
  ).to("cuda")
35
 
36
+ source_image = Image.open("path/to/your_image.jpg").convert("RGB")
37
+ mask_image = Image.open("path/to/your_mask.png").convert("L") # white = area to edit, black = area to keep
38
+
39
  result = pipe(
40
  prompt="a high quality photo background, a quiet beach at sunset, photorealistic, detailed, no people, no text",
41
  negative_prompt="low quality, blurry foreground, distorted subject, watermark, text",
42
+ image=source_image,
43
+ mask_image=mask_image,
44
  num_inference_steps=30,
45
  guidance_scale=7.5,
46
+ strength=1.0, # important: use exactly 1.0 — values like 0.99 only blend lightly instead of fully regenerating the masked area
47
+ generator=torch.Generator(device="cuda").manual_seed(0), # optional, for reproducible results
48
  ).images[0]
49
+
50
+ result.save("output.png")
51
+ ```
52
+
53
+ No mask image? You can auto-generate a foreground mask with [`rembg`](https://github.com/danielgatis/rembg):
54
+
55
+ ```python
56
+ from rembg import remove, new_session
57
+
58
+ session = new_session("u2net")
59
+ fg_mask = remove(source_image, session=session, only_mask=True).convert("L")
60
+ mask_image = Image.eval(fg_mask, lambda x: 255 - x) # invert so white = background
61
  ```
62
 
63
  ## Intended Use