"""
To create summary and images from a search_result of bayesian optimization
"""
from termcolor import cprint

from src import BayesianOpt as BO
from src import Args
from src.Args import Parser, ArgType


def main(args):
    search_result, dimensions = BO.load.from_checkpoint(args.folder /
                                                        'checkpoint')
    BO.save.save_search_result(search_result=search_result,
                               dimensions=dimensions,
                               folder_path=args.folder)
    cprint('---------- Done ----------', 'grey', 'on_green')


if __name__ == '__main__':
    parser = Parser(argtype=ArgType.HPSummary)
    args = parser.parse_args()

    args = Args.preprocess.hp_summary(args)
    main(args)
        n_random_starts = 1
    if from_checkpoint:
        n_random_starts = 0

    search_result = gp_minimize(func=fitness,
                                dimensions=dimensions.dimensions,
                                acq_func='EI',
                                n_calls=args.n_calls,
                                x0=dimensions.default_dim,
                                callback=[checkpoint_callback],
                                n_random_starts=n_random_starts)

    BO.save.save_search_result(search_result=search_result,
                               dimensions=dimensions,
                               folder_path=folder_path)

    cprint('---------- Done ----------', 'grey', 'on_green')


# ----------------------------------------------------------------------------------------------------
#                                                   Script
# ----------------------------------------------------------------------------------------------------

if __name__ == '__main__':
    parser = Parser(argtype=ArgType.HPSearch)
    args = parser.parse_args()

    args = Args.preprocess.bayesian_opt(args)

    main(args)
Beispiel #3
0
        if not args.no_midi:
            roots.append('generated_midis')
        if not args.no_hp:
            roots.append('search_hp')
        if not args.no_model:
            roots.append('saved_models')
    else:
        if args.midi:
            roots.append('generated_midis')
        if args.hp:
            roots.append('hp_search')
        if args.model:
            roots.append('saved_models')

    to_zip = []
    for root in roots:
        to_zip.extend(get_all_file_paths(root))

    with ZipFile('my_zip.zip', 'w') as zip:
        for file in to_zip:
            zip.write(file)

    print('Done zipping in my_zip.zip')


if __name__ == '__main__':
    parser = Parser(argtype=ArgType.Zip)
    args = parser.parse_args()

    args = Args.preprocess.zip(args)
    main(args)
Beispiel #4
0
        midi_generator.generate_fill(no_duration=args.no_duration, verbose=1)

    if args.replicate_fill:
        midi_generator.replicate_fill(save_images=True, no_duration=args.no_duration, verbose=1, noise=args.noise)

    # -------------------- Redo song generate --------------------
    if args.redo_generate:
        midi_generator.redo_song_generate(song_number=args.song_number, save_images=True, no_duration=args.no_duration,
                                          noise=args.noise)

    # -------------------- Redo song replicate --------------------
    if args.redo_replicate:
        midi_generator.redo_song_replicate(song_number=args.song_number, save_images=True, no_duration=args.no_duration,
                                           noise=args.noise)

    # -------------------- Debug batch generation --------------------
    if args.check_batch > -1:
        for i in range(len(midi_generator.sequence)):
            midi_generator.compare_test_predict_on_batch(i)

    cprint('---------- Done ----------', 'grey', 'on_green')


if __name__ == '__main__':
    # create a separate main function because original main function is too mainstream
    parser = Parser(argtype=ArgType.Train)
    args = parser.parse_args()

    args = Args.preprocess.train(args)
    main(args)
Beispiel #5
0
def main(args):
    """
        Entry point
    """
    if args.pc:
        data_path = os.path.join('../Dataset', args.data)
    else:
        data_path = os.path.join('../../../../../../storage1/valentin',
                                 args.data)
    data_transformed_path = data_path + '_transformed'

    if not args.pc:
        os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu

    my_model = MidiGenerator.with_model(id=args.load)  # Load the model
    my_model.generate_from_data(length=args.length,
                                nb_seeds=args.nb_seeds,
                                save_images=args.images,
                                no_duration=args.no_duration)

    cprint('---------- Done ----------', 'grey', 'on_green')


