Diffusers 文件

unCLIP

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

unCLIP

《使用 CLIP 潛在變數進行分層文字條件影像生成》由 Aditya Ramesh、Prafulla Dhariwal、Alex Nichol、Casey Chu 和 Mark Chen 撰寫。🤗 Diffusers 中的 unCLIP 模型來源於 kakaobrain 的 karlo

論文摘要如下:

像 CLIP 這樣的對比模型已被證明能夠學習影像的穩健表示,這些表示能夠同時捕獲語義和風格。為了利用這些表示進行影像生成,我們提出了一個兩階段模型:一個先驗模型,根據文字標題生成 CLIP 影像嵌入;一個解碼器,根據影像嵌入生成影像。我們發現,明確生成影像表示可以提高影像多樣性,同時最大限度地減少真實感和標題相似性的損失。我們的基於影像表示的解碼器還可以生成影像的變體,這些變體保留了其語義和風格,同時改變了影像表示中不存在的非必要細節。此外,CLIP 的聯合嵌入空間能夠以零樣本方式進行語言引導的影像操作。我們使用擴散模型作為解碼器,並對先驗模型進行自迴歸和擴散模型的實驗,發現後者在計算上更高效,並能生成更高質量的樣本。

您可以在 lucidrains/DALLE2-pytorch 找到 lucidrains 的 DALL-E 2 復刻版。

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

UnCLIPPipeline

class diffusers.UnCLIPPipeline

< >

( prior: PriorTransformer decoder: UNet2DConditionModel text_encoder: CLIPTextModelWithProjection tokenizer: CLIPTokenizer text_proj: UnCLIPTextProjModel super_res_first: UNet2DModel super_res_last: UNet2DModel prior_scheduler: UnCLIPScheduler decoder_scheduler: UnCLIPScheduler super_res_scheduler: UnCLIPScheduler )

引數

  • text_encoder (CLIPTextModelWithProjection) — 凍結的文字編碼器。
  • tokenizer (CLIPTokenizer) — 用於標記文字的 CLIPTokenizer
  • prior (PriorTransformer) — 規範的 unCLIP 先驗,用於從文字嵌入中近似影像嵌入。
  • text_proj (UnCLIPTextProjModel) — 用於準備和組合嵌入的實用類,然後將其傳遞給解碼器。
  • decoder (UNet2DConditionModel) — 用於將影像嵌入反轉為影像的解碼器。
  • super_res_first (UNet2DModel) — 超解析度 UNet。用於超解析度擴散過程的所有步驟,除了最後一步。
  • super_res_last (UNet2DModel) — 超解析度 UNet。用於超解析度擴散過程的最後一步。
  • prior_scheduler (UnCLIPScheduler) — 用於先驗去噪過程的排程器(一個修改過的 DDPMScheduler)。
  • decoder_scheduler (UnCLIPScheduler) — 用於解碼器去噪過程的排程器(一個修改過的 DDPMScheduler)。
  • super_res_scheduler (UnCLIPScheduler) — 用於超解析度去噪過程的排程器(一個修改過的 DDPMScheduler)。

用於文字到影像生成的 unCLIP 管道。

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

__call__

< >

( prompt: typing.Union[str, typing.List[str], NoneType] = None num_images_per_prompt: int = 1 prior_num_inference_steps: int = 25 decoder_num_inference_steps: int = 25 super_res_num_inference_steps: int = 7 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None prior_latents: typing.Optional[torch.Tensor] = None decoder_latents: typing.Optional[torch.Tensor] = None super_res_latents: typing.Optional[torch.Tensor] = None text_model_output: typing.Union[transformers.models.clip.modeling_clip.CLIPTextModelOutput, typing.Tuple, NoneType] = None text_attention_mask: typing.Optional[torch.Tensor] = None prior_guidance_scale: float = 4.0 decoder_guidance_scale: float = 8.0 output_type: typing.Optional[str] = 'pil' return_dict: bool = True ) ImagePipelineOutputtuple

引數

  • prompt (strList[str]) — 用於引導影像生成的提示或提示列表。僅當傳遞 text_model_outputtext_attention_mask 時,才可以不定義此引數。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示生成的影像數量。
  • prior_num_inference_steps (int, 可選, 預設為 25) — 先驗去噪的步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • decoder_num_inference_steps (int, 可選, 預設為 25) — 解碼器去噪的步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • super_res_num_inference_steps (int, 可選, 預設為 7) — 超解析度去噪的步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 用於使生成具有確定性的 torch.Generator
  • prior_latents (形狀為 (批大小,嵌入維度) 的 torch.Tensor, 可選) — 用於先驗輸入的預生成噪聲潛在變數。
  • decoder_latents (形狀為 (批大小,通道,高度,寬度) 的 torch.Tensor, 可選) — 用於解碼器輸入的預生成噪聲潛在變數。
  • super_res_latents (形狀為 (批大小,通道,超解析度高度,超解析度寬度) 的 torch.Tensor, 可選) — 用於解碼器輸入的預生成噪聲潛在變數。
  • prior_guidance_scale (float, 可選, 預設為 4.0) — 較高的引導比例值會促使模型生成與文字 prompt 緊密相關的影像,但會降低影像質量。當 guidance_scale > 1 時,啟用引導比例。
  • decoder_guidance_scale (float, 可選, 預設為 4.0) — 較高的引導比例值會促使模型生成與文字 prompt 緊密相關的影像,但會降低影像質量。當 guidance_scale > 1 時,啟用引導比例。
  • text_model_output (CLIPTextModelOutput, 可選) — 可從文字編碼器派生的預定義 CLIPTextModel 輸出。預定義的文字輸出可用於文字嵌入插值等任務。在這種情況下,請確保也傳遞 text_attention_maskprompt 此時可以保留為 None
  • text_attention_mask (torch.Tensor, 可選) — 可從分詞器派生的預定義 CLIP 文字注意力掩碼。在傳遞 text_model_output 時,文字注意力掩碼是必需的。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。在 PIL.Imagenp.array 之間選擇。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ImagePipelineOutput 而不是普通元組。

