AIGC专栏10——EasyAnimate 一个新的类SORA文生视频模型 轻松文生视频

2024-04-14 08:36

本文主要是介绍AIGC专栏10——EasyAnimate 一个新的类SORA文生视频模型 轻松文生视频,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

AIGC专栏10——EasyAnimate 一个新的类SORA文生视频模型 📺轻松文生视频

  • 学习前言
  • 源码下载地址
  • 技术原理储备(DIT/Lora/Motion Module)
    • 什么是Diffusion Transformer (DiT)
    • Lora
    • Motion Module
  • EasyAnimate简介
  • EasyAnimate原理界面展示
  • 快速启动
    • 云使用: AliyunDSW/Docker
    • 本地安装: 环境检查/下载/安装
  • 如何使用
    • 生成
      • 运行python文件
      • 通过ui界面
    • 模型训练
      • 训练视频生成模型
        • i、基于webvid数据集
        • ii、基于自建数据集
      • 训练基础文生图模型
        • i、基于diffusers格式
        • ii、基于自建数据集
      • 训练Lora模型
        • i、基于diffusers格式
        • ii、基于自建数据集
  • 算法细节

学习前言

在过年期间,OpenAI放出了SORA文生视频的预览效果,一瞬间各大媒体争相报道,又引爆了一次科技圈,可惜的是,SORA依然没选择开源。

在这个契机下,本来我也对文生视频的工作非常感兴趣,所以也研究了一些与SORA相关的技术,虽然我们没有像OpenAI那么大的算力,但做一些基础研究还是足够的。

最近我参与了一个EasyAnimate的项目,可以根据文本生成视频,并且借鉴了Animatediff的IDEA,将MotionModule网格化后引入到DIT中,借助DIT的强大生成能力,生成视频效果也还不错,并且由于基于一个可插入结构,EasyAnimate有良好的拓展性,近期也开源了出来。
在这里插入图片描述

源码下载地址

https://github.com/aigc-apps/EasyAnimate

感谢大家的关注。

技术原理储备(DIT/Lora/Motion Module)

什么是Diffusion Transformer (DiT)

DiT基于扩散模型,所以不免包含不断去噪的过程,如果是图生图的话,还有不断加噪的过程,此时离不开DDPM那张老图,如下:
在这里插入图片描述
DiT相比于DDPM,使用了更快的采样器,也使用了更大的分辨率,与Stable Diffusion一样使用了隐空间的扩散,但可能更偏研究性质一些,没有使用非常大的数据集进行预训练,只使用了imagenet进行预训练。

与Stable Diffusion不同的是,DiT的网络结构完全由Transformer组成,没有Unet中大量的上下采样,结构更为简单清晰。

在EasyAnimate中,我们将Motion Module网格化后引入到DIT中,借助DIT的强大生成能力,生成视频效果也还不错。

Lora

由《LoRA: Low-Rank Adaptation of Large Language Models》 提出的一种基于低秩矩阵的对大参数模型进行少量参数微调训练的方法,广泛引用在各种大模型的下游使用中。

由于我们是基于一个可插入的结构设计了EasyAnimate,所以EasyAnimate有良好的拓展性,我们可以对文生图模型训练Lora后应用到文生视频模型中。

Motion Module

AnimateDiff是一个可以对文生图模型进行动画处理的实用框架,其内部设计的Motion Module无需进行特定模型调整,即可一次性为大多数现有的个性化文本转图像模型提供动画化能力。

EasyAnimate参考AnimateDiff使用Motion Module保证动画的连续性,同时作为一个可插入的结构,Motion Module有良好的拓展性

EasyAnimate简介

EasyAnimate是一个基于transformer结构的pipeline,可用于生成AI动画、训练Diffusion Transformer的基线模型与Lora模型,我们支持从已经训练好的EasyAnimate模型直接进行预测,生成不同分辨率,6秒左右、fps12的视频(40 ~ 80帧, 未来会支持更长的视频),也支持用户训练自己的基线模型与Lora模型,进行一定的风格变换。

