Diffusers 文件

DiT

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

DiT

使用 Transformer 的可擴充套件擴散模型 (DiT) 由 William Peebles 和 Saining Xie 開發。

論文摘要如下:

我們探索了一種基於 Transformer 架構的新型擴散模型。我們訓練影像的潛在擴散模型,將常用的 U-Net 主幹替換為在潛在補丁上執行的 Transformer。我們透過 Gflops 衡量的正向傳播複雜性來分析 Diffusion Transformers (DiTs) 的可擴充套件性。我們發現,Gflops 越高的 DiT(透過增加 Transformer 深度/寬度或增加輸入 token 數量)FID 越低。除了具有良好的可擴充套件性,我們最大的 DiT-XL/2 模型在類別條件 ImageNet 512x512 和 256x256 基準測試中超越了所有先前的擴散模型,在後者上實現了 2.27 的最先進 FID。

原始程式碼庫可在 facebookresearch/dit 找到。

請務必查閱排程器指南,瞭解如何在排程器速度和質量之間進行權衡,並檢視跨管道重用元件部分,瞭解如何有效地將相同元件載入到多個管道中。

DiTPipeline

class diffusers.DiTPipeline

< >

( transformer: DiTTransformer2DModel vae: AutoencoderKL scheduler: KarrasDiffusionSchedulers id2label: typing.Optional[typing.Dict[int, str]] = None )

引數

  • transformer (DiTTransformer2DModel) — 一個類別條件式 DiTTransformer2DModel,用於對編碼後的影像潛在特徵進行去噪。
  • vae (AutoencoderKL) — 變分自編碼器 (VAE) 模型,用於對影像進行編碼和解碼,以實現潛在表示。
  • scheduler (DDIMScheduler) — 與 transformer 結合使用的排程器,用於對編碼後的影像潛在特徵進行去噪。

基於 Transformer 主幹而不是 UNet 的影像生成管道。

此模型繼承自 DiffusionPipeline。請檢視超類文件,瞭解所有管道實現的通用方法(下載、儲存、在特定裝置上執行等)。

__call__

< >

( class_labels: typing.List[int] guidance_scale: float = 4.0 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None num_inference_steps: int = 50 output_type: typing.Optional[str] = 'pil' return_dict: bool = True ) ImagePipelineOutputtuple

引數

  • class_labels (List[int]) — 要生成的影像的 ImageNet 類別標籤列表。
  • guidance_scale (float, 可選, 預設為 4.0) — 較高的引導比例值鼓勵模型生成與文字 prompt 緊密相關的影像,但會犧牲影像質量。當 guidance_scale > 1 時啟用引導比例。
  • generator (torch.Generator, 可選) — 用於使生成具有確定性的 torch.Generator
  • num_inference_steps (int, 可選, 預設為 250) — 去噪步數。更多去噪步數通常會帶來更高質量的影像,但會犧牲較慢的推理速度。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。選擇 PIL.Imagenp.array
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ImagePipelineOutput 而不是普通元組。

返回

ImagePipelineOutputtuple

如果 return_dictTrue,則返回 ImagePipelineOutput,否則返回一個 tuple,其中第一個元素是包含生成影像的列表。

用於生成的管道的呼叫函式。

示例

>>> from diffusers import DiTPipeline, DPMSolverMultistepScheduler
>>> import torch

>>> pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", torch_dtype=torch.float16)
>>> pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
>>> pipe = pipe.to("cuda")

>>> # pick words from Imagenet class labels
>>> pipe.labels  # to print all available words

>>> # pick words that exist in ImageNet
>>> words = ["white shark", "umbrella"]

>>> class_ids = pipe.get_label_ids(words)

>>> generator = torch.manual_seed(33)
>>> output = pipe(class_labels=class_ids, num_inference_steps=25, generator=generator)

>>> image = output.images[0]  # label 'white shark'

get_label_ids

< >

( label: typing.Union[str, typing.List[str]] ) intlist

引數

  • label (strdict of str) — 要對映到類別 ID 的標籤字串。

返回

intlist

由管道處理的類別 ID。

將 ImageNet 的標籤字串對映到相應的類別 ID。

ImagePipelineOutput

class diffusers.ImagePipelineOutput

< >

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )

引數

  • images (List[PIL.Image.Image]np.ndarray) — 長度為 batch_size 的去噪 PIL 影像列表或形狀為 (batch_size, height, width, num_channels) 的 NumPy 陣列。

影像流水線的輸出類。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.