-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
135 lines (107 loc) · 6.53 KB
/
run.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# gender classification based on : https://github.com/lr2582858/kaldi-timit-sre-ivector/blob/master/v1/run.sh
# Amir Harati, May 2019
. ./cmd.sh
. ./path.sh
guss_num=512
ivector_dim=200
lda_dim=50
nj=2
exp=exp/ivector_gauss${guss_num}_dim${ivector_dim}
set -e # exit on error
####### Bookmark: scp prep #######
bash local/amt_gender_data_prep.sh ~/data/amt_gender/wav
###### Bookmark: MFCC extraction ######
mfccdir=mfcc
for x in train test; do
steps/make_mfcc.sh --cmd "$train_cmd" --nj $nj data/$x exp/make_mfcc/$x $mfccdir
sid/compute_vad_decision.sh --nj 2 --cmd "$train_cmd" data/$x exp/make_mfcc/$x $mfccdir
utils/fix_data_dir.sh data/$x
done
###### Bookmark: split the test to enroll and eval ######
mkdir -p data/test/enroll data/test/eval
cp data/test/{spk2utt,feats.scp,vad.scp} data/test/enroll
cp data/test/{spk2utt,feats.scp,vad.scp} data/test/eval
python local/split_data_enroll_eval.py data/test/utt2spk data/test/enroll/utt2spk data/test/eval/utt2spk 0
trials=data/test/test.trials
python local/produce_trials.py data/test/eval/utt2spk $trials
#utils/fix_data_dir.sh data/test/enroll
utils/fix_data_dir.sh data/test/eval
# create enril for train
mkdir -p data/train/enroll data/train/eval
cp data/train/{spk2utt,feats.scp,vad.scp} data/train/enroll
python local/split_data_enroll_eval.py data/train/utt2spk data/train/enroll/utt2spk data/train/eval/utt2spk 2000
utils/fix_data_dir.sh data/train/enroll
###### Bookmark: i-vector train ######
# train diag ubm
sid/train_diag_ubm.sh --nj $nj --cmd "$train_cmd" --num-threads 16 \
data/train $guss_num $exp/diag_ubm
#train full ubm
sid/train_full_ubm.sh --nj $nj --cmd "$train_cmd" data/train \
$exp/diag_ubm $exp/full_ubm
#train ivector
sid/train_ivector_extractor.sh --cmd "$train_cmd" --nj 2 \
--ivector-dim $ivector_dim --num-iters 5 $exp/full_ubm/final.ubm data/train \
$exp/extractor
###### Bookmark: i-vector extraction ######
#extract train ivector
sid/extract_ivectors.sh --cmd "$train_cmd" --nj $nj \
$exp/extractor data/train $exp/ivector_train
#extract enroll ivector
sid/extract_ivectors.sh --cmd "$train_cmd" --nj $nj \
$exp/extractor data/train/enroll $exp/ivector_enroll
#extract eval ivector
sid/extract_ivectors.sh --cmd "$train_cmd" --nj $nj \
$exp/extractor data/test/eval $exp/ivector_eval
###### Bookmark: scoring ######
# basic cosine scoring on i-vectors
bash local/cosine_scoring.sh data/train/enroll data/test/eval \
$exp/ivector_enroll $exp/ivector_eval $trials $exp/scores
# cosine scoring after reducing the i-vector dim with LDA
bash local/lda_scoring.sh data/train data/train/enroll data/test/eval \
$exp/ivector_train $exp/ivector_enroll $exp/ivector_eval $trials $exp/scores $lda_dim
# cosine scoring after reducing the i-vector dim with PLDA
bash local/plda_scoring.sh data/train data/train/enroll data/test/eval \
$exp/ivector_train $exp/ivector_enroll $exp/ivector_eval $trials $exp/scores
# print eer
for i in cosine lda plda; do
eer=`compute-eer <(python local/prepare_for_eer.py $trials $exp/scores/${i}_scores) 2> /dev/null`
printf "%15s %5.2f \n" "$i eer:" $eer
done > $exp/scores/results.txt
cat $exp/scores/results.txt
# copy ivector to text file
mkdir -p kaldi_outputs
$KALDI_ROOT/src/bin/copy-vector scp:$exp/ivector_enroll/ivector.scp ark,t:- > kaldi_outputs/enroll_ivec.txt
$KALDI_ROOT/src/bin/copy-vector scp:$exp/ivector_train/ivector.scp ark,t:- > kaldi_outputs/train_ivec.txt
$KALDI_ROOT/src/bin/copy-vector scp:$exp/ivector_eval/ivector.scp ark,t:- > kaldi_outputs/eval_ivec.txt
$KALDI_ROOT/src/bin/copy-vector scp:$exp/ivector_enroll/spk_ivector.scp ark,t:- > kaldi_outputs/norm_spk_enroll_ivec.txt
$KALDI_ROOT/src/bin/copy-vector scp:$exp/ivector_train/spk_ivector.scp ark,t:- > kaldi_outputs/norm_spk_train_ivec.txt
$KALDI_ROOT/src/bin/copy-vector scp:$exp/ivector_eval/spk_ivector.scp ark,t:- > kaldi_outputs/norm_spk_eval_ivec.txt
$KALDI_ROOT/src/ivectorbin/ivector-normalize-length scp:$exp/ivector_enroll/ivector.scp ark,t:- > kaldi_outputs/norm_enroll_ivec.txt
$KALDI_ROOT/src/ivectorbin/ivector-normalize-length scp:$exp/ivector_train/ivector.scp ark,t:- > kaldi_outputs/norm_train_ivec.txt
$KALDI_ROOT/src/ivectorbin/ivector-normalize-length scp:$exp/ivector_eval/ivector.scp ark,t:- > kaldi_outputs/norm_eval_ivec.txt
# LDA vectors
ivector-transform $exp/ivector_train/transform.mat scp:$exp/ivector_enroll/spk_ivector.scp ark:- | ivector-normalize-length ark:- ark,t:- > kaldi_outputs/lda_spk_enroll_ivec.txt
ivector-transform $exp/ivector_train/transform.mat scp:$exp/ivector_train/spk_ivector.scp ark:- | ivector-normalize-length ark:- ark,t:- > kaldi_outputs/lda_spk_train_ivec.txt
ivector-transform $exp/ivector_train/transform.mat scp:$exp/ivector_eval/spk_ivector.scp ark:- | ivector-normalize-length ark:- ark,t:- > kaldi_outputs/lda_spk_eval_ivec.txt
ivector-transform $exp/ivector_train/transform.mat scp:$exp/ivector_enroll/ivector.scp ark:- | ivector-normalize-length ark:- ark,t:- > kaldi_outputs/lda_enroll_ivec.txt
ivector-transform $exp/ivector_train/transform.mat scp:$exp/ivector_train/ivector.scp ark:- | ivector-normalize-length ark:- ark,t:- > kaldi_outputs/lda_train_ivec.txt
ivector-transform $exp/ivector_train/transform.mat scp:$exp/ivector_eval/ivector.scp ark:- | ivector-normalize-length ark:- ark,t:- > kaldi_outputs/lda_eval_ivec.txt
#PLDA (using custom code)
run.pl logs_plda_trans.log \
ivector-plda-transform --normalize-length=true \
--simple-length-normalization=true\
--num-utts=ark:$exp/ivector_enroll/num_utts.ark \
"ivector-copy-plda --smoothing=0.0 $exp/ivector_train/plda - |" \
"ark:ivector-subtract-global-mean $exp/ivector_train/mean.vec scp:$exp/ivector_enroll/spk_ivector.scp ark:- | ivector-normalize-length ark:- ark:- |" \
"ark:ivector-normalize-length scp:$exp/ivector_train/ivector.scp ark:- | ivector-subtract-global-mean $exp/ivector_train/mean.vec ark:- ark:- | ivector-normalize-length ark:- ark:- |" \
./kaldi_outputs/plda_train_ivec.txt|| exit 1;
run.pl logs_plda_trans.log \
ivector-plda-transform --normalize-length=true \
--simple-length-normalization=true\
--num-utts=ark:$exp/ivector_enroll/num_utts.ark \
"ivector-copy-plda --smoothing=0.0 $exp/ivector_train/plda - |" \
"ark:ivector-subtract-global-mean $exp/ivector_train/mean.vec scp:$exp/ivector_enroll/spk_ivector.scp ark:- | ivector-normalize-length ark:- ark:- |" \
"ark:ivector-normalize-length scp:$exp/ivector_eval/ivector.scp ark:- | ivector-subtract-global-mean $exp/ivector_train/mean.vec ark:- ark:- | ivector-normalize-length ark:- ark:- |" \
./kaldi_outputs/plda_eval_ivec.txt|| exit 1;
exit 0