|
| 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