Skip to content

基于PIA(个性化图像动画器)的图像到视频生成

概述

PIA:通过文本到图像模型中的即插即用模块实现个性化图像动画,作者:张一鸣、邢哲宁、曾艳红、方有庆、陈凯

个性化文本到图像(T2I)模型的最新进展彻底改变了内容创作,使非专业人士能够生成具有独特风格的惊艳图像。尽管前景广阔,但通过文本将现实运动添加到这些个性化图像中面临着重大挑战,包括保持独特风格、高保真细节以及通过文本实现运动可控性。在本文中,我们提出了PIA,一个个性化图像动画器,它在与条件图像对齐、通过文本实现运动可控性以及与各种个性化T2I模型兼容方面表现出色,无需特定调整。为了实现这些目标,PIA基于一个具有良好训练的时间对齐层的基T2I模型构建,允许将任何个性化T2I模型无缝转换为图像动画模型。PIA的一个关键组件是引入条件模块,该模块利用条件帧和帧间亲和力作为输入,通过亲和力提示引导外观信息传输,以在潜在空间中进行单帧合成。这种设计缓解了外观相关图像对齐的挑战,并允许更专注于与运动相关指导的对齐。

项目页面

可用管道

| 管道 | 任务 | 演示

|---|---|:---😐 | PIAPipeline | Image-to-Video Generation with PIA |

可用的检查点

适用于PIA的Motion Adapter检查点可以在OpenMMLab组织下找到。这些检查点旨在与基于Stable Diffusion 1.5的任何模型一起使用。

使用示例

PIA需要一个MotionAdapter检查点和Stable Diffusion 1.5模型检查点。MotionAdapter是一组负责在图像帧之间添加连贯运动的Motion模块。这些模块在Stable Diffusion UNet中的Resnet和Attention块之后应用。除了运动模块外,PIA还将SD 1.5 UNet模型的输入卷积层替换为9通道输入卷积层。

以下示例展示了如何使用PIA从单张图像生成视频。

python
import torch
from diffusers import (
    EulerDiscreteScheduler,
    MotionAdapter,
    PIAPipeline,
)
from diffusers.utils import export_to_gif, load_image

adapter = MotionAdapter.from_pretrained("openmmlab/PIA-condition-adapter")
pipe = PIAPipeline.from_pretrained("SG161222/Realistic_Vision_V6.0_B1_noVAE", motion_adapter=adapter, torch_dtype=torch.float16)

pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()
pipe.enable_vae_slicing()

image = load_image(
    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/cat_6.png?download=true"
)
image = image.resize((512, 512))
prompt = "cat in a field"
negative_prompt = "wrong white balance, dark, sketches,worst quality,low quality"

generator = torch.Generator("cpu").manual_seed(0)
output = pipe(image=image, prompt=prompt, generator=generator)
frames = output.frames[0]
export_to_gif(frames, "pia-animation.gif")

以下是一些示例输出:

使用 FreeInit

FreeInit: 弥合视频扩散模型中的初始化差距,作者:Tianxing Wu, Chenyang Si, Yuming Jiang, Ziqi Huang, Ziwei Liu。

FreeInit 是一种有效的方法,它通过在不进行额外训练的情况下提高视频扩散模型生成视频的时间一致性和整体质量。它可以在推理时无缝应用于 PIA、AnimateDiff、ModelScope、VideoCrafter 以及各种其他视频生成模型,通过迭代优化潜在初始化噪声来实现。更多细节可以在论文中找到。

以下示例展示了 FreeInit 的使用方法。

python
import torch
from diffusers import (
    DDIMScheduler,
    MotionAdapter,
    PIAPipeline,
)
from diffusers.utils import export_to_gif, load_image

adapter = MotionAdapter.from_pretrained("openmmlab/PIA-condition-adapter")
pipe = PIAPipeline.from_pretrained("SG161222/Realistic_Vision_V6.0_B1_noVAE", motion_adapter=adapter)

# enable FreeInit
# Refer to the enable_free_init documentation for a full list of configurable parameters
pipe.enable_free_init(method="butterworth", use_fast_sampling=True)

# Memory saving options
pipe.enable_model_cpu_offload()
pipe.enable_vae_slicing()

pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
image = load_image(
    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/cat_6.png?download=true"
)
image = image.resize((512, 512))
prompt = "cat in a field"
negative_prompt = "wrong white balance, dark, sketches,worst quality,low quality"

generator = torch.Generator("cpu").manual_seed(0)

output = pipe(image=image, prompt=prompt, generator=generator)
frames = output.frames[0]
export_to_gif(frames, "pia-freeinit-animation.gif")

PIAPipeline

[[autodoc]] PIAPipeline - all - call - enable_freeu - disable_freeu - enable_free_init - disable_free_init - enable_vae_slicing - disable_vae_slicing - enable_vae_tiling - disable_vae_tiling

PIAPipelineOutput

[[autodoc]] pipelines.pia.PIAPipelineOutput