Diffusers 文件
AutoPipeline
加入 Hugging Face 社群
並獲得增強的文件體驗
開始使用
AutoPipeline
Diffusers 提供了許多用於基本任務的管道,例如生成影像、影片、音訊和影像修復。除此之外,還有用於介面卡和諸如放大、超解析度等功能的專用管道。不同的管道類甚至可以使用相同的檢查點,因為它們共享相同的預訓練模型!管道種類繁多,可能會讓人不知所措,不知道該使用哪個管道類。
AutoPipeline 類旨在簡化 Diffusers 中各種管道的使用。它是一個通用的*任務優先*管道,讓您可以專注於任務(AutoPipelineForText2Image、AutoPipelineForImage2Image 和 AutoPipelineForInpainting),而無需瞭解具體的管道類。AutoPipeline 會自動檢測要使用的正確管道類。
例如,讓我們使用 dreamlike-art/dreamlike-photoreal-2.0 檢查點。
在底層,AutoPipeline 會:
- 從 model_index.json 檔案中檢測到一個
"stable-diffusion"
類。 - 根據您感興趣的任務,它會載入 StableDiffusionPipeline、StableDiffusionImg2ImgPipeline 或 StableDiffusionInpaintPipeline。您可以傳遞給這些特定管道的任何引數(
strength
、num_inference_steps
等)也可以傳遞給 AutoPipeline。
文字到影像
影像到影像
影像修復
from diffusers import AutoPipelineForText2Image
import torch
pipe_txt2img = AutoPipelineForText2Image.from_pretrained(
"dreamlike-art/dreamlike-photoreal-2.0", torch_dtype=torch.float16, use_safetensors=True
).to("cuda")
prompt = "cinematic photo of Godzilla eating sushi with a cat in a izakaya, 35mm photograph, film, professional, 4k, highly detailed"
generator = torch.Generator(device="cpu").manual_seed(37)
image = pipe_txt2img(prompt, generator=generator).images[0]
image

不支援的檢查點
AutoPipeline 支援 Stable Diffusion、Stable Diffusion XL、ControlNet、Kandinsky 2.1、Kandinsky 2.2 和 DeepFloyd IF 檢查點。
如果您嘗試載入不支援的檢查點,將會收到錯誤。
from diffusers import AutoPipelineForImage2Image
import torch
pipeline = AutoPipelineForImage2Image.from_pretrained(
"openai/shap-e-img2img", torch_dtype=torch.float16, use_safetensors=True
)
"ValueError: AutoPipeline can't find a pipeline linked to ShapEImg2ImgPipeline for None"