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