Controllable Music Transformer

Official code for our paper Video Background Music Generation with Controllable Music Transformer (ACM MM 2021 Best Paper Award)

[Paper] [Demos] [Bibtex]

Introduction

在这项工作中,我们解决了视频背景音乐生成的任务。 以前的一些作品实现了有效的音乐生成,但无法为给定的视频专门生成悦耳的音乐,也没有考虑到视频音乐的节奏一致性。 为了生成与给定视频匹配的背景音乐,我们首先建立视频和背景音乐之间的节奏关系。 特别是,我们将视频中的时间、运动速度和运动显着性分别与音乐中的节拍、模拟音符密度和模拟音符强度联系起来。 然后,我们提出了 CMT,这是一种可控音乐转换器,可以对上述节奏特征进行本地控制,以及对音乐流派和用户指定使用的乐器进行全局控制。 客观和主观评价表明,生成的背景音乐与输入视频的兼容性令人满意,同时音乐质量令人印象深刻。

We address the unexplored task – video background music generation. We first establish three rhythmic relations between video and background music. We then propose a Controllable Music Transformer (CMT) to achieve local and global control of the music generation process. Our proposed method does not require paired video and music data for training while generates melodious and compatible music with the given video.

Directory Structure

  • src/: code of the whole pipeline

    • train.py: training script, take a npz as input music data to train the model

    • model.py: code of the model

    • gen_midi_conditional.py: inference script, take a npz (represents a video) as input to generate several songs

    • src/video2npz/: convert video into npz by extracting motion saliency and motion speed

  • dataset/: processed dataset for training, in the format of npz

  • logs/: logs that automatically generate during training, can be used to track training process

  • exp/: checkpoints, named after val loss (e.g. loss_8_params.pt)

  • inference/: processed video for inference (.npz), and generated music(.mid)

Preparation

  • clone this repo

  • download the processed data lpd_5_prcem_mix_v8_10000.npz from HERE and put it under dataset/

  • download the pretrained model loss_8_params.pt from HERE and put it under exp/

  • install ffmpeg=3.2.4

  • prepare a Python3 conda environment

    • conda create -n mm21_py3 python=3.7
      conda activate mm21_py3
      pip install -r py3_requirements.txt
      
    • choose the correct version of torch and pytorch-fast-transformers based on your CUDA version (see fast-trainsformers repo and this issue)

  • prepare a Python2 conda environment (for extracting visbeat)

    • conda create -n mm21_py2 python=2.7
      conda activate mm21_py2
      pip install -r py2_requirements.txt
      
    • open visbeat package directory (e.g. anaconda3/envs/XXXX/lib/python2.7/site-packages/visbeat), replace the original Video_CV.py with src/video2npz/Video_CV.py

Training

Note: use the mm21_py3 environment: conda activate mm21_py3

  • A quick start using the processed data lpd_5_prcem_mix_v8_10000.npz (1~2 days on 8x 1080Ti GPUs):

    python train.py --name train_default -b 8 --gpus 0 1 2 3 4 5 6 7
    
  • If you want to reproduce the whole process:

    1. download the lpd-5-cleansed dataset from HERE and put the extracted files under dataset/lpd_5_cleansed/

    2. go to src/ and convert the pianoroll files (.npz) to midi files (~3 files / sec):

      python pianoroll2midi.py --in_dir ../dataset/lpd_5_cleansed/ --out_dir ../dataset/lpd_5_cleansed_midi/
      
    3. convert midi files to .npz files with our proposed representation (~5 files / sec):

      python midi2numpy_mix.py --midi_dir ../dataset/lpd_5_cleansed_midi/ --out_name data.npz
      
    4. train the model (1~2 days on 8x 1080Ti GPUs):

      python train.py --name train_exp --train_data ../dataset/data.npz -b 8 --gpus 0 1 2 3 4 5 6 7
      

Note: If you want to train with another MIDI dataset, please ensure that each track belongs to one of the five instruments (Drums, Piano, Guitar, Bass, or Strings) and is named exactly with its instrument. You can check this with Muspy:

import muspymidi = muspy.read_midi('xxx.mid')
print([track.name for track in midi.tracks]) # Should be like ['Drums', 'Guitar', 'Bass', 'Strings']

Inference

  • convert input video (MP4 format) into npz (use the mm21_py2 environment):

    conda activate mm21_py2
    cd src/video2npz
    # try resizing the video if this takes a long time
    sh video2npz.sh ../../videos/xxx.mp4
    
  • run model to generate .mid (use the mm21_py3 environment) :

    conda activate mm21_py3
    python gen_midi_conditional.py -f "../inference/xxx.npz" -c "../exp/loss_8_params.pt"# if using another training set, change `decoder_n_class` and `init_n_class` in `gen_midi_conditional` to the ones in `train.py`
    
  • convert midi into audio: use GarageBand (recommended) or midi2audio

    • set tempo to the value of tempo in video2npz/metadata.json (generated when running video2npz.sh)
  • combine original video and audio into video with BGM:

    ffmpeg -i 'xxx.mp4' -i 'yyy.mp3' -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 'zzz.mp4'# xxx.mp4: input video
    # yyy.mp3: audio file generated in the previous step
    # zzz.mp4: output video
    

Matching Method

  • The matching method finds the five most matching music pieces from the music library for a given video (use the mm21_py3 environment).

    conda activate mm21_py3
    python src/match.py inference/xxx.npz dataset/lpd_5_prcem_mix_v8_10000.npz
    

Citation

