This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
forked from magnumresearchgroup/Fastaudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_spoofspeech.py
84 lines (72 loc) · 2.84 KB
/
train_spoofspeech.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import sys
import speechbrain as sb
from hyperpyyaml import load_hyperpyyaml
from models.SpoofSpeechClassifier import SpoofSpeechClassifier
from datasets.SpoofSpeechDataset import get_dataset
import wandb
if __name__ == "__main__":
TRAIN =True
if TRAIN:
wandb.init(project='asv')
config = wandb.config
# Reading command line arguments.
hparams_file, run_opts, overrides = sb.parse_arguments(sys.argv[1:])
# Initialize ddp (useful only for multi-GPU DDP training).
sb.utils.distributed.ddp_init_group(run_opts)
# Load hyperparameters file with command-line overrides.
with open(hparams_file) as fin:
hparams = load_hyperpyyaml(fin, overrides)
# Create experiment directory
sb.create_experiment_directory(
experiment_directory=hparams["output_folder"],
hyperparams_to_save=hparams_file,
overrides=overrides,
)
# Create dataset objects "train", "valid", and "test".
datasets = get_dataset(hparams)
# Initialize the Brain object to prepare for mask training.
spk_id_brain = SpoofSpeechClassifier(
modules=hparams["modules"],
opt_class=hparams["opt_class"],
hparams=hparams,
run_opts=run_opts,
checkpointer=hparams["checkpointer"],
)
spk_id_brain.fit(
epoch_counter=spk_id_brain.hparams.epoch_counter,
train_set=datasets["train"],
valid_set=datasets["dev"],
train_loader_kwargs=hparams["dataloader_options"],
valid_loader_kwargs=hparams["dataloader_options"],
)
spk_id_brain.evaluate(
test_set=datasets["dev"],
min_key="min_tDCF",
progressbar=True,
test_loader_kwargs=hparams["dataloader_options"],
)
else:
hparams_file, run_opts, overrides = sb.parse_arguments(sys.argv[1:])
sb.utils.distributed.ddp_init_group(run_opts)
with open(hparams_file) as fin:
hparams = load_hyperpyyaml(fin, overrides)
hparams_file = os.path.join(hparams['output_folder'], 'hyperparams.yaml')
with open(hparams_file) as fin:
hparams = load_hyperpyyaml(fin, overrides)
hparams['batch_size'] = 1
datasets = get_dataset(hparams)
# Initialize the Brain object to prepare for mask training.
spk_id_brain = SpoofSpeechClassifier(
modules=hparams["modules"],
opt_class=hparams["opt_class"],
hparams=hparams,
run_opts=run_opts,
checkpointer=hparams["checkpointer"],
)
spk_id_brain.evaluate(
test_set=datasets["eval"],
min_key="min_tDCF",
progressbar= True,
test_loader_kwargs=hparams["dataloader_options"],
)