Diffusers documentation

Wan

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

LoRA

Wan

Wan Team 的 Wan-2.1。

本报告介绍了 Wan,这是一套全面且开源的视频基础模型系列,旨在推动视频生成的边界。Wan 基于主流的扩散 Transformer 范式,通过一系列创新实现了生成能力的显著提升,包括我们新颖的 VAE、可扩展的预训练策略、大规模数据筛选以及自动化评估指标。这些贡献共同提升了模型的性能和通用性。具体而言,Wan 具有以下四个关键特性:领先性能:Wan 的 14B 模型在包含数十亿图像和视频的庞大数据集上训练,展示了视频生成在数据规模和模型规模方面的扩展定律。它在多个内部和外部基准测试中持续超越现有的开源模型以及最先进的商业解决方案,展现出明确且显著的性能优势。全面性:Wan 提供了两个强大的模型,即 1.3B 和 14B 参数,分别侧重于效率和效果。它还涵盖了多种下游应用,包括图生视频、指令引导的视频编辑以及个性化视频生成,最多涵盖八项任务。消费级效率:1.3B 模型展现出卓越的资源效率,仅需 8.19 GB 显存,使其兼容广泛的消费级 GPU。开放性:我们开源了 Wan 的整个系列,包括源代码和所有模型,旨在促进视频生成社区的发展。这种开放性旨在显著扩展行业中视频制作的创意可能性,并为学术界提供高质量的视频基础模型。所有代码和模型均可在 this https URL 获取。

您可以在 Wan-AI 组织下找到所有原始的 Wan2.1 检查点。

Diffusers 支持以下 Wan 模型:

点击右侧边栏中的 Wan 模型,以查看更多视频生成示例。

文本到视频生成

下面的示例演示了如何生成针对内存或推理速度进行优化的文本到视频。

T2V 内存
T2V 推理速度

有关各种内存节省技术的详细信息,请参阅 减少内存使用 指南。

下方的 Wan2.1 文本生成视频模型需要约 13GB 的显存。

# pip install ftfy
import torch
import numpy as np
from diffusers import AutoModel, WanPipeline
from diffusers.quantizers import PipelineQuantizationConfig
from diffusers.hooks.group_offloading import apply_group_offloading
from diffusers.utils import export_to_video, load_image
from transformers import UMT5EncoderModel

text_encoder = UMT5EncoderModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="text_encoder", dtype=torch.bfloat16)
vae = AutoModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="vae", dtype=torch.float32)
transformer = AutoModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="transformer", dtype=torch.bfloat16)

# group-offloading
onload_device = torch.device("cuda")
offload_device = torch.device("cpu")
apply_group_offloading(text_encoder,
    onload_device=onload_device,
    offload_device=offload_device,
    offload_type="block_level",
    num_blocks_per_group=4
)
transformer.enable_group_offload(
    onload_device=onload_device,
    offload_device=offload_device,
    offload_type="leaf_level",
    use_stream=True
)

pipeline = WanPipeline.from_pretrained(
    "Wan-AI/Wan2.1-T2V-14B-Diffusers",
    vae=vae,
    transformer=transformer,
    text_encoder=text_encoder,
    dtype=torch.bfloat16
)
pipeline.to("cuda")  # or "mps", "xpu", "cpu"

prompt = """
The camera rushes from far to near in a low-angle shot,
revealing a white ferret on a log. It plays, leaps into the water, and emerges, as the camera zooms in
for a close-up. Water splashes berry bushes nearby, while moss, snow, and leaves blanket the ground.
Birch trees and a light blue sky frame the scene, with ferns in the foreground. Side lighting casts dynamic
shadows and warm highlights. Medium composition, front view, low angle, with depth of field.
"""
negative_prompt = """
Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality,
low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured,
misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards
"""

output = pipeline(
    prompt=prompt,
    negative_prompt=negative_prompt,
    num_frames=81,
    guidance_scale=5.0,
).frames[0]
export_to_video(output, "output.mp4", fps=16)

首尾帧到视频生成

下面的示例演示了如何使用图像到视频流水线,根据文本描述、起始帧和结束帧生成视频。

用法
import numpy as np
import torch
import torchvision.transforms.functional as TF
from diffusers import AutoencoderKLWan, WanImageToVideoPipeline
from diffusers.utils import export_to_video, load_image
from transformers import CLIPVisionModel


model_id = "Wan-AI/Wan2.1-FLF2V-14B-720P-diffusers"
image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", dtype=torch.float32)
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32)
pipe = WanImageToVideoPipeline.from_pretrained(
    model_id, vae=vae, image_encoder=image_encoder, dtype=torch.bfloat16
)
pipe.to("cuda")  # or "mps", "xpu", "cpu"

first_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png")
last_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png")

def aspect_ratio_resize(image, pipe, max_area=720 * 1280):
    aspect_ratio = image.height / image.width
    mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1]
    height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
    width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
    image = image.resize((width, height))
    return image, height, width

def center_crop_resize(image, height, width):
    # Calculate resize ratio to match first frame dimensions
    resize_ratio = max(width / image.width, height / image.height)

    # Resize the image
    width = round(image.width * resize_ratio)
    height = round(image.height * resize_ratio)
    size = [width, height]
    image = TF.center_crop(image, size)

    return image, height, width

first_frame, height, width = aspect_ratio_resize(first_frame, pipe)
if last_frame.size != first_frame.size:
    last_frame, _, _ = center_crop_resize(last_frame, height, width)

prompt = "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective."

output = pipe(
    image=first_frame, last_image=last_frame, prompt=prompt, height=height, width=width, guidance_scale=5.5
).frames[0]
export_to_video(output, "output.mp4", fps=16)

任意到视频的可控生成

Wan VACE 支持多种生成技术,可实现可控的视频生成。部分功能包括:

  • 控制到视频(深度、姿态、草图、光流、灰度、涂鸦、布局、边界框等)。推荐用于预处理视频以获取控制视频的库:huggingface/controlnet_aux
  • 图像/视频到视频(首帧、尾帧、起始片段、结束片段、随机片段)
  • 图像修复与外扩绘制
  • 受视频约束(人脸、物体、角色等)
  • 组合到视频(参考任意内容、动画化任意内容、替换任意内容、扩展任意内容、移动任意内容等)

此拉取请求中可用的代码片段展示了如何使用可控性信号生成视频的一些示例。

在为 VACE 流水线准备输入时,需要牢记的一般原则是:用于条件控制的输入图像或视频帧,应配有一个黑色的掩码。黑色掩码表示模型不会在该区域生成新内容,而仅将这些部分用于条件控制生成过程。对于应由模型生成的部分/帧,掩码应为白色。

