1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MagentaのMusicVAEで音楽データ学習時間を改善するためのプログラム

Last updated at Posted at 2020-07-14

本記事はすでにMagentaの実践を行っている方に向けて書かれています。
Magnetaをご存じない方、実践した事がない方には何が書いてあるのか訳のわからない内容になると思いますのでご注意ください。

MusicVAEの概要とその問題点

Googleの音楽機械学習ライブラリMagenta。 そのMagentaの多彩な音楽生成モデルの中でも3パート(メロディ、ベース、ドラム)のバンド演奏の様な高度な生成を可能にするのがMusicVAEです。

MusicVAEは、Magentaの中でももっとも高度なモデルの一つですが、その分プログラムも複雑で、生成、学習とも、時間がかかります。

特に学習には非常に時間がかかり、大規模データだと数日かかっても終わらない、、、などという事も多々ありました。

このあまりに時間がかかる学習時間について、実はユーザーからGoogleに問い合わせや要望も寄せられており、Magneta開発チームの責任者の方も、プログラム的に問題があるボトルネックな箇所だ、と認める発言をしていました。

ただし同時に、オープンソースのプロジェクトであるMagentaにおいて、そう言った要望に応える改善を、早急に、頻繁に行う事は難しいという旨の発言もしています。

MusicVAEの学習時間を劇的に改善?preprocess_tfrecorf.py

しかし、抜本的なプログラムの見直しはない代わりに、代替案として、対策用のPythonスクリプトファイルを急遽作成してリリースしてくれています。

preprocess_tfrecord.py

です。

このPythonスクリプトファイルが何を行うのでしょうか?
コード内のコメントには以下の様に記述されていました。

r”””Beam job to preprocess a TFRecord of NoteSequences for training a MusicVAE.
Splits a TFRecord of NoteSequences (as prepared by convert_to_note_sequences)
into individual examples using the DataConverter in the given config, outputting the resulting unique sequences in a new TFRecord file. 
The ID field of each new NoteSequence will contain a comma-separated list of the original NoteSequence(s) it was extracted from.

日本語で概略を書くと
大規模な学習用のNotesequence TF Recordデータを、任意の設定に合わせ、Data Converterを使用し , (カンマ)で区切られ、個別にIDが割り振られた小さなデータに分割。
その小さなデータの集まりを、全く新しいTF Recordデータとして作成する。という前処理を行う様です。

単にデータを少ない固まりに分割と聞くと、バッチサイズの変更では?とも思いますが、これまでバッチサイズを変えても学習時間の改善は見れられませんでした。

しかしこの分割されたTF Recordデータは、学習時間の改善に寄与するとの事ですので、学習の際に行われる(時間のかかるボトルネックな)作業を排除する事ができる処理なのでしょう。

学習時間改善!実行コマンド解説

実行には、Magentaの開発環境を構築する必要があります。

サンプルコマンドを見てみましょう。

(preprocess_tfrecord.pyサンプルコマンド)
python -m magenta.models.music_vae.preprocess_tfrecord \
--input_tfrecord=/path/to/tfrecords/train.tfrecord \
--output_tfrecord=/path/to/tfrecords/train-$CONFIG.tfrecord \
--output_shards=10 \
--config=$CONFIG \
--alsologtostderr

の様に実行します。

input_tfrecordにはご自身のTF Recordデータを渡してください。
pathやconfigは各自の設定に合わせて変更してください。
output_shardsは分割されるTF Recordデータの各データサイズでしょうか?

その他のコマンドオプション

サンプルコマンド以外にも色々な指定を行えるオプションがあります。 サンプルコマンドで使用したものも合わせてどんなオプションが使用できるか? tf.flagsで記述された部分のコードを見てみましょう。
(preprocess_tfrecord.pyから抜粋)
flags.DEFINE_string(
input_tfrecord, None,
Filepattern matching input TFRecord file(s).) #変換するTF Recordファイル

flags.DEFINE_string(
output_tfrecord, None,
The prefx for the output TFRecord file(s).) #出力するTF Recordファイル

flags.DEFINE_integer(
output_shards, 32,
The number of output shards.) #出力するTF Recordファイルの分割数?

flags.DEFINE_string(
config, None,
The name of the model config to use.) #使用するMusicVAEの設定

flags.DEFINE_bool(
enable_filtering, True,
If True, enables max_total_time, max_num_notes, min_velocities, 
min_metric_positions, is_drum, and drums_only flags.) #Trueならこれ以下のオプションを有効にする

flags.DEFINE_integer(
max_total_time, 1800,
NoteSequences longer than this (in seconds) will be skipped.) #NoteSequenceの最大時間(指定数以上はスキップ)

flags.DEFINE_integer(
max_num_notes, 10000,
NoteSequences with more than this many notes will be skipped.) #NoteSequenceの最大音数(指定数以上はスキップ)

flags.DEFINE_integer(
min_velocities, 1,
NoteSequences with fewer unique velocities than this will be skipped.) #最小ベロシティ(指定数以下はスキップ)

flags.DEFINE_integer(
min_metric_positions, 1,
NoteSequences with fewer unique metric positions between quarter notes 
than this will be skipped.) #細かいタイミングにある音符をスキップ

flags.DEFINE_bool(
is_drum, None,
If None, filtering will consider drums and non-drums. If True, only drums 
will be considered. If False, only non-drums will be considered.) #TrueならDrum音だけを取り扱う。Falseならドラム音以外だけを取り扱う

flags.DEFINE_bool(
drums_only, False,
If True, NoteSequences with non-drum instruments will be skipped.) #Trueならドラム音ではない音はスキップ

flags.DEFINE_list(
pipeline_options, ‘–runner=DirectRunner,
A comma-separated list of command line arguments to be used as options 
for the Beam Pipeline.) #パイプラインオプション

実行コマンドにオプションとして例えば

--is_drum=True

の様に記述し実行できます。

最後に

MusicVAEは、これまで学習時間が非常に長いのが欠点でした、、、 まだこのpreprocess_tfrecord,pyは試していませんが、もし改善するなら、そしてできれば劇的に改善するなら、MusicVAEで試したい学習と生成はたくさんあります。

学習時間の改善なども今後レポートしたいと思います。

楽しみにしていてください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?