Tune-A-Video:使用图像扩散模型进行一次微调实现文本到视频的生成

Paper : Wu J Z, Ge Y, Wang X, et al. Tune-a-video: One-shot tuning of image diffusion models for text-to-video generation[C]//Proceedings of the IEEE/CVF International Conference on Computer Vision. 2023: 7623-7633.
Introduction : https://tuneavideo.github.io/
Code : https://github.com/showlab/Tune-A-Video

目录

  • [一. 研究思路](#一. 研究思路)
  • [二. 复现](#二. 复现)
    • [1. man-skiing](#1. man-skiing)
    • [2. man-spraying-fire](#2. man-spraying-fire)

一. 研究思路

为了充分利用 T2I 预训练大模型的强大生成能力,T2V 出现了一个新的范式 ------ One-Shot Video Tuning:使用一对文本 - 视频来训练 T2V 生成器,T2V 生成器需要从输入视频中捕获基本的运动信息,然后合成带有编辑文本语义的新视频。然而,T2I 生成的图像虽然满足文本的语义,但是在空间布局和具体内容上还是有比较大的差异。即使扩展了空间 self-attention,帧间还是有明显的不连续。

为了进一步学习连续的运动,本文提出了 Tune-A-Video,在时空维度上 (spatio-temporal dimension) 扩展 T2I 模型。然而,直接使用微调策略来更新参数会破坏 T2I 的先验知识,阻碍视频的生成。

因此,Tune-A-Video 引入了一种稀疏时空注意机制 (sparse spatio-temporal attention mechanism),在视频编辑时只关注第一帧和前一帧;然后再对 T2I 模型进行微调,该过程中只更新 attention 块中的投影矩阵(即 Q、K、V);推理时通过 DDIM 反演保持输入视频的结构,以尽可能保证相邻帧间的运动连续性。

二. 复现

实验过程

  1. 克隆仓库后,创建虚拟环境 tune_a_video 并按照 README 安装依赖和下载权重,然后就可以开始训练;

  2. 训练开始前,需要根据模型和训练数据路径修改 configs 文件夹下的配置文件;

  3. 训练时遇到报错:RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by passing the keyword argument 'find_unused_parameters=True' to 'torch.nn.parallel.DistributedDataParallel', and by making sure all 'forward' function outputs participate in calculating loss. If you already have done the above, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's 'forward' function. Please include the loss function and the structure of the return value of 'forward' of your module when reporting this issue (e.g. list, dict, iterable). Parameter indices which did not receive grad for rank 0: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 In addition, you can set the environment variable TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print out information about which particular parameters did not receive gradient on this rank as part of this error.

    这是分布式数据并行引发的错误,最简单的办法就是只使用一个 GPU 进行训练 [1](#1)。具体的做法是,设置环境变量 CUDA_VISIBLE_DEVICE 指定可用的 GPU:export CUDA_VISIBLE_DEVICES=0

  4. 随后又会遇到新的问题:NotImplementedError: Using RTX 4000 series doesn't support faster communication broadband via P2P or IB. Please set 'NCCL_P2P_DISABLE="1"' and 'NCCL_IB_DISABLE="1" or use 'accelerate launch' which will do this automatically.

    这是因为 RTX 4000 系列显卡在某些情况下不支持通过 P2P 或 IB 来进行更快的通信,根据提示设置 NCCL_P2P_DISABLENCCL_IB_DISABLE 环境变量即可:export NCCL_P2P_DISABLE=1; export NCCL_IB_DISABLE=1

  5. 解决以上问题后,就可以使用 accelerate launch train_tuneavideo.py --config="configs/man-skiing.yaml" 指令进行训练。训练完成后,权重被写入 outputs/XXX 文件夹,配置文件中的 4 条验证结果被写入 outputs/XXX/samples 文件夹:

  6. 还可以使用 README 中提供的示例代码进行推理:

实验结果

1. man-skiing

a man is skiing(输入):

Tune-A-Video man-skiing源视频

mickey mouse is skiing on the snow:

spider man is skiing on the beach, cartoon style:

wonder woman, wearing a cowboy hat, is skiing:

a man, wearing pink clothes, is skiing at sunset:

iron man is skiing on the sea:

2. man-spraying-fire

A man is spraying fire(输入):

TAV man-spraying-fire2源视频

A man is spraying water:


  1. RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by passing the keyword argument find_unused_parameters=True to torch.nn.parallel.DistributedDataParallel, and by making sure all forward function outputs participate in calculating loss #78 ↩︎
相关推荐
HyperAI超神经19 小时前
Stable Virtual Camera 重新定义3D内容生成,解锁图像新维度;BatteryLife助力更精准预测电池寿命
图像处理·人工智能·3d·数学推理·视频生成·对话语音生成·蛋白质突变
next_travel2 天前
注意力蒸馏技术
风格迁移·扩散模型
小喵要摸鱼2 天前
【Hugging Face 开源库】Diffusers 库 —— 扩散模型
开源·扩散模型·hugging face·diffusers 库
Bill Adams13 天前
开源免费一句话生成儿童故事视频核心思想解析
人工智能·开源·音视频·视频生成
AI生成未来14 天前
通向AGI的未来之路!首篇2D/视频/3D/4D统一生成框架全景综述(港科大&中山等)
多模态·图像生成·综述·多模态大模型·视频生成
东荷新绿15 天前
【CVPR-2023】DR2:解决盲人脸复原无法覆盖真实世界所有退化的问题
论文阅读·扩散模型·盲人脸复原
_Meilinger_16 天前
大模型微调|使用 LLaMA-Factory 微调 Llama3-8B-Chinese-Chat 完成知识问答任务
大模型·llm·微调·llama·大模型微调·llama-factory·unsloth
玩电脑的辣条哥25 天前
大模型LoRA微调训练原理是什么?
人工智能·lora·微调
杀生丸学AI1 个月前
【三维分割】LangSplat: 3D Language Gaussian Splatting(CVPR 2024 highlight)
人工智能·3d·大模型·aigc·svd·语义分割·视频生成
CS_木成河1 个月前
【深度学习】预训练和微调概述
人工智能·深度学习·语言模型·微调·预训练