Buckets:

mishig's picture
|
download
raw
1.92 kB
# 文本引导的深度图到图像生成
[StableDiffusionDepth2ImgPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline) 允许你传入文本提示词和初始图像,以作为生成新图像的条件。此外,你还可以传入 `depth_map` 来保留图像结构。如果未提供 `depth_map`,该流水线会通过集成的 [深度估计模型](https://github.com/isl-org/MiDaS) 自动预测深度。
首先,创建一个 [StableDiffusionDepth2ImgPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline) 的实例:
```python
import torch
from diffusers import StableDiffusionDepth2ImgPipeline
from diffusers.utils import load_image, make_image_grid
pipeline = StableDiffusionDepth2ImgPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-depth",
dtype=torch.float16,
use_safetensors=True,
).to("cuda") # or "mps", "xpu", "cpu"
```
现在将您的提示词传递给 pipeline。您还可以传入 `negative_prompt`,以防止某些词语影响图像的生成方式:
```python
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
init_image = load_image(url)
prompt = "two tigers"
negative_prompt = "bad, deformed, ugly, bad anatomy"
image = pipeline(prompt=prompt, image=init_image, negative_prompt=negative_prompt, strength=0.7).images[0]
make_image_grid([init_image, image], rows=1, cols=2)
```
| 输入 | 输出 |
|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| | |

Xet Storage Details

Size:
1.92 kB
·
Xet hash:
9482297f8bc877c68e0f31984927465b3127750dbc837bd347d2c87922331162

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.