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

Faster forwarding #144

Merged
Merged
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
9 changes: 5 additions & 4 deletions data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def _update_data(data_set, labs, fea_dict, fea, fea_index, data_set_fea, labs_fe
fea_index=fea_index+data_set_fea.shape[1]
fea_dict[fea].append(fea_index)
fea_dict[fea].append(fea_dict[fea][6]-fea_dict[fea][5])
elif cnt_fea==0 and (not cnt_fea==0):
elif cnt_fea==0 and (not cnt_lab==0):
labs=np.column_stack((labs,labs_fea))
elif (not cnt_fea==0) and cnt_fea==0:
elif (not cnt_fea==0) and cnt_lab==0:
data_set=np.column_stack((data_set,data_set_fea))
fea_dict[fea].append(fea_index)
fea_index=fea_index+data_set_fea.shape[1]
Expand Down Expand Up @@ -368,12 +368,13 @@ def _load_chunk_refac01(fea_scp,fea_opts,lab_folder,lab_opts,left,right,max_sequ
for lab in lab_dict.keys():
lab_folder, lab_opts = _get_lab_config_from_dict(lab_dict[lab], fea_only)
data_name_fea, data_set_fea, data_set_lab, data_end_index_fea, data_end_index_lab = _load_chunk_refac01(fea_scp, fea_opts, lab_folder, lab_opts, cw_left, cw_right, max_seq_length, output_folder, fea_only)
labs_fea, data_set_fea, data_end_index_fea, data_end_index_lab = _compensate_for_different_context_windows(data_set_fea, data_set_lab, cw_left_max, cw_left, cw_right_max, cw_right, data_end_index_fea, data_end_index_lab)
if sum([abs(e) for e in [cw_left_max, cw_right_max, cw_left, cw_right]]) != 0:
data_set_lab, data_set_fea, data_end_index_fea, data_end_index_lab = _compensate_for_different_context_windows(data_set_fea, data_set_lab, cw_left_max, cw_left, cw_right_max, cw_right, data_end_index_fea, data_end_index_lab)
if cnt_fea == 0 and cnt_lab == 0:
data_end_index_fea_ini = data_end_index_fea
data_end_index_lab_ini = data_end_index_lab
data_name = data_name_fea
data_set, labs, fea_dict, fea_index = _update_data(data_set, labs, fea_dict, fea, fea_index, data_set_fea, labs_fea, cnt_fea, cnt_lab)
data_set, labs, fea_dict, fea_index = _update_data(data_set, labs, fea_dict, fea, fea_index, data_set_fea, data_set_lab, cnt_fea, cnt_lab)
_check_consistency(data_name, data_name_fea, data_end_index_fea_ini, data_end_index_fea, data_end_index_lab_ini, data_end_index_lab)
cnt_lab=cnt_lab+1
cnt_fea=cnt_fea+1
Expand Down
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


9 changes: 8 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,12 @@ def _get_validation_data_for_chunks(fea_names, list_fea, N_chunks):
random.shuffle(full_list_fea_conc)
valid_chunks_fea=list(split_chunks(full_list_fea_conc,N_chunks))
return valid_chunks_fea
def _shuffle_forward_data(config):
if 'shuffle_forwarding_data' in config['forward']:
suffle_on_forwarding = strtobool(config['forward']['shuffle_forwarding_data'])
if not suffle_on_forwarding:
return False
return True

# splitting data into chunks (see out_folder/additional_files)
out_folder=config['exp']['out_folder']
Expand Down Expand Up @@ -1030,7 +1036,8 @@ def _get_validation_data_for_chunks(fea_names, list_fea, N_chunks):


# randomize the list
random.shuffle(full_list_fea_conc)
if _shuffle_forward_data(config):
random.shuffle(full_list_fea_conc)
forward_chunks_fea=list(split_chunks(full_list_fea_conc,N_chunks))


Expand Down