这些是pipeline的生成结果,从生成结果来看,它的生成效果还是非常不错的,Resolution 的顺序是width、height、frames:

首先是使用原始的pixart checkpoint进行预测。

Base ModelsSamplerSeedResolution (h x w x f)PromptGenerationResultDownload
PixArtDPM++43512x512x80A soaring drone footage captures the majestic beauty of a coastal cliff, its red and yellow stratified rock faces rich in color and against the vibrant turquoise of the sea. Seabirds can be seen taking flight around the cliff’s precipices.00000001Download GIF
PixArtDPM++43448x640x80The video captures the majestic beauty of a waterfall cascading down a cliff into a serene lake. The waterfall, with its powerful flow, is the central focus of the video. The surrounding landscape is lush and green, with trees and foliage adding to the natural beauty of the scene.00000001Download GIF
PixArtDPM++43704x384x80A vibrant scene of a snowy mountain landscape. The sky is filled with a multitude of colorful hot air balloons, each floating at different heights, creating a dynamic and lively atmosphere. The balloons are scattered across the sky, some closer to the viewer, others further away, adding depth to the scene.00000001Download GIF
PixArtDPM++43448x640x64The vibrant beauty of a sunflower field. The sunflowers, with their bright yellow petals and dark brown centers, are in full bloom, creating a stunning contrast against the green leaves and stems. The sunflowers are arranged in neat rows, creating a sense of order and symmetry.00000001Download GIF
PixArtDPM++43384x704x48A tranquil Vermont autumn, with leaves in vibrant colors of orange and red fluttering down a mountain stream.00000001Download GIF
PixArtDPM++43704x384x48A vibrant underwater scene. A group of blue fish, with yellow fins, are swimming around a coral reef. The coral reef is a mix of brown and green, providing a natural habitat for the fish. The water is a deep blue, indicating a depth of around 30 feet. The fish are swimming in a circular pattern around the coral reef, indicating a sense of motion and activity. The overall scene is a beautiful representation of marine life.00000001Download GIF
PixArtDPM++43576x448x48Pacific coast, carmel by the blue sea ocean and peaceful waves00000001Download GIF
PixArtDPM++43576x448x80A snowy forest landscape with a dirt road running through it. The road is flanked by trees covered in snow, and the ground is also covered in snow. The sun is shining, creating a bright and serene atmosphere. The road appears to be empty, and there are no people or animals visible in the video. The style of the video is a natural landscape shot, with a focus on the beauty of the snowy forest and the peacefulness of the road.00000001Download GIF
PixArtDPM++43640x448x64The dynamic movement of tall, wispy grasses swaying in the wind. The sky above is filled with clouds, creating a dramatic backdrop. The sunlight pierces through the clouds, casting a warm glow on the scene. The grasses are a mix of green and brown, indicating a change in seasons. The overall style of the video is naturalistic, capturing the beauty of the landscape in a realistic manner. The focus is on the grasses and their movement, with the sky serving as a secondary element. The video does not contain any human or animal elements.00000001Download GIF
PixArtDPM++43704x384x80A serene night scene in a forested area. The first frame shows a tranquil lake reflecting the star-filled sky above. The second frame reveals a beautiful sunset, casting a warm glow over the landscape. The third frame showcases the night sky, filled with stars and a vibrant Milky Way galaxy. The video is a time-lapse, capturing the transition from day to night, with the lake and forest serving as a constant backdrop. The style of the video is naturalistic, emphasizing the beauty of the night sky and the peacefulness of the forest.00000001Download GIF
PixArtDPM++43640x448x80Sunset over the sea.00000001Download GIF

使用人像checkpoint进行预测。

