license: mit
library_name: diffusers
pipeline_tag: text-to-video
本代码库包含StreamingT2V第二阶段经过精简和独立封装的视频扩展流程,命名为"VidXTend"。
该模型主要用于将16帧256x256像素的动画每次扩展8帧(8fps下扩展1秒时长)。
@article{henschel2024streamingt2v,
title={StreamingT2V: 基于文本生成一致、动态且可扩展的长视频},
author={Henschel, Roberto and Khachatryan, Levon and Hayrapetyan, Daniil and Poghosyan, Hayk and Tadevosyan, Vahram and Wang, Zhangyang and Navasardyan, Shant and Shi, Humphrey},
journal={arXiv预印本 arXiv:2403.14773},
year={2024}
}
代码仓库: https://github.com/Picsart-AI-Research/StreamingT2V
使用指南
安装
首先将VidXTend包安装到Python环境。若新建专用环境,请确保指定支持CUDA的torch版本,否则将仅运行于CPU模式。
pip install git+https://github.com/painebenjamin/vidxtend.git
命令行工具
安装包时会同时安装vidxtend
命令行工具。
用法: vidxtend [选项] 视频文件 提示文本
对视频文件运行VidXTend,将生成的帧追加至视频末尾。
选项:
-fps, --frame-rate 整数 视频帧率。默认使用输入视频帧率。
-s, --seconds 浮点数 需扩展的视频秒数。该数值乘以帧率即为生成的总帧数 [默认值: 1.0]
-np, --negative-prompt 文本 扩散过程的负面提示词。
-cfg, --guidance-scale 浮点数 扩散过程的引导系数 [默认值: 7.5]
-ns, --num-inference-steps 整数 扩散步数 [默认值: 50]
-r, --seed 整数 随机种子。
-m, --model 文本 HuggingFace模型名称。
-nh, --no-half 禁用半精度计算。
-no, --no-offload 禁用CPU内存卸载以节省GPU内存。
-ns, --no-slicing 禁用VAE切片技术。
-g, --gpu-id 整数 指定使用的GPU ID。
-sf, --model-single-file 下载并使用单文件模型而非目录。
-cf, --config-file 文本 单文件模式下的配置文件。可接受路径或与模型文件同目录的文件名。未提供时将从模型仓库下载 [默认值: config.json]
-mf, --model-filename 文本 单文件模式下要下载的模型文件 [默认值: vidxtend.safetensors]
-rs, --remote-subfolder 文本 单文件模式下远程仓库的子目录。
-cd, --cache-dir 目录 下载缓存目录。默认使用huggingface缓存。
-o, --output 文件 输出文件 [默认值: output.mp4]
-f, --fit [实际尺寸|覆盖|包含|拉伸] 图像适配模式 [默认值: 覆盖]
-a, --anchor [左上|中上|右上|左中|中心|右中|左下|中下|右下] 图像锚点 [默认值: 左上]
--help 显示帮助信息并退出。
Python接口
可通过以下方式创建流程(自动从本仓库拉取权重),支持分体模型模式:
from vidxtend import VidXTendPipeline
pipeline = VidXTendPipeline.from_pretrained(
"benjamin-paine/vidxtend",
torch_dtype=torch.float16,
variant="fp16",
)
或单文件模式:
from vidxtend import VidXTendPipeline
pipeline = VidXTendPipeline.from_single_file(
"benjamin-paine/vidxtend",
torch_dtype=torch.float16,
variant="fp16",
)
使用以下方法提升性能:
pipeline.enable_model_cpu_offload()
pipeline.enable_vae_slicing()
pipeline.set_use_memory_efficient_attention_xformers()
调用示例如下:
# 假设images是PIL图像列表
new_frames = pipeline(
prompt=提示词,
negative_prompt=None, # 可选负面提示词
image=images[-8:], # 使用视频最后8帧
input_frames_conditioning=images[:1], # 使用视频首帧
eta=1.0,
guidance_scale=7.5,
output_type="pil"
).frames[8:] # 移除输出前8帧(因其作为引导帧)