aigc-apps / CogVideoX-Fun

๐Ÿ“น A more flexible CogVideoX that can generate videos at any resolution and creates videos from images.
Apache License 2.0
292 stars 18 forks source link

CogVideoX-Fun

๐Ÿ˜Š Welcome!

Hugging Face Spaces

English | ็ฎ€ไฝ“ไธญๆ–‡

Table of Contents

Introduction

CogVideoX-Fun is a modified pipeline based on the CogVideoX structure, designed to provide more flexibility in generation. It can be used to create AI images and videos, as well as to train baseline models and Lora models for Diffusion Transformer. We support predictions directly from the already trained CogVideoX-Fun model, allowing the generation of videos at different resolutions, approximately 6 seconds long with 8 fps (1 to 49 frames). Users can also train their own baseline models and Lora models to achieve certain style transformations.

We will support quick pull-ups from different platforms, refer to Quick Start.

What's New:

Function๏ผš

Our UI interface is as follows: ui

Quick Start

1. Cloud usage: AliyunDSW/Docker

a. From AliyunDSW

DSW has free GPU time, which can be applied once by a user and is valid for 3 months after applying.

Aliyun provide free GPU time in Freetier, get it and use in Aliyun PAI-DSW to start CogVideoX-Fun within 5min!

DSW Notebook

b. From ComfyUI

Our ComfyUI is as follows, please refer to ComfyUI README for details. workflow graph

c. From docker

If you are using docker, please make sure that the graphics card driver and CUDA environment have been installed correctly in your machine.

Then execute the following commands in this way:

# pull image
docker pull mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:cogvideox_fun

# enter image
docker run -it -p 7860:7860 --network host --gpus all --security-opt seccomp:unconfined --shm-size 200g mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:cogvideox_fun

# clone code
git clone https://github.com/aigc-apps/CogVideoX-Fun.git

# enter CogVideoX-Fun's dir
cd CogVideoX-Fun

# download weights
mkdir models/Diffusion_Transformer
mkdir models/Personalized_Model

wget https://pai-aigc-photog.oss-cn-hangzhou.aliyuncs.com/cogvideox_fun/Diffusion_Transformer/CogVideoX-Fun-V1.1-2b-InP.tar.gz -O models/Diffusion_Transformer/CogVideoX-Fun-V1.1-2b-InP.tar.gz

cd models/Diffusion_Transformer/
tar -xvf CogVideoX-Fun-V1.1-2b-InP.tar.gz
cd ../../

2. Local install: Environment Check/Downloading/Installation

a. Environment Check

We have verified CogVideoX-Fun execution on the following environment:

The detailed of Windows:

The detailed of Linux:

We need about 60GB available on disk (for saving weights), please check!

b. Weights

We'd better place the weights along the specified path:

๐Ÿ“ฆ models/
โ”œโ”€โ”€ ๐Ÿ“‚ Diffusion_Transformer/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ CogVideoX-Fun-V1.1-2b-InP/
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ CogVideoX-Fun-V1.1-5b-InP/
โ”œโ”€โ”€ ๐Ÿ“‚ Personalized_Model/
โ”‚   โ””โ”€โ”€ your trained trainformer model / your trained lora model (for UI load)

Video Result

The results displayed are all based on image.

CogVideoX-Fun-V1.1-5B

Resolution-1024

Resolution-768

Resolution-512

CogVideoX-Fun-V1.1-5B-Pose

Resolution-512 Resolution-768 Resolution-1024

CogVideoX-Fun-V1.1-2B

Resolution-768

CogVideoX-Fun-V1.1-2B-Pose

Resolution-512 Resolution-768 Resolution-1024

How to use

1. Inference

a. Using Python Code

b. Using webui

c. From ComfyUI

Please refer to ComfyUI README for details.

2. Model Training

A complete CogVideoX-Fun training pipeline should include data preprocessing, and Video DiT training.

a. data preprocessing

We have provided a simple demo of training the Lora model through image data, which can be found in the wiki for details.

A complete data preprocessing link for long video segmentation, cleaning, and description can refer to README in the video captions section.

If you want to train a text to image and video generation model. You need to arrange the dataset in this format.

๐Ÿ“ฆ project/
โ”œโ”€โ”€ ๐Ÿ“‚ datasets/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ internal_datasets/
โ”‚       โ”œโ”€โ”€ ๐Ÿ“‚ train/
โ”‚       โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ 00000001.mp4
โ”‚       โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ 00000002.jpg
โ”‚       โ”‚   โ””โ”€โ”€ ๐Ÿ“„ .....
โ”‚       โ””โ”€โ”€ ๐Ÿ“„ json_of_internal_datasets.json