Wan-Animate:通过整体复制实现统一的角色动画与替换

Wan 团队的 Wan-Animate。

我们推出了 Wan-Animate,一个用于角色动画生成与角色替换的统一框架。给定一张角色图像和一段参考视频,Wan-Animate 可以通过精确复刻视频中角色的表情和动作来驱动该角色,从而生成高保真的角色视频。或者,它可以将动画角色融入参考视频中以替换原始角色,通过复刻场景的光照和色调来实现无缝的环境融合。Wan-Animate 基于 Wan 模型构建。为了使其适应角色动画任务,我们采用了一种改进的输入范式,以区分参考条件和生成区域。这一设计将多种任务统一为一种通用的符号表示。我们使用空间对齐的骨骼信号来复刻身体运动,并使用从源图像中提取的隐式面部特征来重现表情,从而生成具有高可控性和表现力的角色视频。此外,为了增强角色替换过程中的环境融合效果,我们开发了一个辅助的 Relighting LoRA 模块。该模块在保持角色外观一致性的同时,应用适当的环境光照和色调。实验结果表明,Wan-Animate 达到了最先进的性能。我们致力于开源该模型的权重及其源代码。

项目页面:https://humanaigc.github.io/wan-animate

该模型主要由 M. Tolga Cangöz 贡献。

用法

Wan-Animate 流水线支持两种运行模式:

  1. 动画模式(默认):根据参考视频中的动作和表情,对角色图像进行动画处理
  2. 替换模式:在保留场景的同时,将背景视频中的角色替换为新角色
先决条件

在使用 pipeline 之前,您需要对参考视频进行预处理,以提取:

  • 姿态视频:包含表示身体运动的骨骼关键点
  • 面部视频:包含用于表情控制的面部特征表示

对于替换模式,您还需要:

  • 背景视频:包含该场景的原始视频
  • 遮罩视频:一个遮罩,指示在哪里生成内容(白色)与保留原始内容(黑色)

原始视频不应直接用作诸如 pose_video 之类的输入,因为该流水线期望输入已预先处理以提取所需信息。用于准备这些输入的预处理脚本可在 原始 Wan-Animate 仓库 中找到。将这些预处理步骤集成到 Diffusers 中的工作已计划在后续版本中实现。

以下示例演示了如何使用 Wan-Animate 流水线:

动画模式
替换模式
高级选项
import numpy as np
import torch
from diffusers import AutoencoderKLWan, WanAnimatePipeline
from diffusers.utils import export_to_video, load_image, load_video

model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers"
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32)
pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, dtype=torch.bfloat16)
pipe.to("cuda")  # or "mps", "xpu", "cpu"

# Load character image and preprocessed videos
image = load_image("path/to/character.jpg")
pose_video = load_video("path/to/pose_video.mp4")  # Preprocessed skeletal keypoints
face_video = load_video("path/to/face_video.mp4")  # Preprocessed facial features

# Resize image to match VAE constraints
def aspect_ratio_resize(image, pipe, max_area=720 * 1280):
    aspect_ratio = image.height / image.width
    mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1]
    height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
    width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
    image = image.resize((width, height))
    return image, height, width

image, height, width = aspect_ratio_resize(image, pipe)

prompt = "A person dancing energetically in a studio with dynamic lighting and professional camera work"
negative_prompt = "blurry, low quality, distorted, deformed, static, poorly drawn"

# Generate animated video
output = pipe(
    image=image,
    pose_video=pose_video,
    face_video=face_video,
    prompt=prompt,
    negative_prompt=negative_prompt,
    height=height,
    width=width,
    segment_frame_length=77,
    guidance_scale=1.0,
    mode="animate",  # Animation mode (default)
).frames[0]
export_to_video(output, "animated_character.mp4", fps=30)

关键参数

  • mode:在 "animate"(默认)或 "replace" 之间进行选择
  • prev_segment_conditioning_frames:用于时间引导的帧数(推荐值为 1 或 5)。使用 5 可提供更好的时间一致性,但需要更多内存
  • guidance_scale:控制输出结果对文本提示词的遵循程度。较高的值(5-7)会使生成结果更贴合提示词。对于 Wan-Animate,默认情况下 CFG 处于禁用状态(guidance_scale=1.0),但您可以启用它以支持负面提示词,并对面部表情进行更精细的控制。(请注意,CFG 仅针对文本提示词和面部条件。)

备注

  • Wan2.1 支持通过 load_lora_weights() 加载 LoRA。

    查看示例代码
    # pip install ftfy
    import torch
    from diffusers import AutoModel, WanPipeline
    from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
    from diffusers.utils import export_to_video
    
    vae = AutoModel.from_pretrained(
        "Wan-AI/Wan2.1-T2V-1.3B-Diffusers", subfolder="vae", dtype=torch.float32
    )
    pipeline = WanPipeline.from_pretrained(
        "Wan-AI/Wan2.1-T2V-1.3B-Diffusers", vae=vae, dtype=torch.bfloat16
    )
    pipeline.scheduler = UniPCMultistepScheduler.from_config(
        pipeline.scheduler.config, flow_shift=5.0
    )
    pipeline.to("cuda")  # or "mps", "xpu", "cpu"
    
    pipeline.load_lora_weights("benjamin-paine/steamboat-willie-1.3b", adapter_name="steamboat-willie")
    pipeline.set_adapters("steamboat-willie")
    
    pipeline.enable_model_cpu_offload()
    
    # use "steamboat willie style" to trigger the LoRA
    prompt = """
    steamboat willie style, golden era animation, The camera rushes from far to near in a low-angle shot,
    revealing a white ferret on a log. It plays, leaps into the water, and emerges, as the camera zooms in
    for a close-up. Water splashes berry bushes nearby, while moss, snow, and leaves blanket the ground.
    Birch trees and a light blue sky frame the scene, with ferns in the foreground. Side lighting casts dynamic
    shadows and warm highlights. Medium composition, front view, low angle, with depth of field.
    """
    
    output = pipeline(
        prompt=prompt,
        num_frames=81,
        guidance_scale=5.0,
    ).frames[0]
    export_to_video(output, "output.mp4", fps=16)
  • WanTransformer3DModel and AutoencoderKLWan supports loading from single files with from_single_file().

    显示示例代码
    # pip install ftfy
    import torch
    from diffusers import WanPipeline, WanTransformer3DModel, AutoencoderKLWan
    
    vae = AutoencoderKLWan.from_single_file(
        "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/blob/main/split_files/vae/wan_2.1_vae.safetensors"
    )
    transformer = WanTransformer3DModel.from_single_file(
        "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/blob/main/split_files/diffusion_models/wan2.1_t2v_1.3B_bf16.safetensors",
        dtype=torch.bfloat16
    )
    pipeline = WanPipeline.from_pretrained(
        "Wan-AI/Wan2.1-T2V-1.3B-Diffusers",
        vae=vae,
        transformer=transformer,
        dtype=torch.bfloat16
    )
  • 将 AutoencoderKLWan 的 dtype 设置为 torch.float32,以获得更好的解码质量。

  • 每秒帧数 (fps) 或 k 应通过 4 * k + 1 进行计算。

  • 对于低分辨率视频,尝试使用较低的 shift 值(2.0 到 5.0);对于高分辨率图像,则使用较高的 shift 值(7.0 到 12.0)。

  • Wan 2.1 和 2.2 支持使用 LightX2V LoRAs 来加速推理。在 Wan 2.2 上使用它们的操作会稍微复杂一些。请参阅 此代码片段 以了解更多信息。

  • Wan 2.2 包含两个去噪器。默认情况下,LoRA 仅加载到第一个去噪器中。可以设置 load_into_transformer_2=True 将 LoRA 加载到第二个去噪器中。请参阅 此 和 此 示例以了解更多信息。

