Gen-L-Video

G-U-NApache-2.0长期未更新

基于扩散模型的多文本长视频生成与编辑方案,通过时序协同去噪把多个文本提示拼成连贯长视频,解决单次生成时长受限的问题。

The official implementation for "Gen-L-Video: Multi-Text to Long Video Generation via Temporal Co-Denoising".

v0.2发布于 2023-06-09 10:54 UTC307star33fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
conda env create -f requirements.yml
conda activate glv
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
bash scripts/download_pretrained_models.sh
硬件要求按 README 说明

README 提到多数结果可用单张 RTX 3090 生成;环境配置使用 pytorch-cuda=11.6,未说明 CPU 运行方式。

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

免训练把短视频扩散模型扩展成多文本条件的长视频生成与编辑工具

基于扩散模型的多文本长视频生成与编辑方案,通过时序协同去噪把多个文本提示拼成连贯长视频,解决单次生成时长受限的问题。

核心能力

  • 用时间协同去噪把短视频模型扩展到数百帧
  • 支持多段不同语义文本条件的长视频生成
  • 无需额外训练即可复用现成短视频扩散模型
  • 集成 SAM 与 Grounding DINO 做视频内任意物体编辑
  • 支持 pose、depth、seg、sketch、canny 多种控制方式

容易踩的坑

仓库含大量超过 100M 的 gif,直接 clone 可能过大,需 fork 后删除 statics 再克隆;需先下载预训练权重并在配置文件中填写绝对或相对路径;Grounding DINO 在无 GPU 的管理节点上安装需提交到计算节点,否则无法用 GPU 检测。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

