Diffusers 文件
unCLIP
並獲得增強的文件體驗
開始使用
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 ) → ImagePipelineOutput 或 tuple
引數
- prompt (
str
或List[str]
) — 用於引導影像生成的提示或提示列表。僅當傳遞text_model_output
和text_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.Generator
或List[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_mask
。prompt
此時可以保留為None
。 - text_attention_mask (
torch.Tensor
, 可選) — 可從分詞器派生的預定義 CLIP 文字注意力掩碼。在傳遞text_model_output
時,文字注意力掩碼是必需的。 - output_type (
str
, 可選, 預設為"pil"
) — 生成影像的輸出格式。在PIL.Image
或np.array
之間選擇。 - return_dict (
bool
, 可選, 預設為True
) — 是否返回 ImagePipelineOutput 而不是普通元組。
返回
ImagePipelineOutput 或 tuple
如果 return_dict
為 True
,則返回 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 ) → ImagePipelineOutput 或 tuple
引數
- image (
PIL.Image.Image
或List[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.Image
或np.array
。 - return_dict (
bool
, 可選, 預設為True
) — 是否返回 ImagePipelineOutput 而不是普通的元組。
返回
ImagePipelineOutput 或 tuple
如果 return_dict
為 True
,則返回 ImagePipelineOutput,否則返回一個 tuple
,其中第一個元素是生成的影像列表。
用於生成的管道的呼叫函式。
ImagePipelineOutput
class diffusers.ImagePipelineOutput
< 來源 >( 影像: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )
影像流水線的輸出類。