Wan2.2 中文文档 下载 App

Animate-14B 预处理 + 推理:Animation 和 Replacement 两步走

预处理步骤

在跑任何推理之前,先把输入素材(角色图 + 参考视频)处理成骨架、人脸特征、遮罩等中间文件。仓库里有专门的预处理脚本。

Animation 模式预处理

python ./wan/modules/animate/preprocess/preprocess_data.py \
  --ckpt_path ./Wan2.2-Animate-14B/process_checkpoint \
  --video_path ./examples/wan_animate/animate/video.mp4 \
  --refer_path ./examples/wan_animate/animate/image.jpeg \
  --save_path ./examples/wan_animate/animate/process_results \
  --resolution_area 1280 720 \
  --retarget_flag \
  --use_flux

参数说明:

Replacement 模式预处理

python ./wan/modules/animate/preprocess/preprocess_data.py \
  --ckpt_path ./Wan2.2-Animate-14B/process_checkpoint \
  --video_path ./examples/wan_animate/replace/video.mp4 \
  --refer_path ./examples/wan_animate/replace/image.jpeg \
  --save_path ./examples/wan_animate/replace/process_results \
  --resolution_area 1280 720 \
  --iterations 3 \
  --k 7 \
  --w_len 1 \
  --h_len 1 \
  --replace_flag

Replace 模式有更多参数控制遮罩生成,通常保持默认即可。

Animation 推理

预处理完成后,单卡推理:

python generate.py \
  --task animate-14B \
  --ckpt_dir ./Wan2.2-Animate-14B/ \
  --src_root_path ./examples/wan_animate/animate/process_results/ \
  --refert_num 1

多卡加速:

python -m torch.distributed.run --nnodes 1 --nproc_per_node 8 generate.py \
  --task animate-14B \
  --ckpt_dir ./Wan2.2-Animate-14B/ \
  --src_root_path ./examples/wan_animate/animate/process_results/ \
  --refert_num 1 \
  --dit_fsdp --t5_fsdp --ulysses_size 8

Replacement 推理

和 Animation 类似,加上 --replace_flag 和可选的 --use_relighting_lora:

python generate.py \
  --task animate-14B \
  --ckpt_dir ./Wan2.2-Animate-14B/ \
  --src_root_path ./examples/wan_animate/replace/process_results/ \
  --refert_num 1 \
  --replace_flag \
  --use_relighting_lora

--use_relighting_lora 是替换模式的关键——它让新角色自然融入原视频的光照和色调,不会像"贴上去的"。

Diffusers Pipeline(更简单)

如果你更习惯用 Diffusers API,Animate-14B 也已经集成:

from diffusers import WanAnimatePipeline
from diffusers.utils import export_to_video, load_image, load_video

device = "cuda:0"
pipe = WanAnimatePipeline.from_pretrained(
    "Wan-AI/Wan2.2-Animate-14B-Diffusers",
    torch_dtype=torch.bfloat16
)
pipe.to(device)

# Animation 模式
animate_video = pipe(
    image=load_image("角色图.png"),
    pose_video=load_video("动作参考.mp4"),
    face_video=load_video("面部参考.mp4"),
    prompt="People in the video are doing actions.",
    mode="animate",
).frames[0]
export_to_video(animate_video, "animate.mp4", fps=30)

Diffusers 版本不需要手动跑预处理,Pipeline 内部会处理中间步骤。