Skip to content

Commit

Permalink
added safe log as compr. func after mel spectr.
Browse files Browse the repository at this point in the history
  • Loading branch information
menne committed Jul 16, 2019
1 parent 5ce9f13 commit de1a0ed
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion neural_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ def __init__(self, options,inp_dim):
)

def forward(self, x):
def _safe_log(inp, epsilon=1e-20):
eps = torch.FloatTensor([epsilon])
if self._use_cuda:
eps = eps.cuda()
log_inp = torch.log10(torch.max(inp, eps.expand_as(inp)))
return log_inp
assert x.shape[-1] == 1, 'Multi channel time signal processing not suppored yet'
x_reshape_for_stft = torch.squeeze(x, -1).transpose(0, 1)
if self._use_cuda:
Expand All @@ -682,7 +688,9 @@ def forward(self, x):
)
x_power_stft = x_stft.pow(2).sum(-1)
x_power_stft_reshape_for_filterbank_mult = x_power_stft.transpose(1, 2)
out = self._mspec.fm(x_power_stft_reshape_for_filterbank_mult).transpose(0, 1)
mel_spec = self._mspec.fm(x_power_stft_reshape_for_filterbank_mult).transpose(0, 1)
log_mel_spec = _safe_log(mel_spec)
out = log_mel_spec
return out

class liGRU(nn.Module):
Expand Down

0 comments on commit de1a0ed

Please sign in to comment.