Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions inference/ds_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,15 @@ def preprocess_input(
batch['midi'] = ph_midi

if load_pitch:
# Interpolate unvoiced parts before resampling.
f0 = resample_align_curve(
np.array(param['f0_seq'].split(), np.float32),
interp_f0(np.array(param['f0_seq'].split(), np.float32))[0],
original_timestep=float(param['f0_timestep']),
target_timestep=self.timestep,
align_length=T_s
)
batch['pitch'] = torch.from_numpy(
librosa.hz_to_midi(interp_f0(f0)[0]).astype(np.float32)
librosa.hz_to_midi(f0).astype(np.float32)
).to(self.device)[None]

if self.model.predict_dur:
Expand Down Expand Up @@ -442,19 +443,18 @@ def run_inference(
param_copy[f'{v_name}_timestep'] = str(self.timestep)

# Restore ph_spk_mix and spk_mix
if 'ph_spk_mix' in param_copy and 'spk_mix' in param_copy:
if 'ph_spk_mix_backup' in param_copy:
if param_copy['ph_spk_mix_backup'] is None:
del param_copy['ph_spk_mix']
else:
param_copy['ph_spk_mix'] = param_copy['ph_spk_mix_backup']
del param['ph_spk_mix_backup']
if 'spk_mix_backup' in param_copy:
if param_copy['ph_spk_mix_backup'] is None:
del param_copy['spk_mix']
else:
param_copy['spk_mix'] = param_copy['spk_mix_backup']
del param['spk_mix_backup']
if 'ph_spk_mix_backup' in param_copy:
if param_copy['ph_spk_mix_backup'] is None:
param_copy.pop('ph_spk_mix', None)
else:
param_copy['ph_spk_mix'] = param_copy['ph_spk_mix_backup']
del param_copy['ph_spk_mix_backup']
if 'spk_mix_backup' in param_copy:
if param_copy['spk_mix_backup'] is None:
param_copy.pop('spk_mix', None)
else:
param_copy['spk_mix'] = param_copy['spk_mix_backup']
del param_copy['spk_mix_backup']

results.append(param_copy)

Expand Down
5 changes: 4 additions & 1 deletion modules/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ def forward(
return dur_pred_out, pitch_pred_out, ({} if infer else None)

if pitch is None:
pitch = base_pitch + pitch_pred_out
if pitch_pred_out is not None:
pitch = base_pitch + pitch_pred_out
else:
pitch = base_pitch
if self.use_variance_scaling:
var_cond = condition + self.pitch_embed(pitch[:, :, None] / 12)
else:
Expand Down
5 changes: 3 additions & 2 deletions preprocessing/acoustic_binarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def arrange_data_augmentation(self, data_iterator):
k_from_aug = int(total_scale * scale / (1 + total_scale) * len(all_item_names))
k_mutate = int(total_scale * scale / (1 + scale) * len(all_item_names))
aug_types = [0] * k_from_raw + [1] * k_from_aug + [2] * k_mutate
aug_items = random.choices(all_item_names, k=k_from_raw) + random.choices(aug_list, k=k_from_aug + k_mutate)
aug_items = random.choices(all_item_names, k=k_from_raw) + \
random.choices(aug_list, k=k_from_aug) + random.sample(aug_list, k=min(k_mutate, len(aug_list)))

for aug_type, aug_item in zip(aug_types, aug_items):
# Uniform distribution in log domain
Expand All @@ -337,7 +338,7 @@ def arrange_data_augmentation(self, data_iterator):
aug_list.append(aug_task)
elif aug_type == 1:
aug_task = {
'name': aug_item,
'name': aug_item['name'],
'func': aug_item['func'],
'kwargs': deepcopy(aug_item['kwargs'])
}
Expand Down
15 changes: 11 additions & 4 deletions preprocessing/variance_binarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,21 @@ def process_item(self, item_name, meta_data, binarization_args):
if self.prefer_ds:
f0_seq = self.load_attr_from_ds(ds_id, name, 'f0_seq', idx=ds_seg_idx)
if f0_seq is not None:
f0_timestep = float(self.load_attr_from_ds(ds_id, name, 'f0_timestep', idx=ds_seg_idx))
# Interpolate unvoiced parts before resampling.
f0_points, uv_points = interp_f0(np.array(f0_seq.split(), np.float32))
f0 = resample_align_curve(
np.array(f0_seq.split(), np.float32),
original_timestep=float(self.load_attr_from_ds(ds_id, name, 'f0_timestep', idx=ds_seg_idx)),
f0_points,
original_timestep=f0_timestep,
target_timestep=self.timestep,
align_length=length
)
uv = f0 == 0
f0, _ = interp_f0(f0, uv)
uv = resample_align_curve(
uv_points.astype(np.float32),
original_timestep=f0_timestep,
target_timestep=self.timestep,
align_length=length
) > 0.5
if f0 is None:
f0, uv = pitch_extractor.get_pitch(
waveform, samplerate=hparams['audio_sample_rate'], length=length,
Expand Down
2 changes: 1 addition & 1 deletion utils/decomposed_waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _init(
# extraction parameters
self._hop_size = hop_size
self._fft_size = fft_size if fft_size is not None else win_size
self._win_size = win_size if win_size is not None else win_size
self._win_size = win_size if win_size is not None else fft_size
self._time_step = hop_size / samplerate
self._half_width = base_harmonic_radius
self._device = ('cuda' if torch.cuda.is_available() else 'cpu') if device is None else device
Expand Down
8 changes: 1 addition & 7 deletions utils/infer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ def trans_key(raw_data, key):


def resample_align_curve(points: np.ndarray, original_timestep: float, target_timestep: float, align_length: int):
t_max = (len(points) - 1) * original_timestep
curve_interp = np.interp(
np.arange(0, t_max, target_timestep),
np.arange(align_length) * target_timestep,
original_timestep * np.arange(len(points)),
points
).astype(points.dtype)
delta_l = align_length - len(curve_interp)
if delta_l < 0:
curve_interp = curve_interp[:align_length]
elif delta_l > 0:
curve_interp = np.concatenate((curve_interp, np.full(delta_l, fill_value=curve_interp[-1])), axis=0)
return curve_interp


Expand Down