| <!--Copyright 2024 The HuggingFace Team. All rights reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations under the License. | |
| --> | |
| # Text-guided depth-to-image ์์ฑ | |
| [[open-in-colab]] | |
| [`StableDiffusionDepth2ImgPipeline`]์ ์ฌ์ฉํ๋ฉด ํ ์คํธ ํ๋กฌํํธ์ ์ด๊ธฐ ์ด๋ฏธ์ง๋ฅผ ์ ๋ฌํ์ฌ ์ ์ด๋ฏธ์ง์ ์์ฑ์ ์กฐ์ ํ ์ ์์ต๋๋ค. ๋ํ ์ด๋ฏธ์ง ๊ตฌ์กฐ๋ฅผ ๋ณด์กดํ๊ธฐ ์ํด `depth_map`์ ์ ๋ฌํ ์๋ ์์ต๋๋ค. `depth_map`์ด ์ ๊ณต๋์ง ์์ผ๋ฉด ํ์ดํ๋ผ์ธ์ ํตํฉ๋ [depth-estimation model](https://github.com/isl-org/MiDaS)์ ํตํด ์๋์ผ๋ก ๊น์ด๋ฅผ ์์ธกํฉ๋๋ค. | |
| ๋จผ์ [`StableDiffusionDepth2ImgPipeline`]์ ์ธ์คํด์ค๋ฅผ ์์ฑํฉ๋๋ค: | |
| ```python | |
| import torch | |
| import requests | |
| from PIL import Image | |
| from diffusers import StableDiffusionDepth2ImgPipeline | |
| pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-2-depth", | |
| torch_dtype=torch.float16, | |
| ).to("cuda") | |
| ``` | |
| ์ด์ ํ๋กฌํํธ๋ฅผ ํ์ดํ๋ผ์ธ์ ์ ๋ฌํฉ๋๋ค. ํน์ ๋จ์ด๊ฐ ์ด๋ฏธ์ง ์์ฑ์ ๊ฐ์ด๋ ํ๋๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด `negative_prompt`๋ฅผ ์ ๋ฌํ ์๋ ์์ต๋๋ค: | |
| ```python | |
| url = "http://images.cocodataset.org/val2017/000000039769.jpg" | |
| init_image = Image.open(requests.get(url, stream=True).raw) | |
| prompt = "two tigers" | |
| n_prompt = "bad, deformed, ugly, bad anatomy" | |
| image = pipe(prompt=prompt, image=init_image, negative_prompt=n_prompt, strength=0.7).images[0] | |
| image | |
| ``` | |
| | Input | Output | | |
| |---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------| | |
| | <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"/> | | |
| ์๋์ Spaces๋ฅผ ๊ฐ์ง๊ณ ๋๋ฉฐ depth map์ด ์๋ ์ด๋ฏธ์ง์ ์๋ ์ด๋ฏธ์ง์ ์ฐจ์ด๊ฐ ์๋์ง ํ์ธํด ๋ณด์ธ์! | |
| <iframe | |
| src="https://radames-stable-diffusion-depth2img.hf.space" | |
| frameborder="0" | |
| width="850" | |
| height="500" | |
| ></iframe> | |