Base ModelsSamplerSeedResolution (h x w x f)PromptGenerationResultDownload
PortraitEuler A43448x576x801girl, 3d, black hair, brown eyes, earrings, grey background, jewelry, lips, long hair, looking at viewer, photo \(medium\), realistic, red lips, solo00000001Download GIF
PortraitEuler A43448x576x801girl, bare shoulders, blurry, brown eyes, dirty, dirty face, freckles, lips, long hair, looking at viewer, realistic, sleeveless, solo, upper body00000001Download GIF
PortraitEuler A43512x512x641girl, black hair, brown eyes, earrings, grey background, jewelry, lips, looking at viewer, mole, mole under eye, neck tattoo, nose, ponytail, realistic, shirt, simple background, solo, tattoo00000001Download GIF
PortraitEuler A43576x448x641girl, black hair, lips, looking at viewer, mole, mole under eye, mole under mouth, realistic, solo00000001Download GIF

使用人像Lora进行预测。

Base ModelsSamplerSeedResolution (h x w x f)PromptGenerationResultDownload
Pixart + LoraEuler A43512x512x641girl, 3d, black hair, brown eyes, earrings, grey background, jewelry, lips, long hair, looking at viewer, photo \(medium\), realistic, red lips, solo00000001Download GIF
Pixart + LoraEuler A43512x512x641girl, bare shoulders, blurry, brown eyes, dirty, dirty face, freckles, lips, long hair, looking at viewer, mole, mole on breast, mole on neck, mole under eye, mole under mouth, realistic, sleeveless, solo, upper body00000001Download GIF
Pixart + LoraEuler A43512x512x641girl, black hair, lips, looking at viewer, mole, mole under eye, mole under mouth, realistic, solo00000001Download GIF
Pixart + LoraEuler A43512x512x801girl, bare shoulders, blurry, blurry background, blurry foreground, bokeh, brown eyes, christmas tree, closed mouth, collarbone, depth of field, earrings, jewelry, lips, long hair, looking at viewer, photo \(medium\), realistic, smile, solo00000001Download GIF

可以看出,EasyAnimate具有良好的可拓展性,无论是训练Checkpoint还是Lora都可以应用到模型当中,另外,我们设计了分桶策略与自适应视频裁剪,模型既可以预测512x512的视频,也可以预测如384x768的视频。

EasyAnimate原理界面展示

参考Animatediff,我们为EasyAnimate也提供了对应的界面,在界面上,我们可以选择基础模型、motion module版本、基础checkpoint和lora模型。

在填入prompt和neg prompt后,就可以在下面点击generate进行生成了。
在这里插入图片描述

快速启动

云使用: AliyunDSW/Docker

a. 通过阿里云 DSW
我们暂时还没有快速启动资源,等配置完成后再做更新。

b. 通过docker
使用docker的情况下,请保证机器中已经正确安装显卡驱动与CUDA环境,然后以此执行以下命令:

# 拉取镜像
docker pull mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:easyanimate# 进入镜像
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:easyanimate# clone 代码
git clone https://github.com/aigc-apps/EasyAnimate.git# 进入EasyAnimate文件夹
cd EasyAnimate# 下载权重
mkdir models/Diffusion_Transformer
mkdir models/Motion_Module
mkdir models/Personalized_Modelwget https://pai-aigc-photog.oss-cn-hangzhou.aliyuncs.com/easyanimate/Motion_Module/easyanimate_v1_mm.safetensors -O models/Motion_Module/easyanimate_v1_mm.safetensors
wget https://pai-aigc-photog.oss-cn-hangzhou.aliyuncs.com/easyanimate/Personalized_Model/easyanimate_portrait.safetensors -O models/Personalized_Model/easyanimate_portrait.safetensors
wget https://pai-aigc-photog.oss-cn-hangzhou.aliyuncs.com/easyanimate/Personalized_Model/easyanimate_portrait_lora.safetensors -O models/Personalized_Model/easyanimate_portrait_lora.safetensors
wget https://pai-aigc-photog.oss-cn-hangzhou.aliyuncs.com/easyanimate/Diffusion_Transformer/PixArt-XL-2-512x512.tar -O models/Diffusion_Transformer/PixArt-XL-2-512x512.tarcd models/Diffusion_Transformer/
tar -xvf PixArt-XL-2-512x512.tar
cd ../../

