Buckets:

mishig's picture
|
download
raw
2.17 kB
# テキストガイドによる深度から画像への生成
[StableDiffusionDepth2ImgPipeline](/docs/diffusers/v0.43.0/ja/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline) を使用すると、テキストプロンプトと初期画像を渡すことで、新しい画像の生成を条件付けできます。さらに、`depth_map` を渡すことで、画像の構造を保持することも可能です。`depth_map` が指定されない場合、パイプラインは統合された[深度推定モデル](https://github.com/isl-org/MiDaS)によって深度を自動的に推定します。
[StableDiffusionDepth2ImgPipeline](/docs/diffusers/v0.43.0/ja/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"
```
次に、プロンプトをパイプラインに渡します。画像の生成方法に影響を与える特定の単語を防止するために、`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:
2.17 kB
·
Xet hash:
9cf302659440f1018531bba7990e54e4388400ceb89f09834798eea1c189a78c

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