今2023年2月,之前开发stable diffusion最初版本的Runway提出了首个AI编辑模型Gen-1,Gen-1可以在原视频的基础上,编辑出咱们想要的视频。无论是粗糙的3D动画,还是用手机拍出来的摇摇晃晃的视频,Gen-1都可以升级出一个不可思议的效果(当然,其背后原因是Gen1 trained jointly on images and videos)
如下图所示,我们可以基于潜在视频扩散模型(latent video diffusion models),通过给定下图中间部分的原始输入图像,然后既可以通过如下图上面部分的文字引导生成视频,也可以通过如下图下面部分的图像引导生成视频
怎么做到的呢?
首先,视频之所以可以通过文字引导生成,离不开文字引导图像生成的那一系列前置工作(Text-conditioned models, such as DALL-E2 and Stable Diffusion,enable novice users to generate detailed imagery given only a text prompt as input)。毕竟潜在扩散模型提供了在感知压缩空间高校合成图像的方法
其次,通过引入带有时间线的预训练图像模型(temporal layers into a pre-trained image model ),且在图像和视频上做联合训练「即在一个大规模的无字幕视频,和配对的文本图像的数据集上进行训练( trained on a large-scale dataset of uncaptioned videos and paired text-image data)」,从而将潜在扩散模型扩展到视频生成
且Gen1提出了一个可控的结构和内容感知的视频扩散模型(We propose a controllable structure and content-aware video diffusion model),且在推理阶段可以修改由示例图像或文本引导的视频(Editing is performed entirely at inference time without
additional per-video training or pre-processing)
且选择用单眼深度估计的技术来表示结构(单眼深度估计是一种计算机视觉技术,它旨在从仅使用单个摄像机拍摄的二维图像中推断出场景的三维深度信息 ),且由预先训练的神经网络预测嵌入表示内容(We opt to represent structure with monocular depth estimates and content with embeddings predicted by a pre-trained neural network)
然后在视频生成的过程中提供了几种控制模式
首先,类似于image synthesis models,训练我们的模型,使得其可以推断视频的内容,例如他们的外观或风格,及匹配用户提供的图像或文本提示
第二,受到扩散过程的启发,我们将information obscuring process应用到structure representation,以选择模型对给定结构的坚持程度(we apply an information obscuring process to the structure representation to enable selecting of how strongly the model adheres to the given structure)
最后,我们还对推理过程进行了调整,通过自定义指导方法,以及受classifier-free guidance的启发,以控制生成的剪辑的时间一致性(to enable control over temporal consistency in generated clips),相当于做到了时间、内容、结构三者在一致上的统一对齐
为了实现这一目标,我们需要学习视频的生成模型,基于结构表示、内容表示,从而通过输入的视频推断出其结构表示,然后根据编辑视频的描述文本进行修改(modify it based on a text prompt cdescribing the edit),如下图所示
在上图左侧的训练过程中,输入的视频x用一个固定的编码器E编码到,并扩散到
另一边,通过对"使用MiDaS获得的depth maps"进行编码,来提取一个结构表示,并通过使用CLIP对其中一个帧进行编码,来提取内容表示 (We extract a structure representation s by encoding depth maps obtained with MiDaS, and a content representation c by encoding one of the frames with CLIP.)
然后,在、、以及通过交叉注意块提供的的帮助下,模型学习在潜在空间中逆转扩散过程
引入时间层来扩展图像架构,且这些时间层仅对视频输入有效,另自动编码器保持固定并独立处理视频中的每一帧 we extend an image architecture by introducing temporal layers, which are only active for video inputs. All other layers are shared between the image and video model. The autoencoder remains fixed and processes each frame in a video independently.
UNet主要由两个模块组成:残差块和transformer块,通过添加跨时间的一维卷积和跨时间的一维自注意力将它们扩展到视频(we extend them to videos by adding both 1D convolutions across time and 1D self-attentions across time )
在每个残差块中,如上图左侧所示,在每个2D卷积之后引入一个时间卷积(In each residual block, we introduce one temporal convolution after each 2D convolution)
同样的,如上图右侧所示,在每个2D transformer块后,我们都包含一个temporal 1D transformer block, which mimics its spatial counterpart along the time axis,且将learnable positional encodings of the frame index输入到temporal transformer blocks中
最终实现时,将图像视为只有单帧的视频,以统一处理这两种情况
批量大小为b、帧数为n、通道数为c、空间分辨率为w ✖️ h,即形状为b × n × c × h × w的分批张量,被重新排列为w × h (i.e. shape b × n × c × h × w) is rearranged to (b · n) × c × h × w for spatial layers, to (b · h · w) × c × n for temporal convolutions, and to (b · h · w) × n × c for temporal self-attention
//待更
1.1.2.3 结构与内容的表示(Representing Content and Structure)
总之,我们的目标是根据用户提供的编辑视频的文本提示来编辑视频,但还是面临一个问题:即我们没有视频三元组的训练数据、编辑prompt、和生成的输出,也没有成对的视频和文本字幕(Thus, while our goal is to edit an input video based on a text prompt describing the desired edited video, we have neither training data of triplets with a video, its edit prompt and the resulting output, nor even pairs of videos and text captions)
因此,我们必须从训练视频本身导出结构和内容的表示,即、,从而损失函数为
相反,在推理过程中,结构和内容分别来自输入视频和文本提示, edited version x of y通过对以、为条件的生成模型进行采样获得的
其次,为了有效地处理各种各样的任务,引入了学习任务嵌入(learned task embeddings)的概念,用于引导生成过程朝着正确的生成任务方向发展
Second, to process this wide array of tasks effectively,we introduce the concept of learned task embeddings,which are used to steer the generation process toward the correct generative task.
具体来说,对于每个任务,都学习一个独特的任务嵌入向量,并通过交叉注意力交互将其集成到模型中,并将其添加到时间步嵌入中 (we learn a unique task embedding vector, and integrate it into the model through cross-attention interactions, and by adding it to the timestep embeddings )
在训练期间,给定我们数据集中的一个样本,我们使用任务索引,从嵌入表中获取任务的嵌入向量,并与模型权重联合优化它(we use the task index, i, to fetch the task's embedding vector, vi, froman embedding table, and optimize it jointly with the modelweights)
具体而言,我们通过交叉注意交互将任务嵌入到U-Net中,并将其添加到时间步长嵌入中(We do so by introducing the task embedding vias an additional condition to the U-Net, ϵθ. Concretely,we integrate the task embedding into the U-Net via cross-attention interactions, and by adding it to the timestep em-beddings)
优化问题更新为
其中是我们数据集中的任务总数,是来自数据集中的输入图像、输入指令文本、目标图像和任务索引的四元组
// 待更
2.2 Emu Video:先生成图像,再通过图像和文本生成视频
2.2.1 EMU VIDEO:Factorizing Text-to-Video Generation by Explicit Image Conditioning
那用什么样的文本到图像模型来做初始化呢?我们将文本到图像的U-Net架构用于我们的模型,并使用预训练的T2l模型初始化所有空间参数。该模型同时使用冻结的T5-XL和冻结的CLIP文本编码器从文本提示符中提取特征。U-Net中单独的cross-attention层负责每个文本特征。在初始化之后,模型包含2.7B被冻结的空间参数,以及1.7B被学习的时间参数 The model uses both a frozen T5-XL [15]and a frozen CLIP [58] text encoder to extract features fromthe text prompt. Separate cross-attention layers in the U-Net attend to each of the text features. After initialization,our model contains 2.7B spatial parameters which are kept frozen, and 1.7B temporal parameters that are learned
由于视频 - 文本数据集比图像 - 文本数据集要小得多,研究者还使用权重冻结的预训练文本 - 图像(T2I)模型初始化了他们的文本 - 视频模型
且他们确定了关键的设计决策 ------ 改变扩散噪声调度和多阶段训练(adjusted noiseschedules for diffusion, and multi-stage training ) ------ 该方法支持直接生成 512px 的高分辨率视频,不需要先前方法中使用的一些深度级联模型(without requiring a deep cascade of models as inprior work)
再说一下更多细节
我们用预训练的文本到图像模型初始化F,以确保它能够在初始化时生成图像
由于是从预训练的T2I模型初始化并保持冻结状态的,因此我们的模型保留了从大型图像-文本数据集中学习到的概念和风格多样性,并使用它来生成i。这不需要额外的训练成本,而不像Imagen video 那样对图像和视频数据进行联合微调以保持这种风格 Since the spatial layers are initialized from a pretrained T2I model and kept frozen, our model retains the conceptual and stylistic diversity learned from large image-text datasets, and uses it to generate I. This comes at no additional training cost unlike approaches [Imagen video] that do joint finetuning on image and video data to maintain such style
当然,许多直接的T2V方法[比如Align your latents: High-resolution video synthesis with latent diffusion models,再比如Make-a-video: Text-to-video generation without text-video data]也从预训练的T2I模型初始化,并保持空间层冻结。然而,它们没有采用我们基于图像的因子分解,因此不能保留T2I模型的质量和多样性 Many direct T2V ap-proaches [7, 68] also initialize from a pretrained T2I modeland keep the spatial layers frozen. However, they do notemploy our image-based factorization and thus do not re-tain the quality and diversity in the T2I model
由于使用潜在扩散模型,所以首先使用按帧应用的图像自动编码器将视频V转换为潜在空间X∈R T ×C×H×W,这降低了空间维度
再之后,利用自动编码器的解码器,可以将潜空间转换回像素空间(The latent space can be converted back to the pixel spaceusing the autoencoder's decode)
视频的T帧被独立去噪,以产生去噪输入Xt,扩散模型被训练去噪(The T frames of the videoare noised independently to produce the noised input Xt,which the diffusion model is trained to denoise)
预训练的T2I模型已经是文本条件,结合上面描述的图像条件,F同时是文本和图像条件 The pretrained T2I model is already text conditioned and combined with the image conditioning described above,Fis conditioned on both text and image
最终如此操作带来的好处是
与直接用文本生成视频的方法不同,他们的分解方法在推理时会显式地生成一张图像,这使得他们能够轻松保留文生图模型的视觉多样性、风格和质量,如下图所示
这使得 EMU VIDEO 即使在训练数据、计算量和可训练参数相同的情况下,也能超越直接 T2V 方法
且比如通过多阶段的训练方法,文生视频的生成质量可以得到大幅提高
2.2.2 如何延长生成视频的时长
从展示的 demo 中可以看到,EMU VIDEO 已经可以支持 4 秒的视频生成。在论文中,他们还探讨了增加视频时长的方法
作者表示,通过一个小的架构修改,他们可以在 T 帧上约束模型并扩展视频。因此,他们训练 EMU VIDEO 的一个变体,以「过去」16 帧为条件生成未来 16 帧。在扩展视频时,他们使用与原始视频不同的未来文本提示,效果如图 7 所示。他们发现,扩展视频既遵循原始视频,也遵循未来文本提示。