예제 #1
0
    def __init__(self, checkpoint, is_training=False):
        """Initialize the MajMinPopMusicTransformer model, setting the default
        input dimension, memory length, number of encoder layers, and other
        hyperparameters.

        Args:
            checkpoint: the filepath for the pre-trained model.
            is_training: boolean indicating if model should be used in
                         train or evaluation mode.
        """
        PopMusicTransformer.__init__(self, checkpoint, is_training)

        # tick step-size; used to get tempo information in input.
        self.DEFAULT_RESOLUTION = 480
예제 #2
0
def main(num_samples, num_bars, temperature, prompt_dir, output_dir):
    # declare model
    model = PopMusicTransformer(checkpoint='REMI-tempo-chord-checkpoint',
                                is_training=False)

    from_scratch_path = output_dir + 'from_scratch/'
    with_prompt_path = output_dir + 'with_prompt/'

    if not os.path.exists(from_scratch_path):
        os.makedirs(from_scratch_path)
    if not os.path.exists(with_prompt_path):
        os.makedirs(with_prompt_path)

    for i in range(num_samples):
        # generate from scratch
        model.generate(n_target_bar=num_bars,
                       temperature=temperature,
                       output_path=from_scratch_path + '{}.midi'.format(i),
                       prompt=None)

        # generate continuation
        model.generate(n_target_bar=num_bars,
                       temperature=temperature,
                       output_path=with_prompt_path + '{}.midi'.format(i),
                       prompt=prompt_dir + f'{i:03}' + '.midi')

    # close model
    model.close()
예제 #3
0
def main():
    # declare model
    model = PopMusicTransformer(
        checkpoint='my-piano',
        is_training=False)
    
    for i in range(0,10):
        # generate continuation
        model.generate(
            n_target_bar=30,
            temperature=1.2,
            topk=5,
            output_path='./result/continuation'+str(i)+'.midi',
            prompt='./data/evaluation/00'+str(i)+'.mid')

        # generate from scratch
        model.generate(
            n_target_bar=30,
            temperature=1.2,
            topk=5,
            output_path='./result/from_scratch'+str(i)+'.midi',
            prompt=None)
    
    # close model
    model.close()
예제 #4
0
def main():
    # declare model
    model = PopMusicTransformer(checkpoint='Chinese-piano-checkpoint',
                                is_training=True)
    # prepare data
    midi_paths = glob('data/train/*.mid')  # you need to revise it
    training_data = model.prepare_data(midi_paths=midi_paths)

    # check output checkpoint folder
    output_checkpoint_folder = 'my-piano'  # your decision
    if not os.path.exists(output_checkpoint_folder):
        os.mkdir(output_checkpoint_folder)

    # finetune
    model.finetune(training_data=training_data,
                   output_checkpoint_folder=output_checkpoint_folder)

    ####################################
    # after finetuning, please choose which checkpoint you want to try
    # and change the checkpoint names you choose into "model"
    # and copy the "dictionary.pkl" into the your output_checkpoint_folder
    # ***** the same as the content format in "REMI-tempo-checkpoint" *****
    # and then, you can use "main.py" to generate your own music!
    # (do not forget to revise the checkpoint path to your own in "main.py")
    ####################################

    # close
    model.close()
예제 #5
0
파일: finetune.py 프로젝트: sid0710/remi
def main():
    # declare model
    model = PopMusicTransformer(checkpoint='REMI-tempo-checkpoint',
                                is_training=True)
    # prepare data
    midi_paths = glob('finetune_midis/*.midi')  # you need to revise it
    training_data = model.prepare_data(midi_paths=midi_paths)

    # check output checkpoint folder
    ####################################
    # if you use "REMI-tempo-chord-checkpoint" for the pre-trained checkpoint
    # please name your output folder as something with "chord"
    # for example: my-love-chord, cute-doggy-chord, ...
    # if use "REMI-tempo-checkpoint"
    # for example: my-love, cute-doggy, ...
    ####################################
    output_checkpoint_folder = 'REMI-finetune'  # your decision
    if not os.path.exists(output_checkpoint_folder):
        os.mkdir(output_checkpoint_folder)

    # finetune
    model.finetune(training_data=training_data,
                   output_checkpoint_folder=output_checkpoint_folder)

    ####################################
    # after finetuning, please choose which checkpoint you want to try
    # and change the checkpoint names you choose into "model"
    # and copy the "dictionary.pkl" into the your output_checkpoint_folder
    # ***** the same as the content format in "REMI-tempo-checkpoint" *****
    # and then, you can use "main.py" to generate your own music!
    # (do not forget to revise the checkpoint path to your own in "main.py")
    ####################################

    # close
    model.close()
