Upload finetune.py
Browse files- finetune.py +45 -0
finetune.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from model import PopMusicTransformer
|
| 2 |
+
from glob import glob
|
| 3 |
+
import os
|
| 4 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
| 5 |
+
|
| 6 |
+
def main():
|
| 7 |
+
# declare model
|
| 8 |
+
model = PopMusicTransformer(
|
| 9 |
+
checkpoint='REMI-tempo-checkpoint',
|
| 10 |
+
is_training=True)
|
| 11 |
+
# prepare data
|
| 12 |
+
midi_paths = glob('YOUR PERSOANL FOLDER/*.midi') # you need to revise it
|
| 13 |
+
training_data = model.prepare_data(midi_paths=midi_paths)
|
| 14 |
+
|
| 15 |
+
# check output checkpoint folder
|
| 16 |
+
####################################
|
| 17 |
+
# if you use "REMI-tempo-chord-checkpoint" for the pre-trained checkpoint
|
| 18 |
+
# please name your output folder as something with "chord"
|
| 19 |
+
# for example: my-love-chord, cute-doggy-chord, ...
|
| 20 |
+
# if use "REMI-tempo-checkpoint"
|
| 21 |
+
# for example: my-love, cute-doggy, ...
|
| 22 |
+
####################################
|
| 23 |
+
output_checkpoint_folder = 'REMI-finetune' # your decision
|
| 24 |
+
if not os.path.exists(output_checkpoint_folder):
|
| 25 |
+
os.mkdir(output_checkpoint_folder)
|
| 26 |
+
|
| 27 |
+
# finetune
|
| 28 |
+
model.finetune(
|
| 29 |
+
training_data=training_data,
|
| 30 |
+
output_checkpoint_folder=output_checkpoint_folder)
|
| 31 |
+
|
| 32 |
+
####################################
|
| 33 |
+
# after finetuning, please choose which checkpoint you want to try
|
| 34 |
+
# and change the checkpoint names you choose into "model"
|
| 35 |
+
# and copy the "dictionary.pkl" into the your output_checkpoint_folder
|
| 36 |
+
# ***** the same as the content format in "REMI-tempo-checkpoint" *****
|
| 37 |
+
# and then, you can use "main.py" to generate your own music!
|
| 38 |
+
# (do not forget to revise the checkpoint path to your own in "main.py")
|
| 39 |
+
####################################
|
| 40 |
+
|
| 41 |
+
# close
|
| 42 |
+
model.close()
|
| 43 |
+
|
| 44 |
+
if __name__ == '__main__':
|
| 45 |
+
main()
|