Skip to content

added weighted channel averaging layer #143

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions neural_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,23 @@ def _safe_log(inp, epsilon=1e-20):
out = log_mel_spec
return out

class channel_averaging(nn.Module):
def __init__(self, options,inp_dim):
super(channel_averaging, self).__init__()
self._use_cuda = strtobool(options['use_cuda'])
channel_weights = [float(e) for e in options['chAvg_channelWeights'].split(',')]
self._nr_of_channels = len(channel_weights)
numpy_weights = np.asarray(channel_weights, dtype=np.float32) * 1.0 / np.sum(channel_weights)
self._weights = torch.from_numpy(numpy_weights)
if self._use_cuda:
self._weights = self._weights.cuda()
self.out_dim = 1

def forward(self, x):
assert self._nr_of_channels == x.shape[-1]
out = torch.einsum('tbc,c->tb', x, self._weights).unsqueeze(-1)
return out

class liGRU(nn.Module):

def __init__(self, options,inp_dim):
Expand Down
4 changes: 4 additions & 0 deletions proto/channelAvg.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[proto]
chAvg_channelWeights=str