vincentherrmann / pytorch-wavenet

An implementation of WaveNet with fast generation
MIT License
968 stars 225 forks source link

Generation error in mu_law_expansion function #7

Closed robinsloan closed 6 years ago

robinsloan commented 6 years ago

Hi there! I'm running into an error and I'm not sure if it's particular to my setup or something deeper.

When I run generate_script.py, everything seems to go fine until I get to the final mu_law_expansion step, at which point I get first

RuntimeWarning: overflow encountered in exp s = np.sign(data) * (np.exp(np.abs(data) * np.log(mu + 1)) - 1) / mu

and then a fatal

librosa.util.exceptions.ParameterError: Audio buffer is not finite everywhere

It's the np.exp that blows up into enormous numbers.

The data coming into the mu_law_expansion function is all in the range 0-255…

[ 45., 202., 198., 194., 115., …

and then after np.abs(data) * np.log(mu +1) it looks like this…

[ 249.70842382, 1120.91336915, 1098.71706481, 1076.52076047, 638.14374976 …

which np.exp blows up:

[2.79892042e+108, inf, inf, inf, 1.38774344e+277, …

Looking at the code, I have some suspicions about what might be happening, but before I get too far into fiddling with it, I want to confirm that generate_script.py works on your end.

Thanks for sharing this codebase and the accompanying documentation—it's super impressive.

vincentherrmann commented 6 years ago

Thanks! I know this error and I'm sure I fixed it somewhere, but apparently not in the master branch. I'm not great at version control (yet), sorry! You are absolutely right, the input of mu_law_expansion should be between -1. and 1., the values are actually scaled in the code but then never used. So the fix is exactly one letter in wavelet_model.py line 299:

From

o = (x / self.classes) * 2. - 1
generated = np.append(generated, x)

to

o = (x / self.classes) * 2. - 1
generated = np.append(generated, o)

Now the fast generation should work fine.

robinsloan commented 6 years ago

Ah that's terrific! Thanks, Vincent.