Skip to content

Commit 27f08dd

Browse files
authored
Merge pull request #18 from szjung-test/inpaint
Inpaint ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ ์™„๋ฃŒ
2 parents bb694e8 + dffbfe0 commit 27f08dd

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# ํ…์ŠคํŠธ-๊ฐ€์ด๋“œ ์ด๋ฏธ์ง€-์ธํŽ˜์ธํŒ…(inpainting)
14+
15+
[[์ฝœ๋žฉ์—์„œ ์—ด๊ธฐ]]
16+
17+
[`StableDiffusionInpaintPipeline`]์€ ๋งˆ์Šคํฌ์™€ ํ…์ŠคํŠธ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ œ๊ณตํ•˜์—ฌ ์ด๋ฏธ์ง€์˜ ํŠน์ • ๋ถ€๋ถ„์„ ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ธฐ๋Šฅ์€ ์ธํŽ˜์ธํŒ… ์ž‘์—…์„ ์œ„ํ•ด ํŠน๋ณ„ํžˆ ํ›ˆ๋ จ๋œ [`runwayml/stable-diffusion-inpainting`](https://huggingface.co/runwayml/stable-diffusion-inpainting)๊ณผ ๊ฐ™์€ Stable Diffusion ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
18+
19+
๋จผ์ € [`StableDiffusionInpaintPipeline`] ์ธ์Šคํ„ด์Šค๋ฅผ ๋กœ๋“œํ•˜์—ฌ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค:
20+
21+
```python
22+
import PIL
23+
import requests
24+
import torch
25+
from io import BytesIO
26+
27+
from diffusers import StableDiffusionInpaintPipeline
28+
29+
pipeline = StableDiffusionInpaintPipeline.from_pretrained(
30+
"runwayml/stable-diffusion-inpainting",
31+
torch_dtype=torch.float16,
32+
)
33+
pipeline = pipeline.to("cuda")
34+
```
35+
36+
๋‚˜์ค‘์— ๊ต์ฒดํ•  ๊ฐ•์•„์ง€ ์ด๋ฏธ์ง€์™€ ๋งˆ์Šคํฌ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”:
37+
38+
```python
39+
def download_image(url):
40+
response = requests.get(url)
41+
return PIL.Image.open(BytesIO(response.content)).convert("RGB")
42+
43+
44+
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
45+
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
46+
47+
init_image = download_image(img_url).resize((512, 512))
48+
mask_image = download_image(mask_url).resize((512, 512))
49+
```
50+
51+
์ด์ œ ๋งˆ์Šคํฌ๋ฅผ ๋‹ค๋ฅธ ๊ฒƒ์œผ๋กœ ๊ต์ฒดํ•˜๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
52+
53+
```python
54+
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
55+
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
56+
```
57+
58+
| `image` | `mask_image` | `prompt` | output |
59+
| :----------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------: | -----------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
60+
| <img src="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" alt="drawing" width="250"/> | <img src="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" alt="drawing" width="250"/> | **_Face of a yellow cat, high resolution, sitting on a park bench_** | <img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/in_paint/yellow_cat_sitting_on_a_park_bench.png" alt="drawing" width="250"/> |
61+
62+
<ํŒ ๊ฒฝ๊ณ ={true}>
63+
64+
์ด์ „์˜ ์‹คํ—˜์ ์ธ ์ธํŽ˜์ธํŒ… ๊ตฌํ˜„์—์„œ๋Š” ํ’ˆ์งˆ์ด ๋‚ฎ์€ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด์ „ ๋ฒ„์ „๊ณผ์˜ ํ˜ธํ™˜์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ์ƒˆ ๋ชจ๋ธ์ด ํฌํ•จ๋˜์ง€ ์•Š์€ ์‚ฌ์ „ ํ•™์Šต๋œ ํŒŒ์ดํ”„๋ผ์ธ์„ ๋กœ๋“œํ•˜๋ฉด ์ด์ „ ์ธํŽ˜์ธํŒ… ๋ฐฉ๋ฒ•์ด ๊ณ„์† ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
65+
66+
</ํŒ>
67+
68+
์•„๋ž˜ Space์—์„œ ์ด๋ฏธ์ง€ ํŽ˜์ธํŒ…์„ ์ง์ ‘ ํ•ด๋ณด์„ธ์š”!
69+
70+
<iframe
71+
src="https://runwayml-stable-diffusion-inpainting.hf.space"
72+
frameborder="0"
73+
width="850"
74+
height="500"
75+
></iframe>

0 commit comments

Comments
ย (0)