The json_of_internal_datasets.json is a standard JSON file. The file_path in the json can to be set as relative path, as shown in below:

[
    {
      "file_path": "train/00000001.mp4",
      "text": "A group of young men in suits and sunglasses are walking down a city street.",
      "type": "video"
    },
    {
      "file_path": "train/00000002.jpg",
      "text": "A group of young men in suits and sunglasses are walking down a city street.",
      "type": "image"
    },
    .....
]

You can also set the path as absolute path as follow:

[
    {
      "file_path": "/mnt/data/videos/00000001.mp4",
      "text": "A group of young men in suits and sunglasses are walking down a city street.",
      "type": "video"
    },
    {
      "file_path": "/mnt/data/train/00000001.jpg",
      "text": "A group of young men in suits and sunglasses are walking down a city street.",
      "type": "image"
    },
    .....
]

b. Video DiT training

If the data format is relative path during data preprocessing, please set scripts/train.sh as follow.

export DATASET_NAME="datasets/internal_datasets/"
export DATASET_META_NAME="datasets/internal_datasets/json_of_internal_datasets.json"

If the data format is absolute path during data preprocessing, please set scripts/train.sh as follow.

export DATASET_NAME=""
export DATASET_META_NAME="/mnt/data/json_of_internal_datasets.json"

Then, we run scripts/train.sh.

sh scripts/train.sh

For details on setting some parameters, please refer to Readme Train, Readme Lora and Readme Control.

Model zoo

V1.1:

ๅ็งฐ ๅญ˜ๅ‚จ็ฉบ้—ด Hugging Face Model Scope ๆ่ฟฐ
CogVideoX-Fun-V1.1-2b-InP.tar.gz Before extraction:9.7 GB \/ After extraction: 13.0 GB ๐Ÿค—Link ๐Ÿ˜„Link Our official graph-generated video model is capable of predicting videos at multiple resolutions (512, 768, 1024, 1280) and has been trained on 49 frames at a rate of 8 frames per second. Noise has been added to the reference image, and the amplitude of motion is greater compared to V1.0.
CogVideoX-Fun-V1.1-5b-InP.tar.gz Before extraction:16.0 GB \/ After extraction: 20.0 GB ๐Ÿค—Link ๐Ÿ˜„Link Our official graph-generated video model is capable of predicting videos at multiple resolutions (512, 768, 1024, 1280) and has been trained on 49 frames at a rate of 8 frames per second. Noise has been added to the reference image, and the amplitude of motion is greater compared to V1.0.
CogVideoX-Fun-V1.1-2b-Pose.tar.gz Before extraction:9.7 GB \/ After extraction: 13.0 GB ๐Ÿค—Link ๐Ÿ˜„Link Our official pose-control video model is capable of predicting videos at multiple resolutions (512, 768, 1024, 1280) and has been trained on 49 frames at a rate of 8 frames per second.
CogVideoX-Fun-V1.1-5b-Pose.tar.gz Before extraction:16.0 GB \/ After extraction: 20.0 GB ๐Ÿค—Link ๐Ÿ˜„Link Our official pose-control video model is capable of predicting videos at multiple resolutions (512, 768, 1024, 1280) and has been trained on 49 frames at a rate of 8 frames per second.

V1.0:

Name Storage Space Hugging Face Model Scope Description
CogVideoX-Fun-2b-InP.tar.gz Before extraction:9.7 GB \/ After extraction: 13.0 GB ๐Ÿค—Link ๐Ÿ˜„Link Our official graph-generated video model is capable of predicting videos at multiple resolutions (512, 768, 1024, 1280) and has been trained on 49 frames at a rate of 8 frames per second.
CogVideoX-Fun-5b-InP.tar.gz Before extraction:16.0 GB \/ After extraction: 20.0 GB ๐Ÿค—Link ๐Ÿ˜„Link Our official graph-generated video model is capable of predicting videos at multiple resolutions (512, 768, 1024, 1280) and has been trained on 49 frames at a rate of 8 frames per second.

TODO List

Reference

License

This project is licensed under the Apache License (Version 2.0).

The CogVideoX-2B model (including its corresponding Transformers module and VAE module) is released under the Apache 2.0 License.

The CogVideoX-5B model (Transformers module) is released under the CogVideoX LICENSE.