WanPipeline

类 diffusers.WanPipeline

< >

( tokenizer: AutoTokenizertext_encoder: UMT5EncoderModelvae: AutoencoderKLWanscheduler: FlowMatchEulerDiscreteSchedulertransformer: diffusers.models.transformers.transformer_wan.WanTransformer3DModel | None = Nonetransformer_2: diffusers.models.transformers.transformer_wan.WanTransformer3DModel | None = Noneboundary_ratio: float | None = Noneexpand_timesteps: bool = False )

参数

  • tokenizer (T5Tokenizer) — 来自 T5 的分词器, 具体为 google/umt5-xxl 变体。
  • text_encoder(T5EncoderModel)—— T5,具体为 google/umt5-xxl 变体。
  • transformer (WanTransformer3DModel) — 用于对输入潜变量进行去噪的条件 Transformer。
  • scheduler (UniPCMultistepScheduler) — 用于与 transformer 配合,对编码后的图像潜变量进行去噪的调度器。
  • vae (AutoencoderKLWan) — 变分自编码器(VAE)模型,用于将视频编码为潜在表示,以及从潜在表示解码为视频。
  • transformer_2 (WanTransformer3DModel,可选) — 用于在低噪声阶段对输入潜变量进行去噪的条件 Transformer。如果提供该参数,则启用两阶段去噪,其中 transformer 负责高噪声阶段,transformer_2 负责低噪声阶段。如果未提供,则仅使用 transformer。
  • boundary_ratio (float, 可选,默认为 None) — 用于两阶段去噪中切换 transformer 的边界,表示占总时间步的比例。 实际的边界时间步计算为 boundary_ratio * num_train_timesteps。当提供该参数时, transformer 处理时间步 >= boundary_timestep 的部分,transformer_2 处理时间步 < boundary_timestep 的部分。如果为 None,则整个去噪过程仅使用 transformer。

使用 Wan 进行文本到视频生成的 Pipeline。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Noneheight: int = 480width: int = 832num_frames: int = 81num_inference_steps: int = 50guidance_scale: float = 5.0guidance_scale_2: float | None = Nonenum_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'np'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~WanPipelineOutput or tuple

