Commit 5502d3ea authored by Anthony Larcher's avatar Anthony Larcher
Browse files

nnet seqtoseq

parent 62f9e7c4
Pipeline #619 failed with stages
in 0 seconds
......@@ -96,13 +96,16 @@ class BLSTM(nn.Module):
:param inputs:
:return:
"""
#for idx, _s in enumerate(self.blstm_sizes):
# self.blstm_layers[idx].flatten_parameters()
hiddens = []
if self.hidden is None:
#hidden_1, hidden_2 = None, None
for _s in self.blstm_sizes:
hiddens.append(None)
else:
hiddens = self.hidden
hiddens = list(self.hidden)
x = inputs
outputs = []
......@@ -281,7 +284,7 @@ def seqTrain(dataset_yaml,
torch.manual_seed(dataset_params['seed'])
training_set = SeqSet(dataset_yaml,
wav_dir="data/wav/",
mdtm_dir="data/mdtm",
mdtm_dir="data/mdtm/",
mode="vad",
duration=2.,
filter_type="gate",
......@@ -334,18 +337,19 @@ def seqTrain(dataset_yaml,
},
]
if type(model) is SeqToSeq:
optimizer = _optimizer([
{'params': model.parameters(),
'weight_decay': model.weight_decay},],
**_options
)
else:
optimizer = _optimizer([
{'params': model.module.sequence_network.parameters(),
'weight_decay': model.module.sequence_network_weight_decay},],
**_options
)
optimizer = _optimizer([{'params': model.parameters()},], **_options)
#if type(model) is SeqToSeq:
# optimizer = _optimizer([
# {'params': model.parameters(),
# 'weight_decay': model.weight_decay},],
# **_options
# )
#else:
# optimizer = _optimizer([
# {'params': model.module.sequence_network.parameters(),
# #'weight_decay': model.module.sequence_network_weight_decay},],
# **_options
# )
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, 'min', verbose=True)
......@@ -414,6 +418,7 @@ def train_epoch(model, epoch, training_loader, optimizer, log_interval, device):
:param clipping:
:return:
"""
model.to(device)
model.train()
criterion = torch.nn.CrossEntropyLoss(reduction='mean')
......@@ -421,9 +426,12 @@ def train_epoch(model, epoch, training_loader, optimizer, log_interval, device):
for batch_idx, (data, target) in enumerate(training_loader):
target = target.squeeze()
optimizer.zero_grad()
output = model(data.to(device),target=target.to(device))
output = model(data.to(device))
output = output.permute(1, 2, 0)
target = target.permute(1, 0)
loss = criterion(output, target.to(device))
loss.backward()
loss.backward(retain_graph=True)
optimizer.step()
accuracy += (torch.argmax(output.data, 1) == target.to(device)).sum()
......@@ -432,7 +440,7 @@ def train_epoch(model, epoch, training_loader, optimizer, log_interval, device):
logging.critical('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}\tAccuracy: {:.3f}'.format(
epoch, batch_idx + 1, training_loader.__len__(),
100. * batch_idx / training_loader.__len__(), loss.item(),
100.0 * accuracy.item() / ((batch_idx + 1) * batch_size)))
100.0 * accuracy.item() / ((batch_idx + 1) * batch_size * 198)))
return model
......
......@@ -143,12 +143,12 @@ def mdtm_to_label(mdtm_filename,
elif diarization.segments[seg_idx]['start']/100. < t < diarization.segments[seg_idx]['stop']/100. :
label[ii] = speaker_dict[diarization.segments[seg_idx]['cluster']]
# Si on change de segment
elif diarization.segments[seg_idx]['stop']/100. < t:
elif diarization.segments[seg_idx]['stop']/100. < t and len(diarization.segments) > seg_idx + 1:
seg_idx += 1
# On est entre deux segments:
if t < diarization.segments[seg_idx]['start']/100.:
pass
elif diarization.segments[seg_idx]['start']/100. < t < diarization.segments[seg_idx]['stop']/100.:
elif diarization.segments[seg_idx]['start']/100. < t < diarization.segments[seg_idx]['stop']/100.:
label[ii] = speaker_dict[diarization.segments[seg_idx]['cluster']]
return label
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment