Diffusers 文件

文字引導的深度圖到影像生成

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

文字引導的深度圖到影像生成

StableDiffusionDepth2ImgPipeline 允許您透過文字提示和初始影像來條件生成新影像。此外,您還可以傳遞一個 depth_map 來保留影像結構。如果沒有提供 depth_map,管道將透過整合的深度估計模型自動預測深度。

首先建立一個 StableDiffusionDepth2ImgPipeline 例項。

import torch
from diffusers import StableDiffusionDepth2ImgPipeline
from diffusers.utils import load_image, make_image_grid

pipeline = StableDiffusionDepth2ImgPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-depth",
    torch_dtype=torch.float16,
    use_safetensors=True,
).to("cuda")

現在將您的提示傳遞給管道。您還可以傳遞一個 negative_prompt 以防止某些詞語引導影像的生成。

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)
輸入 輸出
< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.