|
| 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 | +# Text-guided depth-to-image 생성 |
| 14 | + |
| 15 | +[[open-in-colab]] |
| 16 | + |
| 17 | +[`StableDiffusionDepth2ImgPipeline`]을 사용하면 텍스트 프롬프트와 초기 이미지를 전달하여 새 이미지의 생성을 조절할 수 있습니다. 또한 이미지 구조를 보존하기 위해 `depth_map`을 전달할 수도 있습니다. `depth_map`이 제공되지 않으면 파이프라인은 통합된 [depth-estimation model](https://github.com/isl-org/MiDaS)을 통해 자동으로 깊이를 예측합니다. |
| 18 | + |
| 19 | + |
| 20 | +먼저 [`StableDiffusionDepth2ImgPipeline`]의 인스턴스를 생성합니다: |
| 21 | + |
| 22 | +```python |
| 23 | +import torch |
| 24 | +import requests |
| 25 | +from PIL import Image |
| 26 | + |
| 27 | +from diffusers import StableDiffusionDepth2ImgPipeline |
| 28 | + |
| 29 | +pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( |
| 30 | + "stabilityai/stable-diffusion-2-depth", |
| 31 | + torch_dtype=torch.float16, |
| 32 | +).to("cuda") |
| 33 | +``` |
| 34 | + |
| 35 | +이제 프롬프트를 파이프라인에 전달합니다. 특정 단어가 이미지 생성을 가이드 하는것을 방지하기 위해 `negative_prompt`를 전달할 수도 있습니다: |
| 36 | + |
| 37 | +```python |
| 38 | +url = "http://images.cocodataset.org/val2017/000000039769.jpg" |
| 39 | +init_image = Image.open(requests.get(url, stream=True).raw) |
| 40 | +prompt = "two tigers" |
| 41 | +n_prompt = "bad, deformed, ugly, bad anatomy" |
| 42 | +image = pipe(prompt=prompt, image=init_image, negative_prompt=n_prompt, strength=0.7).images[0] |
| 43 | +image |
| 44 | +``` |
| 45 | + |
| 46 | +| Input | Output | |
| 47 | +|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------| |
| 48 | +| <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/coco-cats.png" width="500"/> | <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/depth2img-tigers.png" width="500"/> | |
| 49 | + |
| 50 | +아래의 스페이스를 가지고 놀며 depth map이 있는 이미지와 없는 이미지의 차이가 있는지 확인해 보세요! |
| 51 | + |
| 52 | +<iframe |
| 53 | + src="https://radames-stable-diffusion-depth2img.hf.space" |
| 54 | + frameborder="0" |
| 55 | + width="850" |
| 56 | + height="500" |
| 57 | +></iframe> |
0 commit comments