问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

开源视频生成 Pyramid Flow 本地部署实测

创作时间:
作者:
@小白创作中心

开源视频生成 Pyramid Flow 本地部署实测

引用
CSDN
1.
https://blog.csdn.net/u010522887/article/details/143279061

Pyramid Flow是一个开源的视频生成模型,具有参数量小、生成效果好等特点。本文将详细介绍如何在本地部署Pyramid Flow,并通过实际测试来评估其性能。

1. Pyramid Flow 简介

项目地址:https://github.com/jy0205/Pyramid-Flow

Pyramid Flow的主要亮点包括:

  • 仅需2B参数,即可生成768p分辨率、24fps的10秒视频
  • 支持「文本到视频」和「图像到视频」两种模式
  • 采用自回归生成方式,确保视频内容的连贯性和流畅性
  • 采用金字塔式的多尺度架构,生成效率更高

根据官方评测结果,除了semantic score,其他指标均优于开源方案CogVideo:

2. 在线体验

Pyramid Flow已在huggingface上线,可以直接在线体验:

https://huggingface.co/spaces/Pyramid-Flow/pyramid-flow

如果无法访问,可以查看官方的生成样例:

https://pyramid-flow.github.io/

接下来,我们将详细介绍如何在本地部署Pyramid Flow。

3. 本地部署

3.1 环境准备

首先需要准备Pyramid Flow的运行环境:

git clone https://github.com/jy0205/Pyramid-Flow
cd Pyramid-Flow
conda create -n pyramid python==3.8.10
conda activate pyramid
pip install -r requirements.txt

然后,将模型下载到本地:

export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download rain1011/pyramid-flow-sd3 --local-dir ckpts/

模型权重包括768p和384p两种版本。384p版本支持5秒长的24FPS视频,而768p版本则可以生成10秒视频。

3.2 推理测试

首先加载模型:

import os
import torch
from PIL import Image
from pyramid_dit import PyramidDiTForVideoGeneration
from diffusers.utils import export_to_video
os.environ['CUDA_VISIBLE_DEVICES'] = '2'
model = PyramidDiTForVideoGeneration('ckpts/', 'bf16', model_variant='diffusion_transformer_384p')
model.vae.enable_tiling()
# model.vae.to("cuda")
# model.dit.to("cuda")
# model.text_encoder.to("cuda")
# if you're not using sequential offloading bellow uncomment the lines above ^
model.enable_sequential_cpu_offload()

如果把模型都加载进GPU,至少需要19G显存,建议采用上述代码。

测试文本生成视频:

def t2v():
    prompt = "A movie trailer featuring the adventures of the 30 year old space man wearing a red wool knitted motorcycle helmet, blue sky, salt desert, cinematic style, shot on 35mm film, vivid colors"
    with torch.no_grad(), torch.amp.autocast('cuda', dtype=torch.bfloat16):
        frames = model.generate(
            prompt=prompt,
            num_inference_steps=[20, 20, 20],
            video_num_inference_steps=[10, 10, 10],
            height=384,     
            width=640,
            temp=16,                    # temp=16: 5s, temp=31: 10s
            guidance_scale=9.0,         # The guidance for the first frame, set it to 7 for 384p variant
            video_guidance_scale=5.0,   # The guidance for the other video latent
            output_type="pil",
            save_memory=True,           # If you have enough GPU memory, set it to `False` to improve vae decoding speed
        )
    export_to_video(frames, "./text_to_video_sample.mp4", fps=24)

测试图片生成视频:

def i2v():
    image = Image.open('assets/the_great_wall.jpg').convert("RGB").resize((640, 384))
    prompt = "FPV flying over the Great Wall"
    with torch.no_grad(), torch.amp.autocast('cuda', dtype=torch.bfloat16):
        frames = model.generate_i2v(
            prompt=prompt,
            input_image=image,
            num_inference_steps=[10, 10, 10],
            temp=16,
            video_guidance_scale=4.0,
            output_type="pil",
            save_memory=True,           # If you have enough GPU memory, set it to `False` to improve vae decoding speed
        )
    export_to_video(frames, "./image_to_video_sample.mp4", fps=24)

Pyramid Flow对显存要求较高,生成5秒视频至少需要13分钟:

100%|████| 16/16 [13:11<00:00, 49.45s/it]

实测结果显示,Pyramid Flow的效果并未与CogVideo拉开明显差距。

写在最后

AI应用大体可分为:文本、语音、图片、视频,其中语音已被硅基生物攻破。而AI视频生成,从当前效果来看,依然任重道远!

© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号