本地安装: 环境检查/下载/安装

我们已验证EasyAnimate可在以下环境中执行:

Linux 的详细信息:

操作系统 Ubuntu 20.04, CentOS
python: python3.10 & python3.11
pytorch: torch2.2.0
CUDA: 11.8
CUDNN: 8+
GPU: Nvidia-A10 24G & Nvidia-A100 40G & Nvidia-A100 80G

我们需要大约 60GB 的可用磁盘空间,请检查!

b. 权重放置
我们最好将权重按照指定路径进行放置:

📦 models/
├── 📂 Diffusion_Transformer/
│   └── 📂 PixArt-XL-2-512x512/
├── 📂 Motion_Module/
│   └── 📄 easyanimate_v1_mm.safetensors
├── 📂 Motion_Module/
│   ├── 📄 easyanimate_portrait.safetensors
│   └── 📄 easyanimate_portrait_lora.safetensors

如何使用

生成

运行python文件

  • 步骤1:下载对应权重放入models文件夹。
  • 步骤2:在predict_t2v.py文件中修改prompt、neg_prompt、guidance_scale和seed。
  • 步骤3:运行predict_t2v.py文件,等待生成结果,结果保存在samples/easyanimate-videos文件夹中。
  • 步骤4:如果想结合自己训练的其他backbone与Lora,则看情况修改predict_t2v.py中的predict_t2v.py和lora_path。

通过ui界面

  • 步骤1:下载对应权重放入models文件夹。
  • 步骤2:运行app.py文件,进入gradio页面。
  • 步骤3:根据页面选择生成模型,填入prompt、neg_prompt、guidance_scale和seed等,点击生成,等待生成结果,结果保存在sample文件夹中。

模型训练

训练视频生成模型

i、基于webvid数据集

如果使用webvid数据集进行训练,则需要首先下载webvid的数据集。

您需要以这种格式排列webvid数据集。

📦 project/
├── 📂 datasets/
│   ├── 📂 webvid/
│       ├── 📂 videos/
│       │   ├── 📄 00000001.mp4
│       │   ├── 📄 00000002.mp4
│       │   └── 📄 .....
│       └── 📄 csv_of_webvid.csv

然后,进入scripts/train_t2v.sh进行设置。

export DATASET_NAME="datasets/webvid/videos/"
export DATASET_META_NAME="datasets/webvid/csv_of_webvid.csv"...train_data_format="webvid"

最后运行scripts/train_t2v.sh。

sh scripts/train_t2v.sh
ii、基于自建数据集

如果使用内部数据集进行训练,则需要首先格式化数据集。

您需要以这种格式排列数据集。

📦 project/
├── 📂 datasets/
│   ├── 📂 internal_datasets/
│       ├── 📂 videos/
│       │   ├── 📄 00000001.mp4
│       │   ├── 📄 00000002.mp4
│       │   └── 📄 .....
│       └── 📄 json_of_internal_datasets.json

json_of_internal_datasets.json是一个标准的json文件,如下所示:

[{"file_path": "videos/00000001.mp4","text": "A group of young men in suits and sunglasses are walking down a city street.","type": "video"},{"file_path": "videos/00000002.mp4","text": "A notepad with a drawing of a woman on it.","type": "video"}.....
]

json中的file_path需要设置为相对路径。

然后,进入scripts/train_t2v.sh进行设置。

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

最后运行scripts/train_t2v.sh。

sh scripts/train_t2v.sh

训练基础文生图模型

i、基于diffusers格式

数据集的格式可以设置为diffusers格式。

