Commit 2a3b74d2 authored by Anthony Larcher's avatar Anthony Larcher
Browse files

add noise

parent c58d2d5f
......@@ -489,8 +489,9 @@ def data_augmentation(speech,
speech = torch.nn.functional.conv1d(speech_[None, ...], rir[None, ...])[0]
if "add_noise" in augmentations:
# Pick a noise sample from the noise_df
noise_row = noise_df.iloc[random.randrange(noise_df.shape[0])]
# Pick a noise type
noise = torch.zeros_like(speech)
noise_idx = random.randrange(3)
# speech
if noise_idx == 0:
......
......@@ -202,7 +202,10 @@ def eer(negatives, positives):
def test_metrics(model,
device,
speaker_number,
idmap_test_filename,
ndx_test_filename,
key_test_filename,
data_root_name,
num_thread,
mixed_precision):
"""Compute model metrics
......@@ -221,10 +224,10 @@ def test_metrics(model,
Returns:
[type]: [description]
"""
idmap_test_filename = 'h5f/idmap_test.h5'
ndx_test_filename = 'h5f/ndx_test.h5'
key_test_filename = 'h5f/key_test.h5'
data_root_name='/lium/scratch/larcher/voxceleb1/test/wav'
#idmap_test_filename = 'h5f/idmap_test.h5'
#ndx_test_filename = 'h5f/ndx_test.h5'
#key_test_filename = 'h5f/key_test.h5'
#data_root_name='/lium/scratch/larcher/voxceleb1/test/wav'
transform_pipeline = dict()
......@@ -837,7 +840,6 @@ def xtrain(speaker_number,
new_model_dict.update(pretrained_dict)
model.load_state_dict(new_model_dict)
# Freeze required layers
for name, param in model.named_parameters():
if name.split(".")[0] in freeze_parts:
......@@ -980,7 +982,7 @@ def xtrain(speaker_number,
elif opt == 'rmsprop':
_optimizer = torch.optim.RMSprop
_options = {'lr': lr}
else: # opt == 'sgd'
else: # opt == 'sgd'
_optimizer = torch.optim.SGD
_options = {'lr': lr, 'momentum': 0.9}
......@@ -1002,9 +1004,9 @@ def xtrain(speaker_number,
param_list.append({'params': model.module.after_speaker_embedding.parameters(), 'weight_decay': model.module.after_speaker_embedding_weight_decay})
optimizer = _optimizer(param_list, **_options)
scheduler = scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer,
milestones=[10000,50000,100000],
gamma=0.5)
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer,
milestones=[10000,50000,100000],
gamma=0.5)
if mixed_precision:
scaler = torch.cuda.amp.GradScaler()
......@@ -1047,7 +1049,15 @@ def xtrain(speaker_number,
logging.critical(f"***{time.strftime('%H:%M:%S', time.localtime())} Training metrics - Cross validation accuracy = {val_acc} %, EER = {val_eer * 100} %")
if compute_test_eer:
test_eer = test_metrics(model, device, speaker_number, num_thread, mixed_precision)
test_eer = test_metrics(model,
device,
idmap_test_filename=dataset_params["test_set"]["idmap_test_filename"],
ndx_test_filename=dataset_params["test_set"]["ndx_test_filename"],
key_test_filename=dataset_params["test_set"]["key_test_filename"],
data_root_name=dataset_params["test_set"]["data_root_name"],
num_thread=num_thread,
mixed_precision=mixed_precision)
logging.critical(f"***{time.strftime('%H:%M:%S', time.localtime())} Training metrics - Test EER = {test_eer * 100} %")
# remember best accuracy and save checkpoint
......
Supports Markdown
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