本文整理汇总了Python中hparams.hparams_debug_string方法的典型用法代码示例。如果您正苦于以下问题:Python hparams.hparams_debug_string方法的具体用法?Python hparams.hparams_debug_string怎么用?Python hparams.hparams_debug_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hparams
的用法示例。
在下文中一共展示了hparams.hparams_debug_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_eval
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_eval(args, checkpoint_path, output_dir):
print(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path)
eval_dir = os.path.join(output_dir, 'eval')
log_dir = os.path.join(output_dir, 'logs-eval')
wav = load_wav(args.reference_audio)
reference_mel = melspectrogram(wav).transpose()
#Create output path if it doesn't exist
os.makedirs(eval_dir, exist_ok=True)
os.makedirs(log_dir, exist_ok=True)
os.makedirs(os.path.join(log_dir, 'wavs'), exist_ok=True)
os.makedirs(os.path.join(log_dir, 'plots'), exist_ok=True)
with open(os.path.join(eval_dir, 'map.txt'), 'w') as file:
for i, text in enumerate(tqdm(hparams.sentences)):
start = time.time()
mel_filename = synth.synthesize(text, i+1, eval_dir, log_dir, None, reference_mel)
file.write('{}|{}\n'.format(text, mel_filename))
print('synthesized mel spectrograms at {}'.format(eval_dir))
示例2: run_live
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_live(args, checkpoint_path, hparams):
#Log to Terminal without keeping any records in files
log(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, hparams)
#Generate fast greeting message
greetings = 'Hello, Welcome to the Live testing tool. Please type a message and I will try to read it!'
log(greetings)
generate_fast(synth, greetings)
#Interaction loop
while True:
try:
text = input()
generate_fast(synth, text)
except KeyboardInterrupt:
leave = 'Thank you for testing our features. see you soon.'
log(leave)
generate_fast(synth, leave)
sleep(2)
break
示例3: run_eval
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_eval(args, checkpoint_path, output_dir, hparams, sentences):
eval_dir = os.path.join(output_dir, 'eval')
log_dir = os.path.join(output_dir, 'logs-eval')
if args.model == 'Tacotron-2':
assert os.path.normpath(eval_dir) == os.path.normpath(args.mels_dir) #mels_dir = wavenet_input_dir
#Create output path if it doesn't exist
os.makedirs(eval_dir, exist_ok=True)
os.makedirs(log_dir, exist_ok=True)
os.makedirs(os.path.join(log_dir, 'wavs'), exist_ok=True)
os.makedirs(os.path.join(log_dir, 'plots'), exist_ok=True)
log(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, hparams)
delta_size = hparams.tacotron_synthesis_batch_size if hparams.tacotron_synthesis_batch_size < len(sentences) else len(sentences)
batch_sentences = [sentences[i: i+hparams.tacotron_synthesis_batch_size] for i in range(0, len(sentences), delta_size)]
start = time.time()
for i, batch in enumerate(tqdm(batch_sentences)):
audio.save_wav(synth.eval(batch), os.path.join(log_dir, 'wavs', 'eval_batch_{:03}.wav'.format(i)), hparams)
log('\nGenerated total batch of {} in {:.3f} sec'.format(delta_size, time.time() - start))
return eval_dir
示例4: main
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def main():
args = docopt(__doc__)
print("Command line args:\n", args)
checkpoint_dir = args["--checkpoint-dir"]
postnet_checkpoint_dir = args["--postnet-checkpoint-dir"]
data_root = args["--data-root"]
dataset_name = args["--dataset"]
assert dataset_name in ["blizzard2012"]
corpus = importlib.import_module("datasets." + dataset_name)
corpus_instance = corpus.instantiate(in_dir="", out_dir=data_root)
hparams.parse(args["--hparams"])
print(hparams_debug_string())
tf.logging.set_verbosity(tf.logging.INFO)
predict(hparams,
checkpoint_dir,
postnet_checkpoint_dir,
corpus_instance.test_source_files,
corpus_instance.test_target_files, )
示例5: main
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def main():
args = docopt(__doc__)
print("Command line args:\n", args)
checkpoint_dir = args["--checkpoint-dir"]
data_root = args["--data-root"]
dataset_name = args["--dataset"]
assert dataset_name in ["blizzard2012", "ljspeech"]
corpus = importlib.import_module("datasets." + dataset_name)
corpus_instance = corpus.instantiate(in_dir="", out_dir=data_root)
hparams.parse(args["--hparams"])
print(hparams_debug_string())
tf.logging.set_verbosity(tf.logging.INFO)
train_and_evaluate(hparams,
checkpoint_dir,
corpus_instance.training_target_files,
corpus_instance.validation_target_files)
示例6: main
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def main():
args = docopt(__doc__)
print("Command line args:\n", args)
checkpoint_dir = args["--checkpoint-dir"]
data_root = args["--data-root"]
dataset_name = args["--dataset"]
assert dataset_name in ["blizzard2012", "ljspeech"]
corpus = importlib.import_module("datasets." + dataset_name)
corpus_instance = corpus.instantiate(in_dir="", out_dir=data_root)
hparams.parse(args["--hparams"])
print(hparams_debug_string())
tf.logging.set_verbosity(tf.logging.INFO)
train_and_evaluate(hparams,
checkpoint_dir,
corpus_instance.training_source_files,
corpus_instance.training_target_files,
corpus_instance.validation_source_files,
corpus_instance.validation_target_files)
示例7: run_eval
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_eval(args):
print(hparams_debug_string())
synth = Synthesizer()
synth.load(args.checkpoint)
base_path = get_output_base_path(args.checkpoint)
wav = load_wav(args.reference_audio)
mel = melspectrogram(wav).transpose()
for i, text in enumerate(tests):
path = '%s-%d.wav' % (base_path, i)
print('Synthesizing: %s' % path)
with open(path, 'wb') as f:
f.write(synth.synthesize(text, mel))
示例8: run_synthesis
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_synthesis(args, checkpoint_path, output_dir):
metadata_filename = os.path.join(args.input_dir, 'train.txt')
print(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, gta=args.GTA)
with open(metadata_filename, encoding='utf-8') as f:
metadata = [line.strip().split('|') for line in f]
frame_shift_ms = hparams.hop_size / hparams.sample_rate
hours = sum([int(x[4]) for x in metadata]) * frame_shift_ms / (3600)
print('Loaded metadata for {} examples ({:.2f} hours)'.format(len(metadata), hours))
if args.GTA==True:
synth_dir = os.path.join(output_dir, 'gta')
else:
synth_dir = os.path.join(output_dir, 'natural')
#Create output path if it doesn't exist
os.makedirs(synth_dir, exist_ok=True)
print('starting synthesis')
mel_dir = os.path.join(args.input_dir, 'mels')
wav_dir = os.path.join(args.input_dir, 'audio')
with open(os.path.join(synth_dir, 'map.txt'), 'w') as file:
for i, meta in enumerate(tqdm(metadata)):
text = meta[5]
mel_filename = os.path.join(mel_dir, meta[1])
wav_filename = os.path.join(wav_dir, meta[0])
mel_output_filename = synth.synthesize(text, None, i+1, synth_dir, None, mel_filename)
file.write('{}|{}|{}|{}\n'.format(text, mel_filename, mel_output_filename, wav_filename))
print('synthesized mel spectrograms at {}'.format(synth_dir))
示例9: run_eval
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_eval(args):
print(hparams_debug_string())
synth = Synthesizer()
synth.load(args.checkpoint)
base_path = get_output_base_path(args.checkpoint)
for i, text in enumerate(sentences):
path = '%s-%d.wav' % (base_path, i)
print('Synthesizing: %s' % path)
with open(path, 'wb') as f:
f.write(synth.synthesize(text))
示例10: run_eval
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_eval(args, checkpoint_path, output_dir, hparams, sentences):
eval_dir = os.path.join(output_dir, 'eval')
log_dir = os.path.join(output_dir, 'logs-eval')
if args.model == 'Tacotron-2':
assert os.path.normpath(eval_dir) == os.path.normpath(args.mels_dir)
#Create output path if it doesn't exist
os.makedirs(eval_dir, exist_ok=True)
os.makedirs(log_dir, exist_ok=True)
os.makedirs(os.path.join(log_dir, 'wavs'), exist_ok=True)
os.makedirs(os.path.join(log_dir, 'plots'), exist_ok=True)
log(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, hparams)
#Set inputs batch wise
sentences = [sentences[i: i+hparams.tacotron_synthesis_batch_size] for i in range(0, len(sentences), hparams.tacotron_synthesis_batch_size)]
log('Starting Synthesis')
with open(os.path.join(eval_dir, 'map.txt'), 'w') as file:
for i, texts in enumerate(tqdm(sentences)):
start = time.time()
basenames = ['batch_{}_sentence_{}'.format(i, j) for j in range(len(texts))]
mel_filenames, speaker_ids = synth.synthesize(texts, basenames, eval_dir, log_dir, None)
for elems in zip(texts, mel_filenames, speaker_ids):
file.write('|'.join([str(x) for x in elems]) + '\n')
log('synthesized mel spectrograms at {}'.format(eval_dir))
return eval_dir
示例11: run_synthesis
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_synthesis(args, checkpoint_path, output_dir, hparams):
GTA = (args.GTA == 'True')
if GTA:
synth_dir = os.path.join(output_dir, 'gta')
#Create output path if it doesn't exist
os.makedirs(synth_dir, exist_ok=True)
else:
synth_dir = os.path.join(output_dir, 'natural')
#Create output path if it doesn't exist
os.makedirs(synth_dir, exist_ok=True)
metadata_filename = os.path.join(args.input_dir, 'train.txt')
log(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, hparams, gta=GTA)
with open(metadata_filename, encoding='utf-8') as f:
metadata = [line.strip().split('|') for line in f]
frame_shift_ms = hparams.hop_size / hparams.sample_rate
hours = sum([int(x[4]) for x in metadata]) * frame_shift_ms / (3600)
log('Loaded metadata for {} examples ({:.2f} hours)'.format(len(metadata), hours))
metadata = [metadata[i: i+hparams.tacotron_synthesis_batch_size] for i in range(0, len(metadata), hparams.tacotron_synthesis_batch_size)]
log('starting synthesis')
mel_dir = os.path.join(args.input_dir, 'mels')
wav_dir = os.path.join(args.input_dir, 'audio')
with open(os.path.join(synth_dir, 'map.txt'), 'w') as file:
for i, meta in enumerate(tqdm(metadata)):
texts = [m[5] for m in meta]
mel_filenames = [os.path.join(mel_dir, m[1]) for m in meta]
wav_filenames = [os.path.join(wav_dir, m[0]) for m in meta]
basenames = [os.path.basename(m).replace('.npy', '').replace('mel-', '') for m in mel_filenames]
mel_output_filenames, speaker_ids = synth.synthesize(texts, basenames, synth_dir, None, mel_filenames)
for elems in zip(wav_filenames, mel_filenames, mel_output_filenames, speaker_ids, texts):
file.write('|'.join([str(x) for x in elems]) + '\n')
log('synthesized mel spectrograms at {}'.format(synth_dir))
return os.path.join(synth_dir, 'map.txt')
示例12: main
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def main():
args = docopt(__doc__)
print("Command line args:\n", args)
checkpoint_dir = args["--checkpoint-dir"]
checkpoint_path = args["--checkpoint"]
source_data_root = args["--source-data-root"]
target_data_root = args["--target-data-root"]
selected_list_dir = args["--selected-list-dir"]
output_dir = args["--output-dir"]
selected_list_filename = args["--selected-list-filename"] or "test.csv"
tf.logging.set_verbosity(tf.logging.INFO)
if args["--hparam-json-file"]:
with open(args["--hparam-json-file"]) as f:
json = "".join(f.readlines())
hparams.parse_json(json)
hparams.parse(args["--hparams"])
tf.logging.info(hparams_debug_string())
tf.logging.info(f"A selected list file to use: {os.path.join(selected_list_dir, selected_list_filename)}")
test_list = list(load_key_list(selected_list_filename, selected_list_dir))
test_source_files = [os.path.join(source_data_root, f"{key}.{hparams.source_file_extension}") for key in
test_list]
test_target_files = [os.path.join(target_data_root, f"{key}.{hparams.target_file_extension}") for key in
test_list]
predict(hparams,
checkpoint_dir,
checkpoint_path,
output_dir,
test_source_files,
test_target_files)
示例13: run_synthesis
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_synthesis(args, checkpoint_path, output_dir, hparams):
log_dir = os.path.join(output_dir, 'plots')
wav_dir = os.path.join(output_dir, 'wavs')
#We suppose user will provide correct folder depending on training method
log(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, hparams)
if args.model == 'Tacotron-2':
#If running all Tacotron-2, synthesize audio from evaluated mels
metadata_filename = os.path.join(args.mels_dir, 'map.txt')
with open(metadata_filename, encoding='utf-8') as f:
metadata = np.array([line.strip().split('|') for line in f])
speaker_ids = metadata[:, 2]
mel_files = metadata[:, 1]
texts = metadata[:, 0]
speaker_ids = None if (speaker_ids == '<no_g>').all() else speaker_ids
else:
#else Get all npy files in input_dir (supposing they are mels)
mel_files = sorted([os.path.join(args.mels_dir, f) for f in os.listdir(args.mels_dir) if f.split('.')[-1] == 'npy'])
speaker_ids = None if args.speaker_id is None else args.speaker_id.replace(' ', '').split(',')
if speaker_ids is not None:
assert len(speaker_ids) == len(mel_files)
texts = None
log('Starting synthesis! (this will take a while..)')
os.makedirs(log_dir, exist_ok=True)
os.makedirs(wav_dir, exist_ok=True)
mel_files = [mel_files[i: i+hparams.wavenet_synthesis_batch_size] for i in range(0, len(mel_files), hparams.wavenet_synthesis_batch_size)]
speaker_ids = None if speaker_ids is None else [speaker_ids[i: i+hparams.wavenet_synthesis_batch_size] for i in range(0, len(speaker_ids), hparams.wavenet_synthesis_batch_size)]
texts = None if texts is None else [texts[i: i+hparams.wavenet_synthesis_batch_size] for i in range(0, len(texts), hparams.wavenet_synthesis_batch_size)]
with open(os.path.join(wav_dir, 'map.txt'), 'w') as file:
for i, mel_batch in enumerate(tqdm(mel_files)):
mel_spectros = [np.load(mel_file) for mel_file in mel_batch]
basenames = [os.path.basename(mel_file).replace('.npy', '') for mel_file in mel_batch]
speaker_id_batch = None if speaker_ids is None else speaker_ids[i]
audio_files = synth.synthesize(mel_spectros, speaker_id_batch, basenames, wav_dir, log_dir)
speaker_logs = ['<no_g>'] * len(mel_batch) if speaker_id_batch is None else speaker_id_batch
for j, mel_file in enumerate(mel_batch):
if texts is None:
file.write('{}|{}\n'.format(mel_file, audio_files[j], speaker_logs[j]))
else:
file.write('{}|{}|{}\n'.format(texts[i][j], mel_file, audio_files[j], speaker_logs[j]))
log('synthesized audio waveforms at {}'.format(wav_dir))
示例14: run_synthesis
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def run_synthesis(args, checkpoint_path, output_dir, hparams):
GTA = (args.GTA == 'True')
if GTA:
synth_dir = os.path.join(output_dir, 'gta')
#Create output path if it doesn't exist
os.makedirs(synth_dir, exist_ok=True)
else:
synth_dir = os.path.join(output_dir, 'natural')
#Create output path if it doesn't exist
os.makedirs(synth_dir, exist_ok=True)
metadata_filename = os.path.join(args.input_dir, 'train.txt')
log(hparams_debug_string())
synth = Synthesizer()
synth.load(checkpoint_path, hparams, gta=GTA)
with open(metadata_filename, encoding='utf-8') as f:
metadata = [line.strip().split('|') for line in f]
frame_shift_ms = hparams.hop_size / hparams.sample_rate
hours = sum([int(x[4]) for x in metadata]) * frame_shift_ms / (3600)
log('Loaded metadata for {} examples ({:.2f} hours)'.format(len(metadata), hours))
#Set inputs batch wise
metadata = [metadata[i: i+hparams.tacotron_synthesis_batch_size] for i in range(0, len(metadata), hparams.tacotron_synthesis_batch_size)]
log('Starting Synthesis')
mel_dir = os.path.join(args.input_dir, 'mels')
wav_dir = os.path.join(args.input_dir, 'audio')
with open(os.path.join(synth_dir, 'map.txt'), 'w') as file:
for i, meta in enumerate(tqdm(metadata)):
texts = [m[5] for m in meta]
mel_filenames = [os.path.join(mel_dir, m[1]) for m in meta]
wav_filenames = [os.path.join(wav_dir, m[0]) for m in meta]
basenames = [os.path.basename(m).replace('.npy', '').replace('mel-', '') for m in mel_filenames]
mel_output_filenames, speaker_ids = synth.synthesize(texts, basenames, synth_dir, None, mel_filenames)
for elems in zip(wav_filenames, mel_filenames, mel_output_filenames, speaker_ids, texts):
file.write('|'.join([str(x) for x in elems]) + '\n')
log('synthesized mel spectrograms at {}'.format(synth_dir))
return os.path.join(synth_dir, 'map.txt')
示例15: main
# 需要导入模块: import hparams [as 别名]
# 或者: from hparams import hparams_debug_string [as 别名]
def main():
args = docopt(__doc__)
print("Command line args:\n", args)
checkpoint_dir = args["--checkpoint-dir"]
source_data_root = args["--source-data-root"]
target_data_root = args["--target-data-root"]
selected_list_dir = args["--selected-list-dir"]
use_multi_gpu = args["--multi-gpus"]
if args["--hparam-json-file"]:
with open(args["--hparam-json-file"]) as f:
json = "".join(f.readlines())
hparams.parse_json(json)
hparams.parse(args["--hparams"])
training_list = list(load_key_list("train.csv", selected_list_dir))
validation_list = list(load_key_list("validation.csv", selected_list_dir))
training_source_files = [os.path.join(source_data_root, f"{key}.{hparams.source_file_extension}") for key in
training_list]
training_target_files = [os.path.join(target_data_root, f"{key}.{hparams.target_file_extension}") for key in
training_list]
validation_source_files = [os.path.join(source_data_root, f"{key}.{hparams.source_file_extension}") for key in
validation_list]
validation_target_files = [os.path.join(target_data_root, f"{key}.{hparams.target_file_extension}") for key in
validation_list]
log = logging.getLogger("tensorflow")
log.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh = logging.FileHandler(hparams.logfile)
fh.setLevel(logging.INFO)
fh.setFormatter(formatter)
log.addHandler(fh)
tf.logging.set_verbosity(tf.logging.INFO)
tf.logging.info(hparams_debug_string())
train_and_evaluate(hparams,
checkpoint_dir,
training_source_files,
training_target_files,
validation_source_files,
validation_target_files,
use_multi_gpu)