DeepBach:基于深度学习的巴赫合唱曲生成模型

code accompanying "DeepBach: a Steerable Model for Bach Chorales Generation" paper

Branch2Tags2
FilesLast commitLast update
4 years ago
5 years ago
5 years ago
7 years ago
8 years ago
4 years ago
4 years ago
7 years ago
5 years ago
7 years ago
7 years ago
4 years ago
7 years ago
5 years ago
4 years ago

深度巴赫(DeepBach)

这个仓库包含了在以下文献中描述的DeepBach模型的实现:

深度巴赫:用于巴赫合唱曲生成的可定向模型
Gaëtan Hadjeres, François Pachet, Frank Nielsen
ICML 2017 arXiv:1612.01010

代码使用Python 3.6和PyTorch v1.0以及music21库。

要获取原始的Keras版本,请检查出original_keras分支。

由DeepBach生成的音乐示例可以在这个网站上找到。

安装

您可以克隆此仓库,使用Anaconda安装依赖项,并通过以下命令下载预训练模型和数据集:

git clone git@github.com:Ghadjeres/DeepBach.git
cd DeepBach
conda env create --name deepbach_pytorch -f environment.yml
bash dl_dataset_and_models.sh

这将创建一个名为deepbach_pytorch的conda环境。

music21编辑器

您可能需要配置music21调用的音乐编辑器: 打开一个四声部合唱曲。在服务器地址上按回车键,计算出的模型列表应出现。选择并重新加载模型。 请参阅music21文档,了解如何正确配置。在Ubuntu上,例如,您可以使用MuseScore:

sudo apt install musescore
python -c 'import music21; music21.environment.set("musicxmlPath", "/usr/bin/musescore")'

对于无图形界面服务器(无X服务器),只需将其设置为一个空操作命令:

python -c 'import music21; music21.environment.set("musicxmlPath", "/bin/true")'

使用方法

Usage: deepBach.py [OPTIONS]

Options:
  --note_embedding_dim INTEGER    音符嵌入的维度大小
  --meta_embedding_dim INTEGER    元数据嵌入的维度大小
  --num_layers INTEGER            LSTM层的数量
  --lstm_hidden_size INTEGER      LSTM的隐藏层大小
  --dropout_lstm FLOAT            LSTM层之间丢弃的比例
  --linear_hidden_size INTEGER    线性层的隐藏层大小
  --batch_size INTEGER            训练批次大小
  --num_epochs INTEGER            训练轮数
  --train                         训练或重新训练指定模型
  --num_iterations INTEGER        并行伪吉布斯采样迭代次数
  --sequence_length_ticks INTEGER
                                  生成合唱曲的长度(以音符计)
  --help                          显示此消息并退出。

示例

只需运行以下命令,就可以使用预训练模型生成一个四小节的合唱曲并在MuseScore中显示它:

python deepBach.py

添加--train标志可以从头开始训练新模型。

与NONOTO配合使用

运行以下命令启动监听端口5000的Flask服务器:

python flask_server.py

然后您可以使用NONOTO以交互方式与DeepBach一起作曲。

也可以使用Docker启动服务器:

docker run -p 5000:5000 -it --rm ghadjeres/deepbach

(CPU版本)或

docker run --runtime=nvidia -p 5000:5000 -it --rm ghadjeres/deepbach

(GPU版本,需要nvidia-docker)。

在MuseScore中使用

已过时

deepBachMuseScore.qml文件放入MuseScore插件目录,然后运行:

python musescore_flask_server.py

打开MuseScore,使用插件管理器启用deepBachMuseScore插件。之后,不选择任何内容点击“作曲”按钮即可从头生成新的合唱曲。然后,您可以在合唱谱中选择一个区域并点击“作曲”按钮,使用DeepBach再生该区域。

问题

music21编辑器未设置

music21.converter.subConverters.SubConverterException: Cannot find a valid application path for format musicxml. Specify this in your Environment by calling environment.set(None, '/path/to/application')

要么将其设置为MuseScore或其他具有GUI的程序,要么在服务器上设置为空操作命令。见安装部分。

引用

如果您在音乐项目中使用了DeepBach,请考虑引用这项工作或将邮件发送给我。

@InProceedings{pmlr-v70-hadjeres17a,
  title = 	 {{D}eep{B}ach: a Steerable Model for {B}ach Chorales Generation},
  author = 	 {Ga{\"e}tan Hadjeres and Fran{\c{c}}ois Pachet and Frank Nielsen},
  booktitle = 	 {Proceedings of the 34th International Conference on Machine Learning},
  pages = 	 {1362--1371},
  year = 	 {2017},
  editor = 	 {Doina Precup and Yee Whye Teh},
  volume = 	 {70},
  series = 	 {Proceedings of Machine Learning Research},
  address = 	 {International Convention Centre, Sydney, Australia},
  month = 	 {06--11 Aug},
  publisher = 	 {PMLR},
  pdf = 	 {http://proceedings.mlr.press/v70/hadjeres17a/hadjeres17a.pdf},
  url = 	 {http://proceedings.mlr.press/v70/hadjeres17a.html},
}

Introduction

code accompanying "DeepBach: a Steerable Model for Bach Chorales Generation" paper

Customize your domain
35520133Visit GitHub