예제 #6
0
파일: main.py 프로젝트: zhuwenxing/remi
def main():
    # declare model
    model = PopMusicTransformer(checkpoint='REMI-tempo-checkpoint',
                                is_training=False)
    # generate from scratch
    model.generate(n_target_bar=16,
                   temperature=1.2,
                   output_path='./result/from_scratch.midi',
                   prompt=None)
    # generate continuation
    model.generate(n_target_bar=16,
                   temperature=1.2,
                   output_path='./result/continuation.midi',
                   prompt='./data/evaluation/000.midi')
    # close model
    model.close()
예제 #7
0
파일: main.py 프로젝트: Akamight/remi
def main():
    # declare model
    model = PopMusicTransformer(is_training=False)
    # generate from scratch
    for i in range(100):
        model.generate(n_target_bar=50,
                       temperature=1.2,
                       output_path='./result/from_scratch' + str(i) + '.midi',
                       prompt="evaluation/" + str(i).zfill(3) + ".midi")

    model.close()
예제 #8
0
파일: finetune.py 프로젝트: Akamight/remi
def main():
    # declare model
    model = PopMusicTransformer(checkpoint='REMI-tempo-checkpoint',
                                is_training=True,
                                use_chords=True,
                                train_from_scratch=False)
    # prepare data
    midi_paths = glob('midi/**/*.midi', recursive=True) + glob(
        'midi/**/*.mid', recursive=True)  # you need to revise it

    if os.path.exists(
            "233.data"
    ):  # Revise the training data save location, as data preprocessing could take hours or even days on commercial hardware.
        with open("233.data", "rb") as file:
            training_data = pickle.load(file)
    else:
        training_data = model.prepare_data(midi_paths=midi_paths)
        with open("233.data", "wb") as file:
            pickle.dump(training_data, file,
                        protocol=4)  # For large preprocessed files

    # check output checkpoint folder
    ####################################
    # Restrictions on the folder name is removed.
    ####################################
    output_checkpoint_folder = 'REMI-chord-finetune'  # your decision
    if not os.path.exists(output_checkpoint_folder):
        os.mkdir(output_checkpoint_folder)

    # finetune
    model.finetune(training_data=training_data,
                   output_checkpoint_folder=output_checkpoint_folder)

    ####################################
    # after finetuning, please choose which checkpoint you want to try
    # and change the checkpoint names you choose into "model"
    # and copy the "dictionary.pkl" into the your output_checkpoint_folder
    # ***** the same as the content format in "REMI-tempo-checkpoint" *****
    # and then, you can use "main.py" to generate your own music!
    # (do not forget to revise the checkpoint path to your own in "main.py")
    ####################################

    # close
    model.close()
예제 #9
0
def main():
    # declare model
    model = PopMusicTransformer(
        checkpoint='kukkik-finetuned-checkpoint',
        is_training=False)
    
    # generate from scratch
    model.generate(
        n_target_bar=16,
        temperature=1.2,
        topk=5,
        output_path='./result/from_scratch_finetuned.midi',
        prompt=None)
    
    # generate continuation
    model.generate(
        n_target_bar=16,
        temperature=1.2,
        topk=5,
        output_path='./result/continuation_finetuned.midi',
        prompt='./data/evaluation/012.midi')
    
    # close model
    model.close()
예제 #10
0
def load_model():
    return PopMusicTransformer(checkpoint='REMI-tempo-checkpoint',
                               is_training=False)