CoolFace
Apppublic

RabbitRUI/ruispace

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
hparams.py161 linesDownload Raw Back to utils
1from glob import glob2import os3 4class HParams:5	def __init__(self, **kwargs):6		self.data = {}7 8		for key, value in kwargs.items():9			self.data[key] = value10 11	def __getattr__(self, key):12		if key not in self.data:13			raise AttributeError("'HParams' object has no attribute %s" % key)14		return self.data[key]15 16	def set_hparam(self, key, value):17		self.data[key] = value18 19 20# Default hyperparameters21hparams = HParams(22	num_mels=80,  # Number of mel-spectrogram channels and local conditioning dimensionality23	#  network24	rescale=True,  # Whether to rescale audio prior to preprocessing25	rescaling_max=0.9,  # Rescaling value26	27	# Use LWS (https://github.com/Jonathan-LeRoux/lws) for STFT and phase reconstruction28	# It"s preferred to set True to use with https://github.com/r9y9/wavenet_vocoder29	# Does not work if n_ffit is not multiple of hop_size!!30	use_lws=False,31	32	n_fft=800,  # Extra window size is filled with 0 paddings to match this parameter33	hop_size=200,  # For 16000Hz, 200 = 12.5 ms (0.0125 * sample_rate)34	win_size=800,  # For 16000Hz, 800 = 50 ms (If None, win_size = n_fft) (0.05 * sample_rate)35	sample_rate=16000,  # 16000Hz (corresponding to librispeech) (sox --i <filename>)36	37	frame_shift_ms=None,  # Can replace hop_size parameter. (Recommended: 12.5)38	39	# Mel and Linear spectrograms normalization/scaling and clipping40	signal_normalization=True,41	# Whether to normalize mel spectrograms to some predefined range (following below parameters)42	allow_clipping_in_normalization=True,  # Only relevant if mel_normalization = True43	symmetric_mels=True,44	# Whether to scale the data to be symmetric around 0. (Also multiplies the output range by 2, 45	# faster and cleaner convergence)46	max_abs_value=4.,47	# max absolute value of data. If symmetric, data will be [-max, max] else [0, max] (Must not 48	# be too big to avoid gradient explosion, 49	# not too small for fast convergence)50	# Contribution by @begeekmyfriend51	# Spectrogram Pre-Emphasis (Lfilter: Reduce spectrogram noise and helps model certitude 52	# levels. Also allows for better G&L phase reconstruction)53	preemphasize=True,  # whether to apply filter54	preemphasis=0.97,  # filter coefficient.55	56	# Limits57	min_level_db=-100,58	ref_level_db=20,59	fmin=55,60	# Set this to 55 if your speaker is male! if female, 95 should help taking off noise. (To 61	# test depending on dataset. Pitch info: male~[65, 260], female~[100, 525])62	fmax=7600,  # To be increased/reduced depending on data.63 64	###################### Our training parameters #################################65	img_size=96,66	fps=25,67	68	batch_size=16,69	initial_learning_rate=1e-4,70	nepochs=300000,  ### ctrl + c, stop whenever eval loss is consistently greater than train loss for ~10 epochs71	num_workers=20,72	checkpoint_interval=3000,73	eval_interval=3000,74	writer_interval=300,75    save_optimizer_state=True,76 77    syncnet_wt=0.0, # is initially zero, will be set automatically to 0.03 later. Leads to faster convergence. 78	syncnet_batch_size=64,79	syncnet_lr=1e-4,80	syncnet_eval_interval=1000,81	syncnet_checkpoint_interval=10000,82 83	disc_wt=0.07,84	disc_initial_learning_rate=1e-4,85)86 87 88 89# Default hyperparameters90hparamsdebug = HParams(91	num_mels=80,  # Number of mel-spectrogram channels and local conditioning dimensionality92	#  network93	rescale=True,  # Whether to rescale audio prior to preprocessing94	rescaling_max=0.9,  # Rescaling value95	96	# Use LWS (https://github.com/Jonathan-LeRoux/lws) for STFT and phase reconstruction97	# It"s preferred to set True to use with https://github.com/r9y9/wavenet_vocoder98	# Does not work if n_ffit is not multiple of hop_size!!99	use_lws=False,100	101	n_fft=800,  # Extra window size is filled with 0 paddings to match this parameter102	hop_size=200,  # For 16000Hz, 200 = 12.5 ms (0.0125 * sample_rate)103	win_size=800,  # For 16000Hz, 800 = 50 ms (If None, win_size = n_fft) (0.05 * sample_rate)104	sample_rate=16000,  # 16000Hz (corresponding to librispeech) (sox --i <filename>)105	106	frame_shift_ms=None,  # Can replace hop_size parameter. (Recommended: 12.5)107	108	# Mel and Linear spectrograms normalization/scaling and clipping109	signal_normalization=True,110	# Whether to normalize mel spectrograms to some predefined range (following below parameters)111	allow_clipping_in_normalization=True,  # Only relevant if mel_normalization = True112	symmetric_mels=True,113	# Whether to scale the data to be symmetric around 0. (Also multiplies the output range by 2, 114	# faster and cleaner convergence)115	max_abs_value=4.,116	# max absolute value of data. If symmetric, data will be [-max, max] else [0, max] (Must not 117	# be too big to avoid gradient explosion, 118	# not too small for fast convergence)119	# Contribution by @begeekmyfriend120	# Spectrogram Pre-Emphasis (Lfilter: Reduce spectrogram noise and helps model certitude 121	# levels. Also allows for better G&L phase reconstruction)122	preemphasize=True,  # whether to apply filter123	preemphasis=0.97,  # filter coefficient.124	125	# Limits126	min_level_db=-100,127	ref_level_db=20,128	fmin=55,129	# Set this to 55 if your speaker is male! if female, 95 should help taking off noise. (To 130	# test depending on dataset. Pitch info: male~[65, 260], female~[100, 525])131	fmax=7600,  # To be increased/reduced depending on data.132 133	###################### Our training parameters #################################134	img_size=96,135	fps=25,136	137	batch_size=2,138	initial_learning_rate=1e-3,139	nepochs=100000,  ### ctrl + c, stop whenever eval loss is consistently greater than train loss for ~10 epochs140	num_workers=0,141	checkpoint_interval=10000,142	eval_interval=10,143	writer_interval=5,144    save_optimizer_state=True,145 146    syncnet_wt=0.0, # is initially zero, will be set automatically to 0.03 later. Leads to faster convergence. 147	syncnet_batch_size=64,148	syncnet_lr=1e-4,149	syncnet_eval_interval=10000,150	syncnet_checkpoint_interval=10000,151 152	disc_wt=0.07,153	disc_initial_learning_rate=1e-4,154)155 156 157def hparams_debug_string():158	values = hparams.values()159	hp = ["  %s: %s" % (name, values[name]) for name in sorted(values) if name != "sentences"]160	return "Hyperparameters:\n" + "\n".join(hp)161