Diffusers 文件
DiT
並獲得增強的文件體驗
開始使用
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 ) → ImagePipelineOutput 或 tuple
引數
- 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.Image
或np.array
。 - return_dict (
bool
, 可選, 預設為True
) — 是否返回 ImagePipelineOutput 而不是普通元組。
返回
ImagePipelineOutput 或 tuple
如果 return_dict
為 True
,則返回 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]] ) → int
的 list
將 ImageNet 的標籤字串對映到相應的類別 ID。
ImagePipelineOutput
class diffusers.ImagePipelineOutput
< 源 >( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )
影像流水線的輸出類。