Diffusers 文件

DDPMScheduler

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

DDPMScheduler

去噪擴散機率模型 (Denoising Diffusion Probabilistic Models)(DDPM),由 Jonathan Ho、Ajay Jain 和 Pieter Abbeel 提出,提出了一種同名擴散模型。在 🤗 Diffusers 庫中,DDPM 指的是論文中的離散去噪排程器和管道。

論文摘要如下:

我們使用擴散機率模型呈現高質量的影像合成結果,這是一種受非平衡熱力學考慮啟發的潛在變數模型。我們透過在加權變分界上進行訓練獲得最佳結果,該變分界根據擴散機率模型與 Langevin 動力學去噪分數匹配之間的新穎連線進行設計,並且我們的模型自然地允許漸進式有損解壓縮方案,這可以解釋為自迴歸解碼的推廣。在無條件 CIFAR10 資料集上,我們獲得了 9.46 的 Inception 分數和 3.17 的最先進 FID 分數。在 256x256 LSUN 上,我們獲得了與 ProgressiveGAN 相似的樣本質量。我們的實現可在 this https URL 獲得。

DDPMScheduler

class diffusers.DDPMScheduler

< >

( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: typing.Union[numpy.ndarray, typing.List[float], NoneType] = None variance_type: str = 'fixed_small' clip_sample: bool = True prediction_type: str = 'epsilon' thresholding: bool = False dynamic_thresholding_ratio: float = 0.995 clip_sample_range: float = 1.0 sample_max_value: float = 1.0 timestep_spacing: str = 'leading' steps_offset: int = 0 rescale_betas_zero_snr: bool = False )

引數

  • num_train_timesteps (int, 預設為 1000) — 訓練模型的擴散步數。
  • beta_start (float, 預設為 0.0001) — 推理的起始 beta 值。
  • beta_end (float, 預設為 0.02) — 最終 beta 值。
  • beta_schedule (str, 預設為 "linear") — beta 排程器,將 beta 範圍對映到一系列 beta 值以進行模型步進。可選擇 linearscaled_linearsquaredcos_cap_v2sigmoid
  • trained_betas (np.ndarray, 可選) — 直接傳遞給建構函式而不使用 beta_startbeta_end 的 beta 陣列。
  • variance_type (str, 預設為 "fixed_small") — 在向去噪樣本新增噪聲時剪下方差。可選擇 fixed_smallfixed_small_logfixed_largefixed_large_loglearnedlearned_range
  • clip_sample (bool, 預設為 True) — 剪下預測樣本以實現數值穩定性。
  • clip_sample_range (float, 預設為 1.0) — 樣本剪下的最大幅度。僅當 clip_sample=True 時有效。
  • prediction_type (str, 預設為 epsilon, 可選) — 排程器功能的預測型別;可以是 epsilon(預測擴散過程的噪聲)、sample(直接預測噪聲樣本)或 v_prediction(參見 Imagen Video 論文的 2.4 節)。
  • thresholding (bool, 預設為 False) — 是否使用“動態閾值”方法。這不適用於 Stable Diffusion 等潛在空間擴散模型。
  • dynamic_thresholding_ratio (float, 預設為 0.995) — 動態閾值方法的比率。僅當 thresholding=True 時有效。
  • sample_max_value (float, 預設為 1.0) — 動態閾值的閾值。僅當 thresholding=True 時有效。
  • timestep_spacing (str, 預設為 "leading") — 時間步長的縮放方式。更多資訊請參閱 Common Diffusion Noise Schedules and Sample Steps are Flawed 的表 2。
  • steps_offset (int, 預設為 0) — 新增到推理步驟的偏移量,某些模型系列需要此偏移量。
  • rescale_betas_zero_snr (bool, 預設為 False) — 是否重新調整 beta 值以獲得零終端信噪比 (SNR)。這使得模型能夠生成非常明亮和黑暗的樣本,而不是將其限制為中等亮度的樣本。與 --offset_noise 鬆散相關。

DDPMScheduler 探討了去噪分數匹配和 Langevin 動力學取樣之間的聯絡。

該模型繼承自 SchedulerMixinConfigMixin。有關庫為所有排程器(例如載入和儲存)實現的一般方法,請檢視超類文件。

scale_model_input

< >

( sample: Tensor timestep: typing.Optional[int] = None ) torch.Tensor

引數

  • sample (torch.Tensor) — 輸入樣本。
  • timestep (int, 可選) — 擴散鏈中的當前時間步。

返回

torch.Tensor

一個縮放後的輸入樣本。

確保與需要根據當前時間步縮放去噪模型輸入的排程器互換使用。

set_timesteps

< >

( num_inference_steps: typing.Optional[int] = None device: typing.Union[str, torch.device] = None timesteps: typing.Optional[typing.List[int]] = None )

引數

  • num_inference_steps (int) — 使用預訓練模型生成樣本時使用的擴散步數。如果使用此引數,則 timesteps 必須為 None
  • device (strtorch.device, 可選) — 應將時間步移動到的裝置。如果為 None,則不移動時間步。
  • timesteps (List[int], 可選) — 用於支援時間步長之間任意間距的自定義時間步長。如果為 None,則使用預設的時間步長等間距策略。如果傳遞 timesteps,則 num_inference_steps 必須為 None

設定用於擴散鏈的離散時間步(在推理之前執行)。

步驟

< >

( model_output: Tensor timestep: int sample: Tensor generator = None return_dict: bool = True ) DDPMSchedulerOutputtuple

引數

  • model_output (torch.Tensor) — 從學習到的擴散模型直接輸出。
  • timestep (float) — 擴散鏈中的當前離散時間步。
  • sample (torch.Tensor) — 擴散過程建立的樣本當前例項。
  • generator (torch.Generator, 可選) — 隨機數生成器。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 DDPMSchedulerOutputtuple

返回

DDPMSchedulerOutputtuple

如果 `return_dict` 為 `True`,則返回 DDPMSchedulerOutput,否則返回一個元組,其中第一個元素是樣本張量。

透過逆轉 SDE 預測前一個時間步的樣本。此函式從學習到的模型輸出(通常是預測的噪聲)傳播擴散過程。

DDPMSchedulerOutput

class diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput

< >

( prev_sample: Tensor pred_original_sample: typing.Optional[torch.Tensor] = None )

引數

  • prev_sample (torch.Tensor,形狀為影像的 (batch_size, num_channels, height, width)) — 計算出的前一時間步的樣本 (x_{t-1})prev_sample 應在去噪迴圈中用作下一個模型輸入。
  • pred_original_sample (torch.Tensor,形狀為影像的 (batch_size, num_channels, height, width)) — 基於當前時間步的模型輸出預測的去噪樣本 (x_{0})pred_original_sample 可用於預覽進度或進行指導。

排程器 step 函式輸出的輸出類。

< > 在 GitHub 上更新

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