Skip to content
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

Merged
merged 6 commits into from
Feb 19, 2022

Conversation

chomeyama
Copy link
Contributor

Implemented causal option for HiFiGAN
スクリーンショット 2022-02-09 11 39 51

Copy link
Owner

@kan-bayashi kan-bayashi left a 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:

  1. Could you fix the CI errors?
  2. Could you add the test code for causal calculation?

Example test code:

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(),
)

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(),
)

@kan-bayashi
Copy link
Owner

Oh sorry, the CI errors are not related to this PR.
I will fix it. Please ignore about it.

@kan-bayashi
Copy link
Owner

@chomeyama I fixed CI errors #327. Could you merge the current master?

@chomeyama
Copy link
Contributor Author

I have implemented a test code for HiFiGAN and added some modifications to HiFiGAN Generator.

@kan-bayashi
Copy link
Owner

Cool, could you fix ci errors about black?

Copy link
Owner

@kan-bayashi kan-bayashi left a 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!

@kan-bayashi kan-bayashi merged commit 2701d8e into kan-bayashi:master Feb 19, 2022
@gafsd
Copy link

gafsd commented Mar 13, 2022

How do you find this change to hifigan output? Much different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants