-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【Hackathon 8th No.9】在 PaddleSpeech 中复现 DAC 训练需要用到的 loss #3954
base: develop
Are you sure you want to change the base?
Changes from all commits
2c04e0a
b741545
37f60d6
c1a8f99
fd5365c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import torch | ||
from paddleaudio.audiotools.core.audio_signal import AudioSignal | ||
|
||
from paddlespeech.t2s.modules.losses import MultiMelSpectrogramLoss | ||
from paddlespeech.t2s.modules.losses import MultiScaleSTFTLoss | ||
|
||
|
||
def test_dac_losses(): | ||
for i in range(10): | ||
loss_origin = torch.load(f'tests/unit/tts/data/{i}-loss.pt') | ||
recons = AudioSignal(f'tests/unit/tts/data/{i}-recons.wav') | ||
signal = AudioSignal(f'tests/unit/tts/data/{i}-signal.wav') | ||
|
||
recons.audio_data.stop_gradient = False | ||
signal.audio_data.stop_gradient = False | ||
|
||
loss_fn_1 = MultiScaleSTFTLoss() | ||
loss_fn_2 = MultiMelSpectrogramLoss( | ||
n_mels=[5, 10, 20, 40, 80, 160, 320], | ||
window_lengths=[32, 64, 128, 256, 512, 1024, 2048], | ||
mag_weight=0.0, | ||
pow=1.0, | ||
mel_fmin=[0, 0, 0, 0, 0, 0, 0], | ||
mel_fmax=[None, None, None, None, None, None, None]) | ||
|
||
# | ||
# Test AudioSignal | ||
# | ||
|
||
loss_1 = loss_fn_1(recons, signal) | ||
loss_1.backward() | ||
loss_1_grad = signal.audio_data.grad.sum() | ||
|
||
assert abs( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently not. After debugging, I find out that the loss is generated by 'paddle.signal.stft' (without cuda), so I have to compare the implement with '_VF' and paddle. I'm sure that the loss can decrease to 0 if fixing this |
||
(loss_1.item() - loss_origin['stft/loss'].item()) / | ||
loss_1.item()) < 1e-5, r"value incorrect for 'MultiScaleSTFTLoss'" | ||
assert abs( | ||
(loss_1_grad.item() - loss_origin['stft/grad'].sum().item() | ||
) / loss_1_grad. | ||
item()) < 1e-5, r"gradient incorrect for 'MultiScaleSTFTLoss'" | ||
|
||
signal.audio_data.clear_grad() | ||
recons.audio_data.clear_grad() | ||
|
||
loss_2 = loss_fn_2(recons, signal) | ||
loss_2.backward() | ||
loss_2_grad = signal.audio_data.grad.sum() | ||
|
||
assert abs( | ||
(loss_2.item() - loss_origin['mel/loss'].item()) / loss_2. | ||
item()) < 1e-5, r"value incorrect for 'MultiMelSpectrogramLoss'" | ||
assert abs( | ||
(signal.audio_data.grad.sum().item() - | ||
loss_origin['mel/grad'].sum().item()) / loss_2_grad. | ||
item()) < 1e-5, r"gradient incorrect for 'MultiMelSpectrogramLoss'" | ||
|
||
signal.audio_data.clear_grad() | ||
recons.audio_data.clear_grad() | ||
|
||
# | ||
# Test Tensor | ||
# | ||
|
||
loss_1 = loss_fn_1(recons.audio_data, signal.audio_data) | ||
loss_1.backward() | ||
loss_1_grad = signal.audio_data.grad.sum() | ||
|
||
assert abs(loss_1.item() - loss_origin['stft/loss'].item( | ||
)) / loss_1.item() < 1e-5, r"value incorrect for 'MultiScaleSTFTLoss'" | ||
assert abs(loss_1_grad.item() - loss_origin['stft/grad'].sum() | ||
.item()) / loss_1_grad.item( | ||
) < 1e-5, r"gradient incorrect for 'MultiScaleSTFTLoss'" | ||
|
||
signal.audio_data.clear_grad() | ||
recons.audio_data.clear_grad() | ||
|
||
loss_2 = loss_fn_2(recons.audio_data, signal.audio_data) | ||
loss_2.backward() | ||
loss_2_grad = signal.audio_data.grad.sum() | ||
|
||
assert abs( | ||
(loss_2.item() - loss_origin['mel/loss'].item()) / loss_2. | ||
item()) < 1e-5, r"value incorrect for 'MultiMelSpectrogramLoss'" | ||
assert abs( | ||
(loss_2_grad.item() - loss_origin['mel/grad'].sum().item() | ||
) / loss_2_grad. | ||
item()) < 1e-5, r"gradient incorrect for 'MultiMelSpectrogramLoss'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
miss SISDRLoss?