Buckets:
テキストガイドによる深度から画像への生成
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)
| 入力 | 出力 |
|---|---|
Xet Storage Details
- Size:
- 2.17 kB
- Xet hash:
- 9cf302659440f1018531bba7990e54e4388400ceb89f09834798eea1c189a78c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.