4 个版本v0.2
  1. v0.2最新正式版2023-06-09 · 2023-06-09 10:54 UTC
    1. Fix bugs of run_isolated
    2. Add video2video generation, capable of generating very realistic videos.
  2. v0.12023-06-04 · 2023-06-04 18:42 UTC
    查看更新说明
    1. Add long pose-to-video generation.
    2. Colab demo release!
  3. v0.0.22023-06-01 · 2023-06-01 12:59 UTC
    查看更新说明

    Add control video processing.

  4. v0.0.12023-06-01 · 2023-06-01 08:00 UTC
    查看更新说明

    Basic setup and inference scripts.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Gen-L-Video: Long Video Generation via Temporal Co-Denoising

    This repository is the official implementation of Gen-L-Video.

    Project Website arXiv Open In Colab

    You might be interested in Gen-L^2, which works better.

    Introduction

    TL;DR: A universal methodology that extends short video diffusion models for efficient multi-text conditioned long video generation and editing.

    Current methodologies for video generation and editing, while innovative, are often confined to extremely short videos (typically less than 24 frames) and are limited to a single text condition. These constraints significantly limit their applications given that real-world videos usually consist of multiple segments, each bearing different semantic information. To address this challenge, we introduce a novel paradigm dubbed as Gen-L-Video capable of extending off-the-shelf short video diffusion models for generating and editing videos comprising hundreds of frames with diverse semantic segments without introducing additional training, all while preserving content consistency.

    Setup

    Clone the Repo
    git clone https://github.com/G-U-N/Gen-L-Video
    cd Gen-L-Video
    # The repo might be too large to clone because many long gifs are over 100 M. Fork the repo, delete the statics, and then clone it. 
    
    Install Environment via Anaconda
    conda env create -f requirements.yml
    conda activate glv
    conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
    

    Install Xformers

    # (Optional) Makes the build much faster
    pip install ninja
    # Set TORCH_CUDA_ARCH_LIST if running and building on different GPU types
    pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers
    # (this can take dozens of minutes)
    

    Install SAM and Grounding DINO

    pip install git+https://github.com/facebookresearch/segment-anything.git
    pip install git+https://github.com/IDEA-Research/GroundingDINO.git
    

    or

    git clone https://github.com/facebookresearch/segment-anything.git
    cd segment-anything
    pip install -e .
    cd ..
    # If you have a CUDA environment, please make sure the environment variable CUDA_HOME is set. 
    # If the cuda version of the system conflicts with the cudatoolkit version, See: https://github.com/G-U-N/Gen-L-Video/discussions/7
    git clone https://github.com/IDEA-Research/GroundingDINO.git
    cd GroundingDINO
    pip install -e .
    

    Note that if you are using GPU clusters that the management node has no access to GPU resources, you should submit the pip install -e . to the computing node as a computing task when building the GroundingDINO. Otherwise, it will not support detection computing through GPU.

    Download Pretrained Weights

    Make sure git-lfs is available. See: https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md

    bash scripts/download_pretrained_models.sh
    

    After downloading them, you should specify the absolute/relative path of them in the config files.

    If you download all the above pretrained weights in the folder weights , set the configs files as follows:

    1. In configs/tuning-free-inpaint/girl-glass.yaml
    sam_checkpoint: "weights/sam_vit_h_4b8939.pth"
    groundingdino_checkpoint: "weights/groundingdino_swinb_cogcoor.pth"
    controlnet_path: "weights/edit-anything-v0-3"
    
    1. In one-shot-tuning.py, set
    adapter_paths={
        "pose":"weights/T2I-Adapter/models/t2iadapter_openpose_sd14v1.pth",
        "sketch":"weights/T2I-Adapter/models/t2iadapter_sketch_sd14v1.pth",
        "seg": "weights/T2I-Adapter/models/t2iadapter_seg_sd14v1.pth",
        "depth":"weights/T2I-Adapter/models/t2iadapter_depth_sd14v1.pth",
        "canny":"weights/T2I-Adapter/models/t2iadapter_canny_sd14v1.pth"
    }
    
    1. In configs/one-shot-tuning/hike.yaml, set
    pretrained_model_path: "weights/anything-v4.0"
    

    Then all the other weights are able to be automatically downloaded through the API of Hugging Face.

    For users who are unable to download weights automatically

    Here is an additional instruction for installing and running grounding dino.

    # Notice: If you use 'pip install git+https://github.com/IDEA-Research/GroundingDINO.git'
    # You should modify GroundingDINO_SwinB_cfg.py in python site-packages directory
    # e.g. ~/miniconda3/envs/glv/lib/python3.8/site-packages/groundingdino/config/GroundingDINO_SwinB_cfg.py
    cd GroundingDINO/groundingdino/config/ 
    vim GroundingDINO_SwinB_cfg.py
    

    set

    text_encoder_type = "[Your Path]/bert-base-uncased"
    

    Then

    vim GroundingDINO/groundingdino/util/get_tokenlizer.py
    

    Set

    def get_pretrained_language_model(text_encoder_type):
        if text_encoder_type == "bert-base-uncased" or text_encoder_type.split("/")[-1]=="bert-base-uncased":
            return BertModel.from_pretrained(text_encoder_type)
        if text_encoder_type == "roberta-base":
            return RobertaModel.from_pretrained(text_encoder_type)
        raise ValueError("Unknown text_encoder_type {}".format(text_encoder_type))
    

    Now you should be able to run your Grounding DINO with pre-downloaded bert weights.

    Get your own control videos
    git clone https://github.com/lllyasviel/ControlNet.git
    cd ControlNet
    git checkout f4748e3
    mv ../process_data.py .
    python process_data.py --v_path=../data --t_path=../t_data --c_path=../c_data --fps=10
    

    Inference

    1. One-Shot Tuning Method
    accelerate launch one-shot-tuning.py --control=[your control]
    

    [your control] can be set as pose , depth, seg, sketch, canny.

    pose and depth are recommended.

    1. Tuning-Free Method for videos with smooth semantic changes.
    accelerate launch tuning-free-mix.py
    
    1. Tuning-Free Edit Anything in Videos.
    accelerate launch tuning-free-inpaint.py
    
    1. Long video generation with pretrained.
    accelerate launch follow-your-pose-long.py
    
    1. Tuning-Free Long Video2Video generation
    # canny 
    accelerate launch tuning-free-control.py --config=./configs/tuning-free-control/girl-glass.yaml 
    # hed
    accelerate launch tuning-free-control.py --config=./configs/tuning-free-control/girl.yaml
    

    Comparisons

    Results

    Most of the results can be generated with a single RTX 3090.

    Multi-Text Conditioned Long Video Generation

    https://github.com/G-U-N/Gen-L-Video/assets/60997859/9b370894-708a-4ed2-a2ac-abfa93829ea6

    This video containing clips bearing various semantic information.

    Long Video with Smooth Semantic Changes

    All the following videos are directly generated with the pretrained Stable Diffusion weight without additional training.

    Edit Anything in Video

    All the following videos are directly generated with the pretrained Stable Diffusion weight without additional training.

    Controllable Video
    Tuning-Free Long Video-to-Video Generation
    Long Video Generation with Pretrained Short Text-to-Video Diffusion Model

    All the following videos are directly generated with the pre-trained VideoCrafter without additional training.

    Additional Results

    Acknowledgments

    Citation

    If you use any content of this repo for your work, please cite the following bib entry:

    @article{wang2023gen,
      title={Gen-L-Video: Multi-Text to Long Video Generation via Temporal Co-Denoising},
      author={Wang, Fu-Yun and Chen, Wenshuo and Song, Guanglu and Ye, Han-Jia and Liu, Yu and Li, Hongsheng},
      journal={arXiv preprint arXiv:2305.18264},
      year={2023}
    }