Buckets:
| # Adaptadores heredados | |
| Estos métodos siguen siendo compatibles, especialmente en los puntos de control de la familia Stable Diffusion. Para nuevo trabajo, se prefiere [LoRA](../tutorials/using_peft_for_inference), [IP-Adapter](./ip_adapter) y [ControlNet](./controlnet). | |
| ## T2I-Adapter | |
| [T2I-Adapter](https://huggingface.co/papers/2302.08453) es un adaptador para la generación controlable. Aprende un mapeo desde una señal de control (por ejemplo, un mapa de profundidad o bordes canny) hacia las características internas de un modelo preentrenado y añade esa guía durante la generación. Su rol es similar al de [ControlNet](./controlnet), pero es un adaptador más ligero que se conecta como complemento. | |
| Cargue un adaptador condicionado por control y luego cargue el pipeline con [from_pretrained()](/docs/diffusers/main/es/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained) y páselo con `adapter=`. | |
| ```py | |
| import torch | |
| from diffusers import T2IAdapter, StableDiffusionXLAdapterPipeline, AutoencoderKL | |
| t2i_adapter = T2IAdapter.from_pretrained( | |
| "TencentARC/t2i-adapter-canny-sdxl-1.0", | |
| dtype=torch.float16, | |
| ) | |
| ``` | |
| Genera una imagen canny con [opencv-python](https://github.com/opencv/opencv-python). | |
| ```py | |
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| from diffusers.utils import load_image | |
| original_image = load_image( | |
| "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/non-enhanced-prompt.png" | |
| ) | |
| image = np.array(original_image) | |
| low_threshold = 100 | |
| high_threshold = 200 | |
| image = cv2.Canny(image, low_threshold, high_threshold) | |
| image = image[:, :, None] | |
| image = np.concatenate([image, image, image], axis=2) | |
| canny_image = Image.fromarray(image) | |
| ``` | |
| Pase la imagen canny a la pipeline para generar una imagen. | |
| ```py | |
| vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16) | |
| pipeline = StableDiffusionXLAdapterPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-xl-base-1.0", | |
| adapter=t2i_adapter, | |
| vae=vae, | |
| dtype=torch.float16, | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| prompt = """ | |
| A photorealistic overhead image of a cat reclining sideways in a flamingo pool floatie holding a margarita. | |
| The cat is floating leisurely in the pool and completely relaxed and happy. | |
| """ | |
| pipeline( | |
| prompt, | |
| image=canny_image, | |
| num_inference_steps=100, | |
| guidance_scale=10, | |
| ).images[0] | |
| ``` | |
| imagen original | |
| imagen canny | |
| imagen generada | |
| Véase también [Entrenamiento de T2I-Adapter](../training/t2i_adapters). | |
| ### MultiAdapter | |
| Compone varios controles (por ejemplo, canny y depth) con `MultiAdapter`. Pasa una lista de adaptadores a `MultiAdapter` y luego pasa las imágenes de control correspondientes como una lista a la pipeline. | |
| ```py | |
| import torch | |
| from diffusers.utils import load_image | |
| from diffusers import StableDiffusionXLAdapterPipeline, AutoencoderKL, MultiAdapter, T2IAdapter | |
| canny_image = load_image( | |
| "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/canny-cat.png" | |
| ) | |
| depth_image = load_image( | |
| "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl_depth_image.png" | |
| ) | |
| controls = [canny_image, depth_image] | |
| prompt = [""" | |
| a relaxed rabbit sitting on a striped towel next to a pool with a tropical drink nearby, | |
| bright sunny day, vacation scene, 35mm photograph, film, professional, 4k, highly detailed | |
| """] | |
| adapters = MultiAdapter( | |
| [ | |
| T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", dtype=torch.float16), | |
| T2IAdapter.from_pretrained("TencentARC/t2i-adapter-depth-midas-sdxl-1.0", dtype=torch.float16), | |
| ] | |
| ) | |
| ``` | |
| Pasa los adaptadores, el prompt y las imágenes de control a [StableDiffusionXLAdapterPipeline](/docs/diffusers/main/es/api/pipelines/stable_diffusion/adapter#diffusers.StableDiffusionXLAdapterPipeline). Usa el parámetro `adapter_conditioning_scale` para determinar cuánto peso asignar a cada control. | |
| ```py | |
| vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16) | |
| pipeline = StableDiffusionXLAdapterPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-xl-base-1.0", | |
| dtype=torch.float16, | |
| vae=vae, | |
| adapter=adapters, | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| pipeline( | |
| prompt, | |
| image=controls, | |
| height=1024, | |
| width=1024, | |
| adapter_conditioning_scale=[0.7, 0.7] | |
| ).images[0] | |
| ``` | |
| imagen canny | |
| mapa de profundidad | |
| imagen generada | |
| ## Inversión textual | |
| [Textual Inversion](https://huggingface.co/papers/2208.01618) personaliza un modelo para un concepto a partir de 3-5 imágenes mediante el ajuste fino de los embeddings de palabras vinculados a un token único (`<sks>`). Luego, puedes usar ese token en tu prompt para generar el concepto (por ejemplo, pixel art). | |
| Los pesos de Textual Inversion suelen ser de solo unos pocos KB porque son únicamente embeddings de palabras. Cargalos después de [from_pretrained()](/docs/diffusers/main/es/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained) con [load_textual_inversion()](/docs/diffusers/main/es/api/loaders/textual_inversion#diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion) e incluye el token único en el prompt para activar la generación. | |
| ```py | |
| import torch | |
| from diffusers import AutoPipelineForText2Image | |
| pipeline = AutoPipelineForText2Image.from_pretrained( | |
| "stable-diffusion-v1-5/stable-diffusion-v1-5", | |
| dtype=torch.float16 | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| ``` | |
| ```py | |
| pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork") | |
| prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration, <gta5-artwork> style" | |
| pipeline(prompt).images[0] | |
| ``` | |
| Para entrenar embeddings, consulte [Entrenar textual inversion](../training/text_inversion). | |
| Textual Inversion también se puede entrenar para aprender *embeddings negativos* y orientar la generación alejándola de características no deseadas, como "borroso" o "feo", lo que resulta útil para mejorar la calidad de la imagen. | |
| EasyNegative es un embedding negativo ampliamente utilizado que contiene múltiples conceptos negativos aprendidos. Carga los embeddings negativos y especifica el nombre del archivo y el token asociados con los embeddings negativos. Pasa el token a `negative_prompt` en tu pipeline para activarlo. | |
| ```py | |
| import torch | |
| from diffusers import AutoPipelineForText2Image | |
| pipeline = AutoPipelineForText2Image.from_pretrained( | |
| "stable-diffusion-v1-5/stable-diffusion-v1-5", | |
| dtype=torch.float16 | |
| ).to("cuda") # or "mps", "xpu", "cpu" | |
| pipeline.load_textual_inversion( | |
| "EvilEngine/easynegative", | |
| weight_name="easynegative.safetensors", | |
| token="easynegative" | |
| ) | |
| prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration" | |
| negative_prompt = "easynegative" | |
| pipeline(prompt, negative_prompt=negative_prompt).images[0] | |
| ``` | |
Xet Storage Details
- Size:
- 7.07 kB
- Xet hash:
- 0bef85c4fcdd09fd4c81e8ba2bedc6ed0ed1ced86e46ea0d3a6d3ad6ee848810
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.