-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
add causal option for HiFiGAN #326
Conversation
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.
Thank you for your contribution!
I have several requests:
- Could you fix the CI errors?
- Could you add the test code for causal calculation?
Example test code:
ParallelWaveGAN/test/test_parallel_wavegan.py
Lines 310 to 354 in edf35dd
def test_causal_parallel_wavegan(upsample_net, aux_context_window): | |
batch_size = 1 | |
batch_length = 4096 | |
args_g = make_generator_args( | |
use_causal_conv=True, | |
upsample_net=upsample_net, | |
aux_context_window=aux_context_window, | |
dropout=0.0, | |
) | |
model_g = ParallelWaveGANGenerator(**args_g) | |
z = torch.randn(batch_size, 1, batch_length) | |
c = torch.randn( | |
batch_size, | |
args_g["aux_channels"], | |
batch_length // np.prod(args_g["upsample_params"]["upsample_scales"]), | |
) | |
z_ = z.clone() | |
c_ = c.clone() | |
z_[..., z.size(-1) // 2 :] = torch.randn(z[..., z.size(-1) // 2 :].shape) | |
c_[..., c.size(-1) // 2 :] = torch.randn(c[..., c.size(-1) // 2 :].shape) | |
c = torch.nn.ConstantPad1d(args_g["aux_context_window"], 0.0)(c) | |
c_ = torch.nn.ConstantPad1d(args_g["aux_context_window"], 0.0)(c_) | |
try: | |
# check not equal | |
np.testing.assert_array_equal(c.numpy(), c_.numpy()) | |
except AssertionError: | |
pass | |
else: | |
raise AssertionError("Must be different.") | |
try: | |
# check not equal | |
np.testing.assert_array_equal(z.numpy(), z_.numpy()) | |
except AssertionError: | |
pass | |
else: | |
raise AssertionError("Must be different.") | |
# check causality | |
y = model_g(z, c) | |
y_ = model_g(z_, c_) | |
np.testing.assert_array_equal( | |
y[..., : y.size(-1) // 2].detach().cpu().numpy(), | |
y_[..., : y_.size(-1) // 2].detach().cpu().numpy(), | |
) |
ParallelWaveGAN/test/test_melgan.py
Lines 270 to 296 in edf35dd
def test_causal_melgan(dict_g): | |
batch_size = 4 | |
batch_length = 4096 | |
args_g = make_melgan_generator_args(**dict_g) | |
upsampling_factor = np.prod(args_g["upsample_scales"]) | |
c = torch.randn( | |
batch_size, args_g["in_channels"], batch_length // upsampling_factor | |
) | |
model_g = MelGANGenerator(**args_g) | |
c_ = c.clone() | |
c_[..., c.size(-1) // 2 :] = torch.randn(c[..., c.size(-1) // 2 :].shape) | |
try: | |
# check not equal | |
np.testing.assert_array_equal(c.numpy(), c_.numpy()) | |
except AssertionError: | |
pass | |
else: | |
raise AssertionError("Must be different.") | |
# check causality | |
y = model_g(c) | |
y_ = model_g(c_) | |
assert y.size(2) == c.size(2) * upsampling_factor | |
np.testing.assert_array_equal( | |
y[..., : c.size(-1) // 2 * upsampling_factor].detach().cpu().numpy(), | |
y_[..., : c_.size(-1) // 2 * upsampling_factor].detach().cpu().numpy(), | |
) |
Oh sorry, the CI errors are not related to this PR. |
@chomeyama I fixed CI errors #327. Could you merge the current master? |
I have implemented a test code for HiFiGAN and added some modifications to HiFiGAN Generator. |
Cool, could you fix ci errors about black? |
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.
Thank you for your contribution!
How do you find this change to hifigan output? Much different? |
Implemented causal option for HiFiGAN