📦 project/
├── 📂 datasets/
│   ├── 📂 diffusers_datasets/
│       ├── 📂 train/
│       │   ├── 📄 00000001.jpg
│       │   ├── 📄 00000002.jpg
│       │   └── 📄 .....
│       └── 📄 metadata.jsonl

然后,进入scripts/train_t2i.sh进行设置。

export DATASET_NAME="datasets/diffusers_datasets/"...train_data_format="diffusers"

最后运行scripts/train_t2i.sh。

sh scripts/train_t2i.sh
ii、基于自建数据集

如果使用自建数据集进行训练,则需要首先格式化数据集。

您需要以这种格式排列数据集。

📦 project/
├── 📂 datasets/
│   ├── 📂 internal_datasets/
│       ├── 📂 train/
│       │   ├── 📄 00000001.jpg
│       │   ├── 📄 00000002.jpg
│       │   └── 📄 .....
│       └── 📄 json_of_internal_datasets.json

json_of_internal_datasets.json是一个标准的json文件,如下所示:

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

json中的file_path需要设置为相对路径。

然后,进入scripts/train_t2i.sh进行设置。

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

最后运行scripts/train_t2i.sh。

sh scripts/train_t2i.sh

训练Lora模型

i、基于diffusers格式

数据集的格式可以设置为diffusers格式。

📦 project/
├── 📂 datasets/
│   ├── 📂 diffusers_datasets/
│       ├── 📂 train/
│       │   ├── 📄 00000001.jpg
│       │   ├── 📄 00000002.jpg
│       │   └── 📄 .....
│       └── 📄 metadata.jsonl

然后,进入scripts/train_lora.sh进行设置。

export DATASET_NAME="datasets/diffusers_datasets/"...train_data_format="diffusers"

最后运行scripts/train_lora.sh。

sh scripts/train_lora.sh
ii、基于自建数据集

如果使用自建数据集进行训练,则需要首先格式化数据集。

您需要以这种格式排列数据集。

📦 project/
├── 📂 datasets/
│   ├── 📂 internal_datasets/
│       ├── 📂 train/
│       │   ├── 📄 00000001.jpg
│       │   ├── 📄 00000002.jpg
│       │   └── 📄 .....
│       └── 📄 json_of_internal_datasets.json

json_of_internal_datasets.json是一个标准的json文件,如下所示:

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

json中的file_path需要设置为相对路径。

然后,进入scripts/train_lora.sh进行设置。

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

最后运行scripts/train_lora.sh。

sh scripts/train_lora.sh

算法细节

我们使用了PixArt-alpha作为基础模型,并在此基础上引入额外的运动模块(motion module)来将DiT模型从2D图像生成扩展到3D视频生成上来。其框架图如下:
请添加图片描述
其中,Motion Module 用于捕捉时序维度的帧间关系,其结构如下:
请添加图片描述
我们在时序维度上引入注意力机制来让模型学习时序信息,以进行连续视频帧的生成。同时,我们利用额外的网格计算(Grid Reshape),来扩大注意力机制的input token数目,从而更多地利用图像的空间信息以达到更好的生成效果。Motion Module 作为一个单独的模块,在推理时可以用在不同的DiT基线模型上。此外,EasyAnimate不仅支持了motion-module模块的训练,也支持了DiT基模型/LoRA模型的训练,以方便用户根据自身需要来完成自定义风格的模型训练,进而生成任意风格的视频。

这篇关于AIGC专栏10——EasyAnimate 一个新的类SORA文生视频模型 轻松文生视频的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/902572

相关文章

一份LLM资源清单围观技术大佬的日常;手把手教你在美国搭建「百万卡」AI数据中心;为啥大模型做不好简单的数学计算? | ShowMeAI日报

👀日报&周刊合集 | 🎡ShowMeAI官网 | 🧡 点赞关注评论拜托啦! 1. 为啥大模型做不好简单的数学计算?从大模型高考数学成绩不及格说起 司南评测体系 OpenCompass 选取 7 个大模型 (6 个开源模型+ GPT-4o),组织参与了 2024 年高考「新课标I卷」的语文、数学、英语考试,然后由经验丰富的判卷老师评判得分。 结果如上图所

