Image-to-Image
Diffusers
Safetensors
StableDiffusionXLInpaintPipeline
stable-diffusion-xl
inpainting
background-editing
Instructions to use esalahterus/refo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use esalahterus/refo with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("esalahterus/refo", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
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,
|
| 39 |
-
mask_image=mask_image,
|
| 40 |
num_inference_steps=30,
|
| 41 |
guidance_scale=7.5,
|
| 42 |
-
strength=1.0,
|
|
|
|
| 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
|