Diffusers documentation

テキストガイドによる深度から画像への生成

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

テキストガイドによる深度から画像への生成

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",
    dtype=torch.float16,
    use_safetensors=True,
).to("cuda")  # or "mps", "xpu", "cpu"

次に、プロンプトをパイプラインに渡します。画像の生成方法に影響を与える特定の単語を防止するために、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)
入力出力
Update on GitHub