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이 제공되지 않으면 파이프라인은 통합된 depth-estimation model을 통해 깊이를 자동으로 예측합니다.

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"

이제 프롬프트를 pipeline에 전달합니다. 특정 단어가 이미지 생성 방식을 유도하는 것을 방지하려면 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