Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Usage:
|
| 2 |
+
|
| 3 |
+
```python
|
| 4 |
+
from diffusers import StableDiffusionInpaintPipeline
|
| 5 |
+
import torch
|
| 6 |
+
from diffusers.utils import load_image, make_image_grid
|
| 7 |
+
import PIL
|
| 8 |
+
|
| 9 |
+
# 指定模型文件路径
|
| 10 |
+
model_path = "Liangyingping/L2M-Inpainting" # 替换为你自己的模型路径
|
| 11 |
+
|
| 12 |
+
# 加载模型
|
| 13 |
+
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 14 |
+
model_path, torch_dtype=torch.float16, local_files_only=True
|
| 15 |
+
)
|
| 16 |
+
pipe.to("cuda") # 如果有 GPU,可以将模型加载到 GPU 上
|
| 17 |
+
|
| 18 |
+
init_image = load_image("assets/debug_masked_image.png")
|
| 19 |
+
mask_image = load_image("assets/debug_mask.png")
|
| 20 |
+
W, H = init_image.size
|
| 21 |
+
|
| 22 |
+
prompt = "a photo of a person"
|
| 23 |
+
image = pipe(
|
| 24 |
+
prompt=prompt,
|
| 25 |
+
image=init_image,
|
| 26 |
+
mask_image=mask_image,
|
| 27 |
+
h=512, w=512
|
| 28 |
+
).images[0].resize((W, H))
|
| 29 |
+
|
| 30 |
+
print(image.size, init_image.size)
|
| 31 |
+
|
| 32 |
+
image2save = make_image_grid([init_image, mask_image, image], rows=1, cols=3)
|
| 33 |
+
image2save.save("image2save_ours.png")
|
| 34 |
+
```
|