README.md 4.41 KB
Newer Older
dcuai's avatar
dcuai committed
1
# I2VGen-XL
mashun1's avatar
mashun1 committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

## 论文

**I2VGen-XL: High-Quality Image-to-Video Synthesis via Cascaded Diffusion Models**

* https://arxiv.org/abs/2311.04145

## 模型结构
该模型为两阶段的视频生成模型,其主要结构都为`3D-Unet`,其中第一阶段模型为低质量视频生成模型,其中包括提取图像高阶信息(如语义特征)的`CLIP`,图片压缩用到的`D.Enc.``VQGAN`中的`Encoder`)以及提取低阶特征(如细节特征)的`G.Enc.`;第二阶段模型用于生成高质量视频,以文本作为条件,第一阶段的输出进行Resize后作为LDM的输入并执行加噪去噪过程,最终得到高清视频。

![Alt text](readme_imgs/image-1.png)

## 算法原理

该算法使用了级联的方式进行视频生成,将其分为了两个过程,一个用于保证视频语义的连贯性,一个用于增强视频的细节并提高分辨率。

![alt text](readme_imgs/image-2.png)

## 环境配置

### Docker(方法一)

dcuai's avatar
dcuai committed
24
    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
mashun1's avatar
mashun1 committed
25
26
27
28
29
30

    docker run --shm-size 10g --network=host --name=vgen --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

    pip install -r requirements.txt

    # 以下按需安装
mashun1's avatar
mashun1 committed
31
    sudo apt install ffmpeg
mashun1's avatar
mashun1 committed
32

mashun1's avatar
mashun1 committed
33
### Dockerfile(方法二)
mashun1's avatar
mashun1 committed
34
35
36
37
38
39
40
41
42

    # 需要在对应的目录下
    docker build -t <IMAGE_NAME>:<TAG> .

    docker run --shm-size 10g --network=host --name=vgen --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

    pip install -r requirements.txt

    # 以下按需安装
mashun1's avatar
mashun1 committed
43
    sudo apt install ffmpeg
mashun1's avatar
mashun1 committed
44
45
46

### Anaconda (方法三)
1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装:
chenzk's avatar
chenzk committed
47
https://developer.sourcefind.cn/tool/
mashun1's avatar
mashun1 committed
48

mashun1's avatar
mashun1 committed
49
50
    DTK驱动:dtk24.04.1
    python:python3.10
mashun1's avatar
mashun1 committed
51
52
53
    torch:2.1.0
    torchvision:0.16.0
    triton:2.1.0
mashun1's avatar
mashun1 committed
54
55
    xformers:0.0.25
    flash-attn:2.0.4
mashun1's avatar
mashun1 committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应

2、其它非特殊库参照requirements.txt安装

    pip install -r requirements.txt

    # 按需安装

    conda install -c conda-forge ffmpeg


## 数据集

作者未公开训练数据集,常用的数据集目前无法下载。

## 推理

### 命令行

mashun1's avatar
mashun1 committed
76
    HIP_VISIBLE_DEVICES=1 python inference.py --cfg configs/i2vgen_xl_infer.yaml
mashun1's avatar
mashun1 committed
77

mashun1's avatar
mashun1 committed
78
    # 指定输入和模型
mashun1's avatar
mashun1 committed
79
    HIP_VISIBLE_DEVICES=1 python inference.py --cfg configs/i2vgen_xl_infer.yaml  test_list_path data/test_list_for_i2vgen.txt test_model i2vgen-xl/i2vgen_xl_00854500.pth
mashun1's avatar
mashun1 committed
80
81
82
83
84
85

test_list_path 表示输入图像路径及其对应的标题请参考演示文件 data/test_list_for_i2vgen.txt 中的特定格式和建议。test_model 是加载模型的路径。


### gradio页面

mashun1's avatar
mashun1 committed
86
    HIP_VISIBLE_DEVICES=1 python gradio_app.py
mashun1's avatar
mashun1 committed
87
88

![alt text](readme_imgs/image-3.png)
mashun1's avatar
mashun1 committed
89
90

注意:第一次执行该命令前需要创建 `workspace/experiments/test_list_for_i2vgen` 文件夹用来保存生成结果,且执行该命令会下载默认文件,当默认文件下载完毕后(程序会报错)需手动注释/删除 `~/.cache/modelscope/hub/damo/i2vgen-xl/ms_wrapper.py`中的代码,同时需要将`tools/modules/unet/util.py`复制到`~/.cache/modelscope/hub/damo/i2vgen-xl/tools/modules/unet/`中,可执行`cp tools/modules/unet/util.py ~/.cache/modelscope/hub/damo/i2vgen-xl/tools/modules/unet/`
mashun1's avatar
mashun1 committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
        
## result

||输入|输出|
|:---|:---|:---|
|图像|![alt text](readme_imgs/img_0001.jpg)|![alt text](readme_imgs/r.gif)|
|prompt|A green frog floats on the surface of the water on green lotus leaves, with several pink lotus flowers, in a Chinese painting style.||

### 精度



## 应用场景

### 算法类别

mashun1's avatar
update  
mashun1 committed
107
`AIGC`
mashun1's avatar
mashun1 committed
108
109
110
111
112

### 热点应用行业

`媒体,科研,教育`

mashun1's avatar
update  
mashun1 committed
113
114
## 预训练权重

chenzk's avatar
chenzk committed
115
[huggingface](https://huggingface.co/ali-vilab/i2vgen-xl/tree/main)
mashun1's avatar
update  
mashun1 committed
116
117
118
119
120
121
122

    i2vgen-xl/
    ├── i2vgen_xl_00854500.pth
    ├── open_clip_pytorch_model.bin
    ├── stable_diffusion_image_key_temporal_attention_x1.json
    └── v2-1_512-ema-pruned.ckpt

mashun1's avatar
mashun1 committed
123
124
## 源码仓库及问题反馈

chenzk's avatar
chenzk committed
125
* https://developer.sourcefind.cn/codes/modelzoo/i2vgen-xl_pytorch
mashun1's avatar
mashun1 committed
126
127
128
129

## 参考资料

* https://github.com/ali-vilab/VGen