Diffusers documentation

Génération d'images à partir de profondeur guidée par le texte

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

Génération d'images à partir de profondeur guidée par le texte

Le StableDiffusionDepth2ImgPipeline vous permet de transmettre un prompt texte et une image initiale pour conditionner la génération de nouvelles images. En outre, vous pouvez également passer une depth_map pour préserver la structure de l'image. Si aucune depth_map n'est fournie, le pipeline prédit automatiquement la profondeur via un modèle d'estimation de la profondeur intégré.

Commencez par créer une instance 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"

Passez maintenant votre invite au pipeline. Vous pouvez également passer un negative_prompt pour empêcher certains mots de guider la génération d'une image :

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)
EntréeSortie
Update on GitHub