Buckets:
| # Text-guided 이미지 인페인팅(inpainting) | |
| `StableDiffusionInpaintPipeline`은 마스크와 텍스트 프롬프트를 제공하여 이미지의 특정 부분을 편집할 수 있도록 합니다. 이 기능은 인페인팅 작업을 위해 특별히 훈련된 [`stable-diffusion-v1-5/stable-diffusion-inpainting`](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting)과 같은 Stable Diffusion 버전을 사용합니다. | |
| 먼저 `StableDiffusionInpaintPipeline` 인스턴스를 불러옵니다: | |
| ```python | |
| import PIL | |
| import requests | |
| import torch | |
| from io import BytesIO | |
| from diffusers import StableDiffusionInpaintPipeline | |
| pipeline = StableDiffusionInpaintPipeline.from_pretrained( | |
| "stable-diffusion-v1-5/stable-diffusion-inpainting", | |
| torch_dtype=torch.float16, | |
| ) | |
| pipeline = pipeline.to("cuda") | |
| ``` | |
| 나중에 교체할 강아지 이미지와 마스크를 다운로드하세요: | |
| ```python | |
| def download_image(url): | |
| response = requests.get(url) | |
| return PIL.Image.open(BytesIO(response.content)).convert("RGB") | |
| img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" | |
| mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" | |
| init_image = download_image(img_url).resize((512, 512)) | |
| mask_image = download_image(mask_url).resize((512, 512)) | |
| ``` | |
| 이제 마스크를 다른 것으로 교체하라는 프롬프트를 만들 수 있습니다: | |
| ```python | |
| prompt = "Face of a yellow cat, high resolution, sitting on a park bench" | |
| image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0] | |
| ``` | |
| `image` | `mask_image` | `prompt` | output | | |
| :-------------------------:|:-------------------------:|:-------------------------:|-------------------------:| | |
| | | ***Face of a yellow cat, high resolution, sitting on a park bench*** | | | |
| > [!WARNING] | |
| > 이전의 실험적인 인페인팅 구현에서는 품질이 낮은 다른 프로세스를 사용했습니다. 이전 버전과의 호환성을 보장하기 위해 새 모델이 포함되지 않은 사전학습된 파이프라인을 불러오면 이전 인페인팅 방법이 계속 적용됩니다. | |
Xet Storage Details
- Size:
- 2.28 kB
- Xet hash:
- e9d2265130de125809797af14359f2d44a10ef8d11b46fff3dcc152e3651d57c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.