LoginSignup
3
1

More than 3 years have passed since last update.

[Tips] TFRecordsのNoteSequenceの中身を確認する方法

Posted at

備忘録も兼ねてTipsを共有します。掲題の通り、Tensorflowで楽曲データを取り扱うときのデータ形式である NoteSequence の中身を目視で確認する方法です。

動作環境

  • magentaがインストール済。
    • tensorflow/tensorflow:latest-devel のDocker内で pip install magenta を実行した状態。
  • Python 2.7
    • Cloud DataflowをPythonから使うために2系にする必要があったので...。

コード

from magenta.music import note_sequence_io


tfrecord_path = '/path/to/note_sequence.tfrecord'
for sequence in note_sequence_io.note_sequence_record_iterator(tfrecord_path):
    print sequence.id
    print sequence.collection_name
    print sequence.filename
    print sequence.notes

出力結果

以下のような出力が得られます。 私は 楽器Noって含まれてるんだっけ? 等の確認がしたくて見た感じです。

/id/midi/dir_name/xxxxxxxxxxxxxxxxxxxxxxx
dir_name
xxxxxxx.mid
[pitch: 75
velocity: 94
start_time: 74.5522065
end_time: 74.608176625
program: 12
, pitch: 87
velocity: 86
start_time: 29.552226
end_time: 29.88804675
instrument: 1
, pitch: 89
velocity: 93
start_time: 29.999987
end_time: 30.33580775
instrument: 1
, pitch: 91
...
]

midi -> NoteSequence化

magentaリポジトリのコンバートスクリプトで簡単にできます。

3
1
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
3
1