Peformance RNN使ってみた【図解速習DeepLearning】#021
こんにちは!こーたろーです。
春からDeepLearningや機械学習を教えることになりました。
今は準備でばたばたしております。
合間を縫ってブログを書いていきます。
毎日書くのは大変!
ということで、今回も【図解速習DEEP LEARNING】やっていきます!
今回はPerformance RNNで音源を作っていきます。
Performance RNNでは、LSTMのモデルをつかって学習を行っている、学習済みモデルです。
MIDに似たIデータから、楽譜を解釈し、タイミングや音の強弱を自在に変化させ、演奏します。
早速コーディングしていきます。
事前準備
今回もPython2系を使用していきます。
下記のURLから2系のGoogle Colabを開きます。
https://colab.research.google.com/notebook#create=true&language=python2
環境設定を行っていきます。
学習時の入力データセットは、Yamaha 「e-Piano Competition data set」を用います。
環境の準備
%tensorflow_version 1.x !apt-get update -qq && apt-get install -qq libfluidsynth1 build-essential libasound2-dev libjack-dev !pip install -U magenta==0.5.0 pyfluidsynth import ctypes.util orig_ctypes_util_find_library = ctypes.util.find_library def proxy_find_library(lib): if lib == 'fluidsynth': return 'libfluidsynth.so.1' else: return orig_ctypes_util_find_library(lib) ctypes.util.find_library = proxy_find_library !gsutil -m cp gs://download.magenta.tensorflow.org/soundfonts/Yamaha-C5-Salamander-JNv5.1.sf2 /tmp/ import os from magenta.models.performance_rnn import performance_sequence_generator from magenta.protobuf import generator_pb2 from magenta.protobuf import music_pb2 import magenta.music as mm import warnings warnings.filterwarnings("ignore", category=DeprecationWarning)
モデルを取得する
モデル名とモデルのディレクトリを指定して取得していきます。
BUNDLE_DIR = '/tmp/' MODEL_NAME = 'performance_with_dynamics' BUNDLE_NAME = MODEL_NAME + '.mag' mm.notebook_utils.download_bundle(BUNDLE_NAME, BUNDLE_DIR)
曲の生成及び演奏データの生成
学習済みモデルに開始フレーズを与えて、次々と音を予測して曲を生成していきます。
最後に演奏データを出力します。
bundle = mm.sequence_generator_bundle.read_bundle_file(os.path.join(BUNDLE_DIR, BUNDLE_NAME)) generator_map = performance_sequence_generator.get_generator_map() generator = generator_map[MODEL_NAME](checkpoint=None, bundle=bundle) generator.initialize() generator_options = generator_pb2.GeneratorOptions() generator_options.args['temperature'].float_value = 1.0 generate_section = generator_options.generate_sections.add(start_time=0, end_time=30) sequence = generator.generate(music_pb2.NoteSequence(), generator_options) mm.plot_sequence(sequence) mm.play_sequence(sequence, mm.midi_synth.fluidsynth, sf2_path='/tmp/Yamaha-C5-Salamander-JNv5.1.sf2')
音源データにおけるDeepLearningはいかがだったでしょうか。
新たな芸術もデータサイエンスの中から生まれるかもしれませんね。
次回からは強化学習を行っていきます!
DeepLearning体験ももう少しで終わります。
ではでは。