@inproceedings{di2021video,title={Video Background Music Generation with Controllable Music Transformer},author={Di, Shangzhe and Jiang, Zeren and Liu, Si and Wang, Zhaokai and Zhu, Leyan and He, Zexin and Liu, Hongming and Yan, Shuicheng},booktitle={Proceedings of the 29th ACM International Conference on Multimedia},pages={2037--2045},year={2022}
}

Acknowledgements

Our code is based on Compound Word Transformer.

山东大学项目实训十六——可控音乐变压器Controllable Music Transformer相关推荐

  1. 山东大学项目实训——地图圈系统——微信小程序(16)

    地图圈系统--微信小程序(16) 一.社区功能 二.项目代码 三.效果展示 一.社区功能 这次项目实训的社区功能是一个很大的模块,包括显示用户发布的文字及图片.用户选择的地点.发布的时间.点赞.评论等 ...

  2. 山东大学项目实训——6月29日

    总结项目实训近两天的工作. 首先在第一天上午,参加项目实训开幕仪式,了解实训相关规定和内容.然后与李学庆老师见面,由他像我们讲解项目内容,介绍项目需求. 同时我主动提出担任项目组长. 通过与李学庆老师 ...

  3. 山东大学项目实训——简易微信小游戏(一)

    一.项目背景 微信小程序接触真实用户快,对用户反馈快速体现,是一个非常好的实践平台.同时就行业背景来看,人们对于无需安装打开即玩的休闲类小游戏的需求依然存在. 二.工作内容 开发绳套奶牛.大鱼吃小鱼. ...

  4. 实训十六:路由器RIPV2配置

    一.实验目的 掌握动态路由的配置方法 理解 RIP-2 协议的工作过程 理解 RIP-2 对变长子网掩码的支持 二.应用环境 在不连续的变长子网掩码环境中,RIP-1 的自动汇总会得出错误的路由 RI ...

  5. 山东大学项目实训——地图圈系统——微信小程序(18)

    地图圈系统--微信小程序(18) 一.轨迹记录功能 二.项目代码 三.效果展示 一.轨迹记录功能 轨迹记录功能的实现思路相对简单,设置一个定时器,每隔1s获取一下当前位置,将当前的经纬度坐标加入到数组 ...

  6. 山东大学项目实训(四)—— 微信小程序扫描web端二维码实现web端登录

    效果 点击登录后,显示二维码→打开"探古"(本项目)微信小程序,扫描二维码确认登录→web端登录成功 主要流程 因为本人主要负责web前端的开发,所以本文仅介绍web前端的实现方法 ...

  7. 山东大学项目实训小组一——基于深度学习的AI视频剪辑器“易剪”

    技术要点:图像处理 计算机视觉 深度学习 多媒体前端 一.项目研究背景: 随着短视频热潮的兴起,越来越多的人投入精力到了视频剪辑视频制作之中.然而利用现有的视频剪辑工具,剪辑一段视频是非常麻烦的,尤其 ...

  8. 山东大学项目实训——地图圈系统——微信小程序(17)

    地图圈系统--微信小程序(17) 一.社区附加功能 二.项目代码 三.效果展示 一.社区附加功能 在上次社区功能的基础上,我增加了几个附加功能,首先点击用户头像可以看到此用户的用户信息,然后点击查看动 ...

  9. 山东大学项目实训——地图圈系统——微信小程序(5)

    地图圈系统--微信小程序(5) 一.腾讯位置服务路线规划api 二.结果响应实例 三.项目代码 四.效果展示 一.腾讯位置服务路线规划api 提供路线规划能力. 1.驾车(driving):支持结合实 ...

最新文章

  1. C#下调用WMI查询系统信息
  2. ct读片软件_伦琴影领影像诊断中心:这六大MRI读片技巧,影像医生必须掌握
  3. 算法之图搜索算法(一)
  4. TimerTask定时任务
  5. 有没有测试人心里的软件,心理测评,认识自己的有效工具:(二)你做的可能是假的心理测试...
  6. 原生xgboost与sklearn里的xgboost
  7. Windows下安装Semantic-Segmentation-Editor标注软件
  8. parfor —— matlab 下的并行循环
  9. 如何把Spring Boot 项目变成一个XML配置的Spring项目
  10. 详析Exchange 2007/2010 SSL证书如何安装
  11. 从单张图重建三维人体模型综述(二)
  12. python UI自动化图片断言
  13. 【Java】日期格式化的三种方式
  14. python实现定时自动发送qq消息
  15. 计算机学报编辑待遇,《计算机学报》编辑委员会
  16. 我参加NVIDIA Sky Hackathon 环境安装(编程环境)
  17. SQL的select 语句的执行顺序
  18. 数据技术-分析报告如何写
  19. chareter oracle,Oracle数据库的操作程序.pdf-汇文网
  20. 一亩三分地-每日答题

热门文章

  1. 矩阵链乘法 自顶向下 自底向上 Python 实现 算法导论
  2. 次更新不适用您的计算机,Windows系统安装补丁时提示“此更新不适用于你的计算机”的解决方案!...
  3. OBS更改标题?标题一改,安能辨我是雌雄?
  4. layui后台首页关闭标签
  5. java计算机毕业设计再生产公益管理系统设计与实现MyBatis+系统+LW文档+源码+调试部署
  6. 有些jpg图在IE浏览器中打不开
  7. AndroidLocalizationer 支持百度翻译
  8. 用 node.js 来制作数据可视化视频吧
  9. 茶颜悦色的“雷”早已埋下
  10. oracle wallet java_使用Oracle sqlplus Instant客户端访问Oracle Wallet