Diffusers documentation
テキストガイドによる深度から画像への生成
はじめに
推論
拡散パイプラインの使用
アダプターとパーソナライズ
最適化とスケーリング
モジュール型 Diffusers
学習とファインチューニング
リソース
コントリビュート
API
テキストガイドによる深度から画像への生成
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)| 入力 | 出力 |
|---|---|
![]() | ![]() |

