Ejemplo n.º 1
0
def main(exp, frame_sizes, generate_from, **params):
    params = dict(default_params,
                  exp=exp,
                  frame_sizes=frame_sizes,
                  generate_from=generate_from,
                  **params)
    model = SampleRNN(
        frame_sizes=params['frame_sizes'],
        n_rnn=params['n_rnn'],
        dim=params['dim'],
        learn_h0=params['learn_h0'],
        q_levels=params['q_levels'],
        nb_classes=params['nb_classes'],
        weight_norm=params['weight_norm'],
    )
    #    model = SampleRNN([16, 4], 2, 1024, True, 256, True)
    print('Loading saved model' + params['generate_from'])
    checkpoint = torch.load(params['generate_from'])
    temporary_dict = {}
    for k, v in checkpoint.items():
        temporary_dict[k[6:]] = v
    checkpoint = temporary_dict
    model.load_state_dict(checkpoint)
    if not os.path.exists(params['generate_to']):
        os.mkdir(params['generate_to'])
    print(params['cond'])
    generator = GeneratorPlugin(params['generate_to'], params['n_samples'],
                                params['sample_length'], params['sample_rate'],
                                params['nb_classes'], params['cond'])
    generator.register_generate(model.cuda(), params['cuda'])
    generator.epoch(exp)
Ejemplo n.º 2
0
# Load pretrained model
model.load_state_dict(new_pretrained_state)

# Generate Plugin
num_samples = 1  # params['n_samples']
sample_length = params['sample_length']
sample_rate = params['sample_rate']
sampling_temperature = params['sampling_temperature']

# Override from our options
sample_length = sample_rate * int(options.length)

print("Number samples: {}, sample_length: {}, sample_rate: {}".format(num_samples, sample_length, sample_rate))
print("Generating %d seconds of audio" % (sample_length / sample_rate))
generator = GeneratorPlugin(GENERATED_PATH, num_samples, sample_length, sample_rate, sampling_temperature)

# Call new register function to accept the trained model and the cuda setting
generator.register_generate(model.cuda(), params['cuda'])

# Generate new audio
# $$$ check if we already have generated audio and increment the file name
generator.epoch(OUTPUT_NAME)
GENERATED_FILEPATH = GENERATED_PATH + "ep" + OUTPUT_NAME + "-s1.wav"
print("Saved audio to %s " % GENERATED_FILEPATH)

if options.output:
    print("Moving to %s" % options.output)
    os.rename(GENERATED_FILEPATH, options.output)