Diffusers documentation

Generación de imágenes a partir de profundidad guiada por texto

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

Generación de imágenes a partir de profundidad guiada por texto

El StableDiffusionDepth2ImgPipeline permite pasar un prompt de texto y una imagen inicial para condicionar la generación de nuevas imágenes. Además, también puedes pasar un depth_map para preservar la estructura de la imagen. Si no se proporciona un depth_map, el pipeline predice automáticamente la profundidad mediante un modelo de estimación de profundidad integrado.

Comience creando una instancia de 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"

Ahora pasa tu prompt a la pipeline. También puedes pasar un negative_prompt para evitar que ciertas palabras guíen cómo se genera una imagen:

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)
EntradaSalida
Update on GitHub