MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / add_f0_loss

Method add_f0_loss

tasks/tts/fs2.py:254–269  ·  view source on GitHub ↗
(self, p_pred, f0, uv, losses, nonpadding)

Source from the content-addressed store, hash-verified

252 self.add_f0_loss(output['pitch_pred'], f0, uv, losses, nonpadding=nonpadding)
253
254 def add_f0_loss(self, p_pred, f0, uv, losses, nonpadding):
255 assert p_pred[..., 0].shape == f0.shape
256 if hparams['use_uv']:
257 assert p_pred[..., 1].shape == uv.shape
258 losses['uv'] = (F.binary_cross_entropy_with_logits(
259 p_pred[:, :, 1], uv, reduction='none') * nonpadding).sum() \
260 / nonpadding.sum() * hparams['lambda_uv']
261 nonpadding = nonpadding * (uv == 0).float()
262
263 f0_pred = p_pred[:, :, 0]
264 if hparams['pitch_loss'] in ['l1', 'l2']:
265 pitch_loss_fn = F.l1_loss if hparams['pitch_loss'] == 'l1' else F.mse_loss
266 losses['f0'] = (pitch_loss_fn(f0_pred, f0, reduction='none') * nonpadding).sum() \
267 / nonpadding.sum() * hparams['lambda_f0']
268 elif hparams['pitch_loss'] == 'ssim':
269 return NotImplementedError
270
271 def cwt_loss(self, cwt_p, cwt_g):
272 if hparams['cwt_loss'] == 'l1':

Callers 2

add_pitch_lossMethod · 0.95
add_pitch_lossMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected