Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tanreinama committed Nov 8, 2020
1 parent fa865ae commit 8386aeb
Show file tree
Hide file tree
Showing 31 changed files with 1,429 additions and 0 deletions.
150 changes: 150 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Chord2Melody - Automatic Music Generation AI



[日本語](README_ja.md)

[demonstration]()

[samples](samples/)



## What is Chord2Melody?



It is an AI that composes music, with MIDI output.

It is based on GPT-2. You can generate music of arbitrary length, and you can also specify the chord progression to generate music.

Or they can compose a continuation of a music they've been working on.

The output music can be used as free content without any copyright or usage restrictions.



### Pretrained Models



There are two models that have been trained: the "base_5tr" with 5 output tracks and the "base_17tr" with 17 tracks.



| Model Name | output tracks | total number of parameters |
| ------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------- |
| [base_5tr](https://www.nama.ne.jp/models/chord2melody-base_5tr.tar.gz) | Drums, Piano, Guitar, Bass, Strings | 86167296 |
| [base_17tr](https://www.nama.ne.jp/models/chord2melody-base_17tr.tar.gz) | Drums, Piano, Chromatic Percussion, <br />Organ, Guitar, Bass, Strings, Ensemble, <br />Brass, Reed, Pipe, Synth Lead, Synth Pad, <br />Synth Effects, Ethnic, Percussive, Sound Effects | 86941440 |



## Usage



First, clone chord2melody from GitHub.

```sh
$ git clone https://github.com/tanreinama/chord2melody
$ cd chord2melody
```

Then, download and extract the pretrained model from the link above.

```sh
$ wget https://www.nama.ne.jp/models/chord2melody-base_5tr.tar.bz2
$ tar xvfj chord2melody-base_5tr.tar.bz2
```

Launch chord2melody.py with specifying the model , a MIDI file is created.

```sh
$ python3 chord2melody.py --model base_5tr
```

There is no limit to the length of music that can be output. The total number of bars of music to be generated is specified with the "--num_bars" option.

```sh
$ python3 chord2melody.py --num_bars 48
```



### Chord to Melody



To specify the chord progression, use the "--chord" option, and use the "--chordbeat" option to specify how many chords to put in a measure.

```sh
$ python3 chord2melody.py --chord "C|C|C|C|Dm|Dm|Dm|Dm|G7|G7|G7|G7|Am|Am|Am|Am" --chordbeat 4
```

Chord" option, you can specify from [Available Chord](chordlist.txt) or "auto" connected with "|".



###Compose a continuation of a music



The program "melody2melody.py" will automatically compose a continuation of a music you have been working on. Use the "--input" option in "melody2melody.py" to specify the MIDI file you want to create a continuation of.

```sh
$ python3 melody2melody.py --input halfway.mid
```



### Specifies the fluctuation of the melody



By specifying "--top_p", you can specify the fluctuation of the song.

```sh
$ python3 chord2melody.py --top_k 25 --top_p 0
```

Put one or two numbers in "--top_p". The first number is used when there's a chord progression and the second (if specified) when the chord progression is "auto".



## Learning Methods



The data for training is from [Lakh Pianoroll Dataset](https://salu133445.github.io/lakh-pianoroll-dataset/). To train, download [lpd_5_full.tar.gz](https://drive.google.com/u/0/open?id=1tZKMhYazSWapFTUt7H6abHSo-QKH9ATC) or [lpd-17-full.tar.gz](https://drive. google.com/uc?export=download&id=1bJAC2SKhdKbKvpLL1V1l66cCgWX8eQEm) and extract it.

Next, go to the train directory and run "encode.py" to create a training data file.

The "--da" option allows you to specify data augmentation by modulation. The randomly modulated data is used to increase the training data.

```sh
$ cd train
$ python3 encode.py --dataset lpd_5 --output lpd_5_dataset
```

Run "train.py" with specify the type of dataset (lpd_5/lpd_7) in "--dataset" option and the encoded training data file in "--input" option.

```sh
$ python3 train.py --dataset lpd_5 --input lpd_5_dataset
```



### Fine Tuning



To fine-tune your own data, you must first edit the data to 5 or 17 tracks of MIDI data.

Then save the data in pypianoroll format, with the tracks in the same order as the original model.

Then you can create a training data file in encoder.py and fine tune it by specifying the original trained model in the "--restore_from" field.

```sh
$ python3 train.py --dataset lpd_5 --input lpd_5_dataset --restore_from ../base_5tr
```

152 changes: 152 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Chord2Melody - 音楽自動生成AI



[English](README.md)

[デモンストレーション]()

[サンプル](samples/)



## Chord2Melodyとは



音楽を作曲してくれるAIです。MIDIでアウトプットされます。

GPT-2をベースに作成されました。任意の長さの音楽を生成出来て、さらにコード進行を指定して生成させることも可能です。

あるいは、作りかけの曲の続きを作曲してくれます。

出力された音楽は、著作権や利用範囲の制限のないフリーコンテンツとして利用出来ます。



### 学習済みモデル



学習済みのモデルは、出力トラック数が5トラックの「base_5tr」と、17トラックを出力する「base_17tr」の2種類あります。



| モデル | 出力トラック | 総パラメーター数 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---------------- |
| [base_5tr](https://www.nama.ne.jp/models/chord2melody-base_5tr.tar.gz) | Drums, Piano, Guitar, Bass, Strings | 86167296 |
| [base_17tr](https://www.nama.ne.jp/models/chord2melody-base_17tr.tar.gz) | Drums, Piano, Chromatic Percussion, <br />Organ, Guitar, Bass, Strings, Ensemble, <br />Brass, Reed, Pipe, Synth Lead, Synth Pad, <br />Synth Effects, Ethnic, Percussive, Sound Effects | 86941440 |



## 使い方



まず、GitHubからクローンします。

```sh
$ git clone https://github.com/tanreinama/chord2melody
$ cd chord2melody
```

上記のリンクから学習済みのモデルをダウンロードして展開します。

```sh
$ wget https://www.nama.ne.jp/models/chord2melody-base_5tr.tar.bz2
$ tar xvfj chord2melody-base_5tr.tar.bz2
```

モデルを指定し、chord2melody.pyを起動すると、MIDIファイルが作成されます。

```sh
$ python3 chord2melody.py --model base_5tr
```

出力可能な音楽の長さに制限はありません。合計で何小節分の音楽を生成するかは、「--num_bars」オプションで指定します。

```sh
$ python3 chord2melody.py --num_bars 48
```



### コード進行→メロディー



コード進行を指定するには、「--chord」オプションを使用します。1小節に何個のコードを入れるかは「--chordbeat」オプションで指定します。

```sh
$ python3 chord2melody.py --chord "C|C|C|C|Dm|Dm|Dm|Dm|G7|G7|G7|G7|Am|Am|Am|Am" --chordbeat 4
```

「--chord」オプションには、[利用出来るコード一覧](chordlist.txt)にあるものか「auto」を、「|」で繋げて指定します。



### 曲の続きを作曲



「melody2melody.py」プログラムは、作りかけの曲の続きを自動で作曲してくれます。「melody2melody.py」に「--input」オプションで、続きを作りたいMIDIファイルを指定します。

```sh
$ python3 melody2melody.py --input halfway.mid
```



### 曲の揺らぎを指定



「--top_p」を指定することで、曲の揺らぎを指定出来ます。

```sh
$ python3 chord2melody.py --chord "C|C|C|C|Dm|Dm|Dm|Dm" --top_p 45,7
```

「--top_p」には、一つか二つの数字を入れます。一つ目の数字はコード進行がある時に使用され、二つ目は(指定されていれば)コード進行が「auto」の時に使用されます。



## 学習方法



学習のためのデータは、 [Lakh Pianoroll Dataset](https://salu133445.github.io/lakh-pianoroll-dataset/)を使用します。予め、[lpd_5_full.tar.gz](https://drive.google.com/u/0/open?id=1tZKMhYazSWapFTUt7H6abHSo-QKH9ATC)又は、[lpd-17-full.tar.gz](https://drive.google.com/uc?export=download&id=1bJAC2SKhdKbKvpLL1V1l66cCgWX8eQEm)をダウンロードして展開しておきます。

trainディレクトリに移動して、「encode.py」を実行して、学習データファイルを作成します。

「--da」オプションで、変調によるData Augmentationを指定出来ます。ランダムに変調を行ったデータで、学習データを増やします。

```sh
$ cd train
$ python3 encode.py --dataset lpd_5 --output lpd_5_dataset
```

「--dataset」にデータセットの種類(lpd_5/lpd_7)を、「--input」にエンコードされた学習データファイルを指定して、「train.py」を実行します。

```sh
$ python3 train.py --dataset lpd_5 --input lpd_5_dataset
```



### ファインチューニング



自前のデータを使ってファインチューニングするには、まずデータを5トラック or 17トラックのMIDIデータに編集する必要があります。

そして、トラックの並び順を、元のモデルと同じ順番にして、pypianoroll形式で保存します。

その後、「encoder.py」で学習データファイルを作成し、「--restore_from」にオリジナルの学習済みのモデルを指定してやると、ファインチューニングすることが出来ます。

```sh
$ python3 train.py --dataset lpd_5 --input lpd_5_dataset --restore_from ../base_5tr
```



Loading

0 comments on commit 8386aeb

Please sign in to comment.