返回

ImagePipelineOutputtuple

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

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

UnCLIPImageVariationPipeline

class diffusers.UnCLIPImageVariationPipeline

< >

( 解碼器: UNet2DConditionModel 文字編碼器: CLIPTextModelWithProjection 分詞器: CLIPTokenizer 文字投影: UnCLIPTextProjModel 特徵提取器: CLIPImageProcessor 影像編碼器: CLIPVisionModelWithProjection 第一個超解析度: UNet2DModel 最後一個超解析度: UNet2DModel 解碼器排程器: UnCLIPScheduler 超解析度排程器: UnCLIPScheduler )

引數

  • text_encoder (CLIPTextModelWithProjection) — 凍結的文字編碼器。
  • tokenizer (CLIPTokenizer) — 用於對文字進行分詞的 CLIPTokenizer
  • feature_extractor (CLIPImageProcessor) — 從生成的影像中提取特徵的模型,用作 image_encoder 的輸入。
  • image_encoder (CLIPVisionModelWithProjection) — 凍結的 CLIP 影像編碼器 (clip-vit-large-patch14)。
  • text_proj (UnCLIPTextProjModel) — 用於準備和組合嵌入的實用程式類,然後將其傳遞給解碼器。
  • decoder (UNet2DConditionModel) — 用於將影像嵌入反轉為影像的解碼器。
  • super_res_first (UNet2DModel) — 超解析度 UNet。用於超解析度擴散過程的所有步驟,除了最後一步。
  • super_res_last (UNet2DModel) — 超解析度 UNet。用於超解析度擴散過程的最後一步。
  • decoder_scheduler (UnCLIPScheduler) — 解碼器去噪過程中使用的排程器(修改後的 DDPMScheduler)。
  • super_res_scheduler (UnCLIPScheduler) — 超解析度去噪過程中使用的排程器(修改後的 DDPMScheduler)。

使用 UnCLIP 從輸入影像生成影像變體。

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

__call__

< >

( 影像: typing.Union[PIL.Image.Image, typing.List[PIL.Image.Image], torch.Tensor, NoneType] = None 每個提示的影像數量: int = 1 解碼器推理步數: int = 25 超解析度推理步數: int = 7 生成器: typing.Optional[torch._C.Generator] = None 解碼器潛在表示: typing.Optional[torch.Tensor] = None 超解析度潛在表示: typing.Optional[torch.Tensor] = None 影像嵌入: typing.Optional[torch.Tensor] = None 解碼器引導比例: float = 8.0 輸出型別: typing.Optional[str] = 'pil' 返回字典: bool = True ) ImagePipelineOutputtuple

引數

  • image (PIL.Image.ImageList[PIL.Image.Image]torch.Tensor) — 用作起點的影像或表示影像批次的張量。如果提供張量,它需要與 CLIPImageProcessor 配置相容。只有在傳遞 image_embeddings 時才能將其保留為 None
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示生成的影像數量。
  • decoder_num_inference_steps (int, 可選, 預設為 25) — 解碼器的去噪步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • super_res_num_inference_steps (int, 可選, 預設為 7) — 超解析度的去噪步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • generator (torch.Generator, 可選) — torch.Generator 用於使生成具有確定性。
  • decoder_latents (形狀為 (批次大小,通道數,高度,寬度) 的 torch.Tensor, 可選) — 預生成的噪聲潛在表示,用作解碼器的輸入。
  • super_res_latents (形狀為 (批次大小,通道數,超解析度高度,超解析度寬度) 的 torch.Tensor, 可選) — 預生成的噪聲潛在表示,用作解碼器的輸入。
  • decoder_guidance_scale (float, 可選, 預設為 4.0) — 較高的引導比例值會鼓勵模型生成與文字 prompt 緊密相關的影像,但影像質量會降低。當 guidance_scale > 1 時,啟用引導比例。
  • image_embeddings (torch.Tensor, 可選) — 可從影像編碼器派生的預定義影像嵌入。預定義影像嵌入可用於影像插值等任務。image 可以保留為 None
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。選擇 PIL.Imagenp.array
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ImagePipelineOutput 而不是普通的元組。

返回

ImagePipelineOutputtuple

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

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

ImagePipelineOutput

class diffusers.ImagePipelineOutput

< >

( 影像: 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.