if __name__ == '__main__':
    # create a separate main function because original main function is too mainstream
    parser = Parser(argtype=ArgType.Generate)
    args = parser.parse_args()
    args = Args.preprocess.generate(args)
    main(args)
                'all_shapes': all_shapes,
                'input_size': all_shapes[0][0][2],  # The number of notes
                'notes_range': args.notes_range,
                'mono': args.mono,
                'nb_files_per_npy': g.midi.nb_files_per_npy,
                'transposed': not args.no_transpose
            },
            dump_file)

    summary.summarize(
        # Function params
        path=data_transformed_path,
        title=args.data,
        # Summary params
        nb_files=nb_valid_files,
        nb_instruments=len(args.instruments),
        instruments=args.instruments,
        input_size=all_shapes[0][0][2],
        notes_range=args.notes_range)

    print('Number of songs :', colored('{0}'.format(nb_valid_files), 'blue'))
    print(colored('---------- Done ----------', 'grey', 'on_green'))


if __name__ == '__main__':
    # create a separate main function because original main function is too mainstream
    parser = Parser(argtype=ArgType.ComputeData)
    args = parser.parse_args()
    args = Args.preprocess.compute_data(args)
    main(args)
Beispiel #7
0
        id_saved_folder_base = '' if len(cp_id) == 1 else cp_id[0]
    elif args.bo_name:
        id_saved_folder_base = args.bo_name + '-'
    else:
        id_saved_folder_base = ''
    i_cp = int(args.from_checkpoint.split('-')
               [-1]) if args.from_checkpoint is not None else 0
    if not args.in_place and args.from_checkpoint is not None:
        i_cp += 1

    for script in range(1, args.nscripts):
        print(f'Script {script + 1}/{args.nscripts}')
        s = 'python bayesian-opt.py'
        # We only need to say the number of call and the check point
        # And the if in_place, we keep it
        s += f' --n-calls {args.n_calls}'
        s += f' --from-checkpoint {id_saved_folder_base}{i_cp}'
        if args.in_place:
            s += ' --in-place'
        else:
            i_cp += 1
        os.system(s)


if __name__ == '__main__':
    parser = Parser(argtype=ArgType.NScriptsBO)
    args = parser.parse_args()

    args = Args.preprocess.n_scripts_bo(args)
    main(args)
Beispiel #8
0
    :param args:
    :return:
    """
    if not args.midi:
        shutil.rmtree(path='generated_midis', ignore_errors=True)
    if not args.hp:
        shutil.rmtree(path='hp_search', ignore_errors=True)
    if not args.model:
        shutil.rmtree(path='saved_models', ignore_errors=True)
    if not args.tensorboard:
        shutil.rmtree(path='tensorboard', ignore_errors=True)
    if not args.temp:
        shutil.rmtree(path='temp', ignore_errors=True)
    if not args.data_temp:
        data_temp = EPath(g.path.get_data_folder_path(args)) / 'temp'
        shutil.rmtree(path=data_temp, ignore_errors=True)
    if not args.zip:
        zip_path = EPath('my_zip.zip')
        if zip_path.exists():
            zip_path.unlink()
    print('Done cleaning')


if __name__ == '__main__':
    parser = Parser(argtype=ArgType.Clean)
    args = parser.parse_args()

    args = Args.preprocess.clean(args)
    main(args)
        # matrix_midi = np.transpose(matrix_midi, , 3))
        output_notes = Midi.create.matrix_to_midi(matrix_midi,
                                                  instruments=args.instruments,
                                                  notes_range=args.notes_range,
                                                  mono=args.mono)
        Midi.create.save_midi(output_notes, args.instruments,
                              checked_file_name.as_posix())
        Images.pianoroll.save_array_as_pianoroll(array=matrix_midi,
                                                 folder_path=midi_path.parent,
                                                 name=midi_path.stem +
                                                 '_checked',
                                                 seed_length=0,
                                                 mono=args.mono or args.bach)
    min_notes_range += args.notes_range[0]
    max_notes_range += args.notes_range[0]
    print('----------', colored('Checking is done', 'white', 'on_green'),
          '----------')
    print('Number of correct files :', colored(nb_correct_files, 'magenta'),
          '-- nb measures :', colored(nb_measures, 'magenta'))
    print('Range of notes :', colored(min_notes_range, 'magenta'), ':',
          colored(max_notes_range, 'magenta'))


if __name__ == '__main__':
    # create a separate main function because original main function is too mainstream
    parser = Parser(argtype=ArgType.CheckData)
    args = parser.parse_args()

    args = Args.preprocess.check_dataset(args)
    main(args)