大语言模型(LLMs)能够进行推理和规划吗?

大语言模型(LLMs),基本上是经过强化训练的 n-gram 模型,它们在网络规模的语言语料库(实际上,可以说是我们文明的知识库)上进行了训练,展现出了一种超乎预期的语言行为,引发了我们的广泛关注。从训练和操作的角度来看,LLMs 可以被认为是一种巨大的、非真实的记忆库,相当于为我们所有人提供了一个外部的系统 1(见图 1)。然而,它们表面上的多功能性让许多研究者好奇,这些模型是否也能在通常需要系

人工和AI大语言模型成本对比 ai语音模型

这里既有AI,又有生活大道理,无数渺小的思考填满了一生。 上一专题搭建了一套GMM-HMM系统,来识别连续0123456789的英文语音。 但若不是仅针对数字,而是所有普通词汇,可能达到十几万个词,解码过程将非常复杂,识别结果组合太多,识别结果不会理想。因此只有声学模型是完全不够的,需要引入语言模型来约束识别结果。让“今天天气很好”的概率高于“今天天汽很好”的概率,得到声学模型概率高,又符合表达

智能客服到个人助理,国内AI大模型如何改变我们的生活?

引言 随着人工智能(AI)技术的高速发展,AI大模型越来越多地出现在我们的日常生活和工作中。国内的AI大模型在过去几年里取得了显著的进展,不少独创的技术点和实际应用令人瞩目。 那么,国内的AI大模型有哪些独创的技术点?它们在实际应用中又有哪些出色表现呢?此外,普通人又该如何利用这些大模型提升工作和生活的质量和效率呢?本文将为你一一解析。 一、国内AI大模型的独创技术点 多模态学习 多

OpenCompass:大模型测评工具

大模型相关目录 大模型,包括部署微调prompt/Agent应用开发、知识库增强、数据库增强、知识图谱增强、自然语言处理、多模态等大模型应用开发内容 从0起步,扬帆起航。 大模型应用向开发路径:AI代理工作流大模型应用开发实用开源项目汇总大模型问答项目问答性能评估方法大模型数据侧总结大模型token等基本概念及参数和内存的关系大模型应用开发-华为大模型生态规划从零开始的LLaMA-Factor

模型压缩综述

https://www.cnblogs.com/shixiangwan/p/9015010.html

百度OCR识别结构结构化处理视频

https://edu.csdn.net/course/detail/10506

AI赋能天气:微软研究院发布首个大规模大气基础模型Aurora

编者按:气候变化日益加剧,高温、洪水、干旱,频率和强度不断增加的全球极端天气给整个人类社会都带来了难以估计的影响。这给现有的天气预测模型提出了更高的要求——这些模型要更准确地预测极端天气变化,为政府、企业和公众提供更可靠的信息,以便做出及时的准备和响应。为了应对这一挑战,微软研究院开发了首个大规模大气基础模型 Aurora,其超高的预测准确率、效率及计算速度,实现了目前最先进天气预测系统性能的显著

PyTorch模型_trace实战:深入理解与应用

pytorch使用trace模型 1、使用trace生成torchscript模型2、使用trace的模型预测 1、使用trace生成torchscript模型 def save_trace(model, input, save_path):traced_script_model = torch.jit.trace(model, input)<

关于文章“python+百度语音识别+星火大模型+讯飞语音合成的语音助手”报错的修改

前言 关于我的文章:python+百度语音识别+星火大模型+讯飞语音合成的语音助手,运行不起来的问题 文章地址: https://blog.csdn.net/Phillip_xian/article/details/138195725?spm=1001.2014.3001.5501 1.报错问题 如果运行中报错,且报错位置在Xufi_Voice.py文件中的pcm_2_wav,如下图所示