参数

  • prompt (str 或 list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,请改为传入 prompt_embeds。
  • negative_prompt (str 或 list[str],可选) — 图像生成过程中需要避免的提示词。如果未定义,请改为传入 negative_prompt_embeds。在未使用引导(guidance_scale < 1)时将被忽略。
  • height (int,默认为 480) — 生成图像的高度(以像素为单位)。
  • width (int,默认为 832) — 生成图像的宽度(以像素为单位)。
  • num_frames (int,默认为 81) — 生成视频的帧数。
  • num_inference_steps (int,默认为 50) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但推理速度会变慢。
  • guidance_scale (float,默认为 5.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale 定义为 Imagen Paper 中公式 2 的 w。通过设置 guidance_scale > 1 来启用引导尺度。较高的引导尺度会促使生成与文本 prompt 紧密关联的图像,但通常以牺牲图像质量为代价。
  • guidance_scale_2 (float,可选,默认为 None) — 低噪声阶段 transformer(transformer_2)的 guidance scale。如果 None 且 pipeline 的 boundary_ratio 不为 None,则使用与 guidance_scale 相同的值。仅当 transformer_2 和 pipeline 的 boundary_ratio 均不为 None 时使用。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词生成的图像数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于使生成过程确定性的 torch.Generator。
  • latents (torch.Tensor, 可选) — 预先生成的、从高斯分布中采样的含噪潜变量,用作图像生成的输入。可用于以不同的提示词微调同一生成过程。如果未提供,则使用提供的随机generator进行采样,生成一个潜变量张量。
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词加权)。如果未提供,则从 prompt 输入参数生成文本嵌入。
  • negative_prompt_embeds (torch.Tensor,可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入(提示词权重)。如果未提供,negative_prompt_embeds 将根据 negative_prompt 输入参数生成。
  • output_type (str,可选,默认为 "np") — 生成图像的输出格式。可选 PIL.Image 或 np.array。
  • return_dict (bool,可选,默认为 True) — 是否返回 WanPipelineOutput 而不是普通元组。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • callback_on_step_end (Callable、PipelineCallback、MultiPipelineCallbacks、可选) — 在推理过程中,每个去噪步骤结束时调用的函数,或 PipelineCallback 或 MultiPipelineCallbacks 的子类,其参数如下:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。callback_kwargs 将包含由 callback_on_step_end_tensor_inputs 指定的所有张量列表。
  • callback_on_step_end_tensor_inputs (list,可选) — callback_on_step_end 函数的张量输入列表。列表中指定的张量将作为 callback_kwargs 参数传递。您只能包含流水线类 ._callback_tensor_inputs 属性中列出的变量。
  • max_sequence_length (int,默认为 512) — 文本编码器的最大序列长度。如果提示词长于该长度,将被截断;如果短于该长度,将被填充至该长度。

返回值

~WanPipelineOutput 或 tuple

如果 return_dict 为 True,则返回 WanPipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表,第二个元素是 bool 列表,用于指示对应的生成图像是否包含“不适合工作场所”(nsfw)内容。

用于生成的 pipeline 的调用函数。

示例:

>>> import torch
>>> from diffusers.utils import export_to_video
>>> from diffusers import AutoencoderKLWan, WanPipeline
>>> from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler

>>> # Available models: Wan-AI/Wan2.1-T2V-14B-Diffusers, Wan-AI/Wan2.1-T2V-1.3B-Diffusers
>>> model_id = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
>>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
>>> pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
>>> flow_shift = 5.0  # 5.0 for 720P, 3.0 for 480P
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
>>> negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"

>>> output = pipe(
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     height=720,
...     width=1280,
...     num_frames=81,
...     guidance_scale=5.0,
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=16)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 226device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

参数

  • prompt (str 或 list[str],可选) — 要编码的提示
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • do_classifier_free_guidance(bool,可选,默认为 True)— 是否使用 classifier free guidance。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词应生成的视频数量。用于放置结果嵌入的 torch 设备
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从 prompt 输入参数生成。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如提示词加权。如果未提供,negative_prompt_embeds 将从 negative_prompt 输入参数生成。
  • device — (torch.device,可选): torch 设备
  • dtype — (torch.dtype,可选): torch 数据类型

将提示词编码为文本编码器的隐藏状态。

WanImageToVideoPipeline

class diffusers.WanImageToVideoPipeline

< >

( tokenizer: AutoTokenizertext_encoder: UMT5EncoderModelvae: AutoencoderKLWanscheduler: FlowMatchEulerDiscreteSchedulerimage_processor: CLIPImageProcessorPil = Noneimage_encoder: CLIPVisionModel = Nonetransformer: WanTransformer3DModel = Nonetransformer_2: WanTransformer3DModel = Noneboundary_ratio: float | None = Noneexpand_timesteps: bool = False )

参数

  • tokenizer (T5Tokenizer) — 来自 T5 的分词器, 具体为 google/umt5-xxl 变体。
  • text_encoder(T5EncoderModel)—— T5,具体为 google/umt5-xxl 变体。
  • image_encoder (CLIPVisionModel) — CLIP,具体为 clip-vit-huge-patch14 变体。
  • transformer (WanTransformer3DModel) — 用于对输入潜变量进行去噪的条件 Transformer。
  • scheduler (UniPCMultistepScheduler) — 用于与 transformer 配合,对编码后的图像潜变量进行去噪的调度器。
  • vae (AutoencoderKLWan) — 变分自编码器(VAE)模型,用于将视频编码为潜在表示,以及从潜在表示解码为视频。
  • transformer_2(WanTransformer3DModel,可选)— 用于在低噪声阶段对输入潜变量进行去噪的条件 Transformer。在双阶段去噪中, transformer 负责高噪声阶段,transformer_2 负责低噪声阶段。如果未提供,则仅使用 transformer。
  • boundary_ratio (float, 可选,默认为 None) — 用于两阶段去噪中切换 transformer 的边界,表示占总时间步的比例。 实际的边界时间步计算为 boundary_ratio * num_train_timesteps。当提供该参数时, transformer 处理时间步 >= boundary_timestep 的部分,transformer_2 处理时间步 < boundary_timestep 的部分。如果为 None,则整个去噪过程仅使用 transformer。

使用 Wan 进行图像到视频生成的 Pipeline。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Noneheight: int = 480width: int = 832num_frames: int = 81num_inference_steps: int = 50guidance_scale: float = 5.0guidance_scale_2: float | None = Nonenum_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneimage_embeds: typing.Optional[torch.Tensor] = Nonelast_image: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'np'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~WanPipelineOutput or tuple

参数

  • image (PipelineImageInput) — 用于条件生成的输入图像。必须为图像、图像列表或 torch.Tensor。
  • last_image (torch.Tensor, 可选) — 用于条件化生成视频的可选最后一帧。提供时,模型将在 image(第一帧)和 last_image(最后一帧)之间进行插值。
  • prompt (str 或 list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则必须改为传入 prompt_embeds。
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • height (int,默认为 480) — 生成视频的高度。
  • width (int,默认为 832) — 生成视频的宽度。
  • num_frames (int,默认为 81) — 生成视频的帧数。
  • num_inference_steps (int,默认为 50) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但推理速度会变慢。
  • guidance_scale (float,默认为 5.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale 定义为 Imagen Paper 中公式 2 的 w。通过设置 guidance_scale > 1 来启用引导尺度。较高的引导尺度会促使生成与文本 prompt 紧密关联的图像,但通常以牺牲图像质量为代价。
  • guidance_scale_2 (float,可选,默认为 None) — 低噪声阶段 transformer(transformer_2)的 guidance scale。如果 None 且 pipeline 的 boundary_ratio 不为 None,则使用与 guidance_scale 相同的值。仅当 transformer_2 和 pipeline 的 boundary_ratio 均不为 None 时使用。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词生成的图像数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于使生成过程确定性的 torch.Generator。
  • latents (torch.Tensor, 可选) — 预先生成的、从高斯分布中采样的含噪潜变量,用作图像生成的输入。可用于以不同的提示词微调同一生成过程。如果未提供,则使用提供的随机generator进行采样,生成一个潜变量张量。
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词加权)。如果未提供,则从 prompt 输入参数生成文本嵌入。
  • negative_prompt_embeds (torch.Tensor,可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词权重)。如果未提供,则从 negative_prompt 输入参数生成文本嵌入。
  • image_embeds (torch.Tensor, 可选) — 预生成的图像嵌入。可用于轻松调整图像输入(加权)。如果未提供,则从 image 输入参数生成图像嵌入。
  • output_type (str,可选,默认为 "np") — 生成图像的输出格式。可选 PIL.Image 或 np.array。
  • return_dict (bool,可选,默认为 True) — 是否返回 WanPipelineOutput 而不是普通元组。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • callback_on_step_end (Callable、PipelineCallback、MultiPipelineCallbacks、可选) — 在推理过程中,每个去噪步骤结束时调用的函数,或 PipelineCallback 或 MultiPipelineCallbacks 的子类,其参数如下:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。callback_kwargs 将包含由 callback_on_step_end_tensor_inputs 指定的所有张量列表。
  • callback_on_step_end_tensor_inputs (list,可选) — callback_on_step_end 函数的张量输入列表。列表中指定的张量将作为 callback_kwargs 参数传递。您只能包含流水线类 ._callback_tensor_inputs 属性中列出的变量。
  • max_sequence_length (int,默认为 512) — 文本编码器的最大序列长度。如果提示词长于该长度,将被截断;如果短于该长度,将被填充至该长度。

返回值

~WanPipelineOutput 或 tuple

如果 return_dict 为 True,则返回 WanPipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表,第二个元素是 bool 列表,用于指示对应的生成图像是否包含“不适合工作场所”(nsfw)内容。

用于生成的 pipeline 的调用函数。

示例:

>>> import torch
>>> import numpy as np
>>> from diffusers import AutoencoderKLWan, WanImageToVideoPipeline
>>> from diffusers.utils import export_to_video, load_image
>>> from transformers import CLIPVisionModel

>>> # Available models: Wan-AI/Wan2.1-I2V-14B-480P-Diffusers, Wan-AI/Wan2.1-I2V-14B-720P-Diffusers
>>> model_id = "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers"
>>> image_encoder = CLIPVisionModel.from_pretrained(
...     model_id, subfolder="image_encoder", torch_dtype=torch.float32
... )
>>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
>>> pipe = WanImageToVideoPipeline.from_pretrained(
...     model_id, vae=vae, image_encoder=image_encoder, torch_dtype=torch.bfloat16
... )
>>> pipe.to("cuda")

>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg"
... )
>>> max_area = 480 * 832
>>> aspect_ratio = image.height / image.width
>>> mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1]
>>> height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
>>> width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
>>> image = image.resize((width, height))
>>> prompt = (
...     "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in "
...     "the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
... )
>>> negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"

>>> output = pipe(
...     image=image,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     height=height,
...     width=width,
...     num_frames=81,
...     guidance_scale=5.0,
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=16)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 226device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

参数

  • prompt (str 或 list[str],可选) — 要编码的提示
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • do_classifier_free_guidance(bool,可选,默认为 True)— 是否使用 classifier free guidance。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词应生成的视频数量。用于放置结果嵌入的 torch 设备
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从 prompt 输入参数生成。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如提示词加权。如果未提供,negative_prompt_embeds 将从 negative_prompt 输入参数生成。
  • device — (torch.device,可选): torch 设备
  • dtype — (torch.dtype,可选): torch 数据类型

将提示词编码为文本编码器的隐藏状态。

WanVACEPipeline

class diffusers.WanVACEPipeline

< >

( tokenizer: AutoTokenizertext_encoder: UMT5EncoderModelvae: AutoencoderKLWanscheduler: FlowMatchEulerDiscreteSchedulertransformer: WanVACETransformer3DModel = Nonetransformer_2: WanVACETransformer3DModel = Noneboundary_ratio: float | None = None )

参数

  • tokenizer (T5Tokenizer) — 来自 T5 的分词器, 具体为 google/umt5-xxl 变体。
  • text_encoder(T5EncoderModel)—— T5,具体为 google/umt5-xxl 变体。
  • vae (AutoencoderKLWan) — 变分自编码器(VAE)模型,用于将视频编码为潜在表示,以及从潜在表示解码为视频。
  • scheduler (UniPCMultistepScheduler) — 用于与 transformer 配合,对编码后的图像潜变量进行去噪的调度器。
  • transformer (WanVACETransformer3DModel, 可选) — 用于在高噪声阶段对输入潜变量进行去噪的条件 Transformer。在双阶段去噪中, transformer 负责高噪声阶段,transformer_2 负责低噪声阶段。必须提供 transformer 或 transformer_2 中的至少一个。
  • transformer_2 (WanVACETransformer3DModel, 可选) — 用于在低噪声阶段对输入潜变量进行去噪的条件 Transformer。在双阶段去噪中, transformer 负责高噪声阶段,transformer_2 负责低噪声阶段。必须提供 transformer 或 transformer_2 中的至少一个。
  • boundary_ratio (float, 可选,默认为 None) — 用于两阶段去噪中切换 transformer 的边界,表示占总时间步的比例。 实际的边界时间步计算为 boundary_ratio * num_train_timesteps。当提供该参数时, transformer 处理时间步 >= boundary_timestep 的部分,transformer_2 处理时间步 < boundary_timestep 的部分。如果为 None,则整个去噪过程仅使用可用的 transformer。

用于使用 Wan 进行可控生成的 Pipeline。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonevideo: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = Nonemask: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = Nonereference_images: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = Noneconditioning_scale: typing.Union[float, list[float], torch.Tensor] = 1.0height: int = 480width: int = 832num_frames: int = 81num_inference_steps: int = 50guidance_scale: float = 5.0guidance_scale_2: float | None = Nonenum_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'np'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~WanPipelineOutput or tuple

参数

  • prompt (str 或 list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则必须改为传入 prompt_embeds。
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • video (list[PIL.Image.Image], 可选) — 用作生成起点的输入视频。视频应是一个 PIL 图像列表、numpy 数组或 torch 张量。目前,该流水线一次仅支持生成一个视频。
  • mask (list[PIL.Image.Image], 可选) — 输入掩码用于定义哪些视频区域作为条件,哪些区域用于生成。掩码中的黑色区域表示条件区域,白色区域表示生成区域。掩码应为 PIL 图像列表、numpy 数组或 torch 张量。目前支持一次生成单个视频。
  • reference_images (list[PIL.Image.Image],可选) — 一个包含一张或多张参考图像的列表,作为生成的额外条件。例如,如果你正在尝试对视频进行修复以更改角色,可以在这里传入新角色的参考图像。有关支持的任务和用例的完整列表,请参阅 Diffusers 的 示例 和原始 用户指南。
  • conditioning_scale (float, list[float], torch.Tensor,默认为 1.0) — 在模型的每个控制层中,将控制条件潜在流添加到去噪潜在流时所应用的条件缩放。如果提供浮点数,则均匀应用于所有层。如果提供列表或张量,其长度应与模型中控制层的数量(len(transformer.config.vace_layers))相同。
  • height (int,默认为 480) — 生成图像的高度(以像素为单位)。
  • width (int,默认为 832) — 生成图像的宽度(以像素为单位)。
  • num_frames (int,默认为 81) — 生成视频的帧数。
  • num_inference_steps (int,默认为 50) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但推理速度会变慢。
  • guidance_scale (float,默认为 5.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale 定义为 Imagen Paper 中公式 2 的 w。通过设置 guidance_scale > 1 来启用引导尺度。较高的引导尺度会促使生成与文本 prompt 紧密关联的图像,但通常以牺牲图像质量为代价。
  • guidance_scale_2 (float,可选,默认为 None) — 低噪声阶段 transformer(transformer_2)的 guidance scale。如果 None 且 pipeline 的 boundary_ratio 不为 None,则使用与 guidance_scale 相同的值。仅当 transformer_2 和 pipeline 的 boundary_ratio 均不为 None 时使用。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词生成的图像数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于使生成过程确定性的 torch.Generator。
  • latents (torch.Tensor, 可选) — 预先生成的、从高斯分布中采样的含噪潜变量,用作图像生成的输入。可用于以不同的提示词微调同一生成过程。如果未提供,则使用提供的随机generator进行采样,生成一个潜变量张量。
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词加权)。如果未提供,则从 prompt 输入参数生成文本嵌入。
  • negative_prompt_embeds (torch.Tensor,可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入(提示词权重)。如果未提供,negative_prompt_embeds 将根据 negative_prompt 输入参数生成。
  • output_type (str,可选,默认为 "np") — 生成图像的输出格式。可选 PIL.Image 或 np.array。
  • return_dict (bool,可选,默认为 True) — 是否返回 WanPipelineOutput 而不是普通元组。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • callback_on_step_end (Callable、PipelineCallback、MultiPipelineCallbacks、可选) — 在推理过程中,每个去噪步骤结束时调用的函数,或 PipelineCallback 或 MultiPipelineCallbacks 的子类,其参数如下:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。callback_kwargs 将包含由 callback_on_step_end_tensor_inputs 指定的所有张量列表。
  • callback_on_step_end_tensor_inputs (list,可选) — callback_on_step_end 函数的张量输入列表。列表中指定的张量将作为 callback_kwargs 参数传递。您只能包含流水线类 ._callback_tensor_inputs 属性中列出的变量。
  • max_sequence_length (int,默认为 512) — 文本编码器的最大序列长度。如果提示词长于该长度,将被截断;如果短于该长度,将被填充至该长度。

返回值

~WanPipelineOutput 或 tuple

如果 return_dict 为 True,则返回 WanPipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表,第二个元素是 bool 列表,用于指示对应的生成图像是否包含“不适合工作场所”(nsfw)内容。

用于生成的 pipeline 的调用函数。

示例:

>>> import torch
>>> import PIL.Image
>>> from diffusers import AutoencoderKLWan, WanVACEPipeline
>>> from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
>>> from diffusers.utils import export_to_video, load_image
def prepare_video_and_mask(first_img: PIL.Image.Image, last_img: PIL.Image.Image, height: int, width: int, num_frames: int):
    first_img = first_img.resize((width, height))
    last_img = last_img.resize((width, height))
    frames = []
    frames.append(first_img)
    # Ideally, this should be 127.5 to match original code, but they perform computation on numpy arrays
    # whereas we are passing PIL images. If you choose to pass numpy arrays, you can set it to 127.5 to
    # match the original code.
    frames.extend([PIL.Image.new("RGB", (width, height), (128, 128, 128))] * (num_frames - 2))
    frames.append(last_img)
    mask_black = PIL.Image.new("L", (width, height), 0)
    mask_white = PIL.Image.new("L", (width, height), 255)
    mask = [mask_black, *[mask_white] * (num_frames - 2), mask_black]
    return frames, mask

>>> # Available checkpoints: Wan-AI/Wan2.1-VACE-1.3B-diffusers, Wan-AI/Wan2.1-VACE-14B-diffusers
>>> model_id = "Wan-AI/Wan2.1-VACE-1.3B-diffusers"
>>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
>>> pipe = WanVACEPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
>>> flow_shift = 3.0  # 5.0 for 720P, 3.0 for 480P
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe.to("cuda")

>>> prompt = "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective."
>>> negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
>>> first_frame = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png"
... )
>>> last_frame = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png>>> "
... )

>>> height = 512
>>> width = 512
>>> num_frames = 81
>>> video, mask = prepare_video_and_mask(first_frame, last_frame, height, width, num_frames)

>>> output = pipe(
...     video=video,
...     mask=mask,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     height=height,
...     width=width,
...     num_frames=num_frames,
...     num_inference_steps=30,
...     guidance_scale=5.0,
...     generator=torch.Generator().manual_seed(42),
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=16)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 226device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

参数

  • prompt (str 或 list[str],可选) — 要编码的提示
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • do_classifier_free_guidance(bool,可选,默认为 True)— 是否使用 classifier free guidance。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词应生成的视频数量。用于放置结果嵌入的 torch 设备
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从 prompt 输入参数生成。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如提示词加权。如果未提供,negative_prompt_embeds 将从 negative_prompt 输入参数生成。
  • device — (torch.device,可选): torch 设备
  • dtype — (torch.dtype,可选): torch 数据类型

将提示词编码为文本编码器的隐藏状态。

WanVideoToVideoPipeline

class diffusers.WanVideoToVideoPipeline

< >

( tokenizer: AutoTokenizertext_encoder: UMT5EncoderModeltransformer: WanTransformer3DModelvae: AutoencoderKLWanscheduler: FlowMatchEulerDiscreteScheduler )

参数

  • tokenizer (T5Tokenizer) — 来自 T5 的分词器, 具体为 google/umt5-xxl 变体。
  • text_encoder(T5EncoderModel)—— T5,具体为 google/umt5-xxl 变体。
  • transformer (WanTransformer3DModel) — 用于对输入潜变量进行去噪的条件 Transformer。
  • scheduler (UniPCMultistepScheduler) — 用于与 transformer 配合,对编码后的图像潜变量进行去噪的调度器。
  • vae (AutoencoderKLWan) — 变分自编码器(VAE)模型,用于将视频编码为潜在表示,以及从潜在表示解码为视频。

使用 Wan 进行视频到视频生成的 Pipeline。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( video: list = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] = Noneheight: int = 480width: int = 832num_inference_steps: int = 50timesteps: list[int] | None = Noneguidance_scale: float = 5.0strength: float = 0.8num_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'np'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~WanPipelineOutput or tuple

参数

  • video (list[PIL.Image.Image]) — 用于视频到视频生成的起始输入视频。视频应以 PIL 图像列表、numpy 数组或 torch 张量的形式提供。
  • prompt (str 或 list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则必须改为传入 prompt_embeds。
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • height (int,默认为 480) — 生成图像的高度(以像素为单位)。
  • width (int,默认为 832) — 生成图像的宽度(以像素为单位)。
  • num_inference_steps (int,默认为 50) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但推理速度会变慢。
  • timesteps (list[int], 可选) — 用于支持 timesteps 参数的调度器去噪过程的自定义时间步,该参数位于其 set_timesteps 方法中。如果未定义,则使用传入 num_inference_steps 时的默认行为。必须按降序排列。
  • guidance_scale (float,默认为 5.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale 定义为 Imagen Paper 中公式 2 的 w。通过设置 guidance_scale > 1 来启用引导尺度。较高的引导尺度会促使生成与文本 prompt 紧密关联的图像,但通常以牺牲图像质量为代价。
  • strength (float,默认为 0.8) — 较高的 strength 值会导致原始图像与生成的视频之间产生更大的差异。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词生成的图像数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于使生成过程确定性的 torch.Generator。
  • latents (torch.Tensor, 可选) — 预先生成的、从高斯分布中采样的含噪潜变量,用作图像生成的输入。可用于以不同的提示词微调同一生成过程。如果未提供,则使用提供的随机generator进行采样,生成一个潜变量张量。
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词加权)。如果未提供,则从 prompt 输入参数生成文本嵌入。
  • negative_prompt_embeds (torch.Tensor,可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入(提示词权重)。如果未提供,negative_prompt_embeds 将根据 negative_prompt 输入参数生成。
  • output_type (str,可选,默认为 "np") — 生成图像的输出格式。可选 PIL.Image 或 np.array。
  • return_dict (bool,可选,默认为 True) — 是否返回 WanPipelineOutput 而不是普通元组。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • callback_on_step_end (Callable、PipelineCallback、MultiPipelineCallbacks、可选) — 在推理过程中,每个去噪步骤结束时调用的函数,或 PipelineCallback 或 MultiPipelineCallbacks 的子类,其参数如下:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。callback_kwargs 将包含由 callback_on_step_end_tensor_inputs 指定的所有张量列表。
  • callback_on_step_end_tensor_inputs (list,可选) — callback_on_step_end 函数的张量输入列表。列表中指定的张量将作为 callback_kwargs 参数传递。您只能包含流水线类 ._callback_tensor_inputs 属性中列出的变量。
  • max_sequence_length (int,默认为 512) — 文本编码器的最大序列长度。如果提示词长于该长度,将被截断;如果短于该长度,将被填充至该长度。

返回值

~WanPipelineOutput 或 tuple

如果 return_dict 为 True,则返回 WanPipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表,第二个元素是 bool 列表,用于指示对应的生成图像是否包含“不适合工作场所”(nsfw)内容。

用于生成的 pipeline 的调用函数。

示例:

>>> import torch
>>> from diffusers.utils import export_to_video, load_video
>>> from diffusers import AutoencoderKLWan, WanVideoToVideoPipeline
>>> from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler

>>> # Available models: Wan-AI/Wan2.1-T2V-14B-Diffusers, Wan-AI/Wan2.1-T2V-1.3B-Diffusers
>>> model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
>>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
>>> pipe = WanVideoToVideoPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
>>> flow_shift = 3.0  # 5.0 for 720P, 3.0 for 480P
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe.to("cuda")

>>> prompt = "A robot standing on a mountain top. The sun is setting in the background"
>>> negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
>>> video = load_video(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/hiker.mp4"
... )
>>> output = pipe(
...     video=video,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     height=480,
...     width=720,
...     guidance_scale=5.0,
...     strength=0.7,
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=16)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 226device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

参数

  • prompt (str 或 list[str],可选) — 要编码的提示
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • do_classifier_free_guidance(bool,可选,默认为 True)— 是否使用 classifier free guidance。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词应生成的视频数量。用于放置结果嵌入的 torch 设备
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从 prompt 输入参数生成。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如提示词加权。如果未提供,negative_prompt_embeds 将从 negative_prompt 输入参数生成。
  • device — (torch.device,可选): torch 设备
  • dtype — (torch.dtype,可选): torch 数据类型

将提示词编码为文本编码器的隐藏状态。

WanAnimatePipeline

类 diffusers.WanAnimatePipeline

< >

( tokenizer: AutoTokenizertext_encoder: UMT5EncoderModelvae: AutoencoderKLWanscheduler: UniPCMultistepSchedulerimage_processor: CLIPImageProcessorPilimage_encoder: CLIPVisionModeltransformer: WanAnimateTransformer3DModel )

参数

  • tokenizer (T5Tokenizer) — 来自 T5 的分词器, 具体为 google/umt5-xxl 变体。
  • text_encoder(T5EncoderModel)—— T5,具体为 google/umt5-xxl 变体。
  • image_encoder (CLIPVisionModel) — CLIP,具体为 clip-vit-huge-patch14 变体。
  • transformer (WanAnimateTransformer3DModel) — 用于对输入潜变量进行去噪的条件 Transformer。
  • scheduler (UniPCMultistepScheduler) — 用于与 transformer 配合,对编码后的图像潜变量进行去噪的调度器。
  • vae (AutoencoderKLWan) — 变分自编码器(VAE)模型,用于将视频编码为潜在表示,以及从潜在表示解码为视频。
  • image_processor (CLIPImageProcessor) — 用于在编码前对图像进行预处理的图像处理器。

使用 Wan-Animate 进行统一角色动画和替换的 Pipeline。

WanAnimatePipeline 以角色图像、姿态视频和面部视频作为输入,并以两种模式生成视频:

  1. 动画模式:模型会生成一段角色图像视频,模仿输入姿态和面部视频中的人类动作。角色会根据提供的动作控制进行动画处理,从而生成一段新的角色动画视频。

  2. 替换模式:模型使用提供的角色图像,替换背景视频中的角色,并利用姿态视频和面部视频进行动作控制。此模式需要额外的 background_video 和 mask_video 输入。遮罩视频中,黑色区域表示应保留原始内容,白色区域表示应生成新角色。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

该 pipeline 还继承了以下加载方法:

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]pose_video: listface_video: listbackground_video: list[PIL.Image.Image] | None = Nonemask_video: list[PIL.Image.Image] | None = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] = Noneheight: int = 720width: int = 1280segment_frame_length: int = 77num_inference_steps: int = 20mode: str = 'animate'prev_segment_conditioning_frames: int = 1motion_encode_batch_size: int | None = Noneguidance_scale: float = 1.0num_videos_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneimage_embeds: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'np'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~WanPipelineOutput or tuple

参数

  • image (PipelineImageInput) — 用于条件生成的输入角色图像。必须是一张图像、一个图像列表或一个 torch.Tensor。
  • pose_video (list[PIL.Image.Image]) — 用于条件生成的输入姿态视频。必须是一个 PIL 图像列表。
  • face_video (list[PIL.Image.Image]) — 用于条件生成的输入人脸视频。必须是一个 PIL 图像列表。
  • background_video (list[PIL.Image.Image], 可选) — 当 mode 为 "replace" 时,用于条件生成输入的后台视频。必须是一个 PIL 图像列表。
  • mask_video (list[PIL.Image.Image], 可选) — 当 mode 为 "replace" 时,用于条件生成输入的掩码视频。必须是一个 PIL 图像列表。
  • prompt (str 或 list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则必须改为传入 prompt_embeds。
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • mode (str,默认为 "animation") — 生成模式。在 "animate" 和 "replace" 之间选择。
  • prev_segment_conditioning_frames (int,默认为 1) — 用于时间引导的上一视频片段的帧数。建议设置为 1 或 5。通常应为 4N + 1,其中 N 为非负整数。
  • motion_encode_batch_size (int, 可选) — 通过运动编码器对面部视频进行批量编码时的批处理大小。通过设置较小的批处理大小,可以在推理速度和更低的内存占用之间进行权衡。如果未设置,则默认为 self.transformer.config.motion_encoder_batch_size。
  • height (int,默认为 720) — 生成视频的高度。
  • width (int,默认为 1280) — 生成视频的宽度。
  • segment_frame_length (int,默认为 77) — 每个生成的视频片段中的帧数。生成的视频总帧数将与 pose_video 的帧数相等;我们将分段生成视频,直到达到该长度。通常应为 4N + 1,其中 N 为非负整数。
  • num_inference_steps (int,默认为 20) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但代价是推理速度变慢。
  • guidance_scale (float,默认为 1.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale 定义为 Imagen Paper 中公式 2 的 w。通过设置 guidance_scale > 1 来启用引导尺度。较高的引导尺度会促使生成与文本 prompt 紧密关联的图像,通常以牺牲图像质量为代价。默认情况下,Wan Animate 推理不使用 CFG。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词生成的图像数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 用于使生成过程确定性的 torch.Generator。
  • latents (torch.Tensor, 可选) — 预先生成的、从高斯分布中采样的含噪潜变量,用作图像生成的输入。可用于以不同的提示词微调同一生成过程。如果未提供,则使用提供的随机generator进行采样,生成一个潜变量张量。
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词加权)。如果未提供,则从 prompt 输入参数生成文本嵌入。
  • negative_prompt_embeds (torch.Tensor,可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词权重)。如果未提供,则从 negative_prompt 输入参数生成文本嵌入。
  • image_embeds (torch.Tensor, 可选) — 预生成的图像嵌入。可用于轻松调整图像输入(加权)。如果未提供,则从 image 输入参数生成图像嵌入。
  • output_type (str,可选,默认为 "np") — 生成图像的输出格式。可选 PIL.Image 或 np.array。
  • return_dict (bool,可选,默认为 True) — 是否返回 WanPipelineOutput 而不是普通元组。
  • attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将传递给 diffusers.models.attention_processor 中定义的 AttentionProcessor,该处理器在 self.processor 下定义。
  • callback_on_step_end (Callable、PipelineCallback、MultiPipelineCallbacks、可选) — 在推理过程中,每个去噪步骤结束时调用的函数,或 PipelineCallback 或 MultiPipelineCallbacks 的子类,其参数如下:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。callback_kwargs 将包含由 callback_on_step_end_tensor_inputs 指定的所有张量列表。
  • callback_on_step_end_tensor_inputs (List,可选) — callback_on_step_end 函数的张量输入列表。列表中指定的张量将作为 callback_kwargs 参数传入。您只能包含流水线类的 ._callback_tensor_inputs 属性中列出的变量。
  • max_sequence_length (int,默认为 512) — 文本编码器的最大序列长度。如果提示词长于该长度,将被截断;如果短于该长度,将被填充至该长度。

返回值

~WanPipelineOutput 或 tuple

如果 return_dict 为 True,则返回 WanPipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表,第二个元素是 bool 列表,用于指示对应的生成图像是否包含“不适合工作场所”(nsfw)内容。

用于生成的 pipeline 的调用函数。

示例:

>>> import torch
>>> import numpy as np
>>> from diffusers import WanAnimatePipeline
>>> from diffusers.utils import export_to_video, load_image, load_video

>>> model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers"
>>> pipe = WanAnimatePipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> # Optionally upcast the Wan VAE to FP32
>>> pipe.vae.to(torch.float32)
>>> pipe.to("cuda")

>>> # Load the reference character image
>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg"
... )

>>> # Load pose and face videos (preprocessed from reference video)
>>> # Note: Videos should be preprocessed to extract pose keypoints and face features
>>> # Refer to the Wan-Animate preprocessing documentation for details
>>> pose_video = load_video("path/to/pose_video.mp4")
>>> face_video = load_video("path/to/face_video.mp4")

>>> # CFG is generally not used for Wan Animate
>>> prompt = (
...     "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in "
...     "the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
... )

>>> # Animation mode: Animate the character with the motion from pose/face videos
>>> output = pipe(
...     image=image,
...     pose_video=pose_video,
...     face_video=face_video,
...     prompt=prompt,
...     height=height,
...     width=width,
...     segment_frame_length=77,  # Frame length of each inference segment
...     guidance_scale=1.0,
...     num_inference_steps=20,
...     mode="animate",
... ).frames[0]
>>> export_to_video(output, "output_animation.mp4", fps=30)

>>> # Replacement mode: Replace a character in the background video
>>> # Requires additional background_video and mask_video inputs
>>> background_video = load_video("path/to/background_video.mp4")
>>> mask_video = load_video("path/to/mask_video.mp4")  # Black areas preserved, white areas generated
>>> output = pipe(
...     image=image,
...     pose_video=pose_video,
...     face_video=face_video,
...     background_video=background_video,
...     mask_video=mask_video,
...     prompt=prompt,
...     height=height,
...     width=width,
...     segment_frame_length=77,  # Frame length of each inference segment
...     guidance_scale=1.0,
...     num_inference_steps=20,
...     mode="replace",
... ).frames[0]
>>> export_to_video(output, "output_replacement.mp4", fps=30)

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 226device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

参数

  • prompt (str 或 list[str],可选) — 要编码的提示
  • negative_prompt (str 或 list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入 negative_prompt_embeds。在未使用引导时会被忽略(即当 guidance_scale 小于 1 时忽略)。
  • do_classifier_free_guidance(bool,可选,默认为 True)— 是否使用 classifier free guidance。
  • num_videos_per_prompt (int,可选,默认为 1) — 每个提示词应生成的视频数量。用于放置结果嵌入的 torch 设备
  • prompt_embeds (torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从 prompt 输入参数生成。
  • negative_prompt_embeds (torch.Tensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如提示词加权。如果未提供,negative_prompt_embeds 将从 negative_prompt 输入参数生成。
  • device — (torch.device,可选): torch 设备
  • dtype — (torch.dtype,可选): torch 数据类型

将提示词编码为文本编码器的隐藏状态。

pad_video_frames

< >

( frames: listnum_target_frames: int )

使用类似“reflect”的策略,将类数组视频 frames 填充至 num_target_frames。假设帧维度是第一个维度。在一维情况下,我们可以将该策略可视化如下:

pad_video_frames([1, 2, 3, 4, 5], 10) -> [1, 2, 3, 4, 5, 4, 3, 2, 1, 2]

WanPipelineOutput

class diffusers.pipelines.wan.pipeline_output.WanPipelineOutput

< >

( frames: Tensor )

参数

  • frames (torch.Tensor、np.ndarray 或 list[list[PIL.Image.Image]]) — 视频输出列表 - 它可以是一个长度为 batch_size, 的嵌套列表,其中每个子列表包含长度为 num_frames. 的去噪 PIL 图像序列。它也可以是一个形状为 (batch_size, num_frames, channels, height, width) 的 NumPy 数组或 Torch 张量。

Wan 流水线的输出类。

Update on GitHub