-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·298 lines (240 loc) · 10.1 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
set -e
#===== begin config =======
stage=0
fix_scp=false
show_vpc_scores=true
skip_stage=
anon_exp_parameter="x_vector_vpc__crossgender=false__f0transformation=false__diffpseudospeaker"
verbose=""
########
# Once trained the rotation is applied on the anon-trial set to revert the VoicePrivacy anonymization,
# Top1 accuracy is calculated between de-anon-trial and trial-anon to asses the reversibility of procrustes (in the x-vector domain)
# EER / linkability is calculated between de-anon-trial and original enroll
########
# anon xvector extracted with anon model
retrained_anon_xtractor=false
# procrustes trained on ("f", "m" or "")
filter_gender=""
# train rotation with wasserstein procrustes instead of procrustes
wp=false
# Frontend params for wasserstein procrustes
frontend_train=""
# frontend_train="--pca --pca_n_dim 70"
wass_procrustes_param="--niter 512 --bsz 8 --lr 10" # Hyperparameter found with grid search
# oracle:
oracle_f=false
oracle_m=false
#===== end config =======
. utils/parse_options.sh || exit 1;
. ./env.sh
mkdir -p exp
frontend_test="$frontend_train --pca_load_path exp/enroll_train_wp"
anon_xtractor="_retrained_xtractor"
if ! $retrained_anon_xtractor; then
anon_xtractor=""
fi
wp_flag=""
if $wp; then
wp_flag="--wp"
fi
if [ $stage -le -1 ]; then
printf "${GREEN}Stage -1: testing x-vector loader${NC}\n"
for anon_exp_parameter in \
"x_vector_vpc__crossgender=false__f0transformation=false__diffpseudospeaker" \
"x_vector_vpc__crossgender=false__f0transformation=false__diffpseudospeaker_retrained_xtractor" \
"x_vector_vpc__crossgender=false__f0transformation=true__diffpseudospeaker" \
"x_vector_vpc__crossgender=false__f0transformation=true__diffpseudospeaker_retrained_xtractor" \
"x_vector_vpc__crossgender=true__f0transformation=false__diffpseudospeaker" \
"x_vector_vpc__crossgender=true__f0transformation=false__diffpseudospeaker_retrained_xtractor" \
"x_vector_vpc__crossgender=true__f0transformation=true__diffpseudospeaker" \
"x_vector_vpc__crossgender=true__f0transformation=true__diffpseudospeaker_retrained_xtractor" \
;do
printf "$anon_exp_parameter\n"
if $fix_scp; then
cd "data/$anon_exp_parameter"
rg "exp/models/asv_eval[^/]*/xvect_01709_1" --files-with-matches | \
xargs sed -i "s|exp/models/asv_eval[^/]*/xvect_01709_1|data/$anon_exp_parameter|g" || true
cd -
fi
for suffix in "" "_anon"; do
for original_dset in xvect_libri_test_trials_f xvect_libri_test_trials_m xvect_libri_test_enrolls; do
original_dset=${original_dset}${suffix}
printf " $original_dset\n"
python ./prep_dset.py \
./data/$anon_exp_parameter/$original_dset/xvector.scp \
./data/$anon_exp_parameter/$original_dset/xvector.scp \
"/tmp/test/Emb_U" "/tmp/test/User_U" \
"/tmp/test/Emb_L" "/tmp/test/User_L" \
--test
done
done
done
printf "${GREEN}Stage -1: All Scp files could be read${NC}\n"
exit 0
fi
slug=original
if [ $stage -le 0 ]; then
# quite useful step to test if the compute_spk_cosine script works
printf "${GREEN}Reproduce VoicePrivacy EER results with cosine scoring${NC}\n"
index=0
for exp in "$anon_exp_parameter" \
"$anon_exp_parameter${anon_xtractor}"; do
if [[ $index == 1 ]]; then
slug=anon
if ! $retrained_anon_xtractor; then
break
fi
printf "${GREEN}Anonymized x-vector -> (extracted by a x-vector trained on anonymized speech)${NC}\n"
else
for dset in "f" "m";do
printf "**ASV ($slug): ${RED}test_trials_${dset} ${GREEN}original${NC} <=> ${RED}test_enrolls - ${GREEN}original${RED}${NC}**\n"
python compute_spk_cosine.py \
./data/${exp}/xvect_libri_test_trials_${dset}/meta/trials \
./data/${exp}/xvect_libri_test_trials_${dset}/ \
./data/${exp}/xvect_libri_test_enrolls/ \
./exp/cosine_scores.txt
PYTHONPATH=$(realpath ./utils/anonymization_metrics) \
python ./utils/compute_metrics.py \
-k ./data/${exp}/xvect_libri_test_trials_${dset}/meta/trials \
-s ./exp/cosine_scores.txt
done
for dset in "f" "m";do
printf "**ASV ($slug): ${RED}test_trials_${dset} ${GREEN}anonymized${NC} <=> ${RED}test_enrolls - ${GREEN}original${RED}${NC}**\n"
python compute_spk_cosine.py \
./data/${exp}/xvect_libri_test_trials_${dset}/meta/trials \
./data/${exp}/xvect_libri_test_trials_${dset}_anon/ \
./data/${exp}/xvect_libri_test_enrolls/ \
./exp/cosine_scores.txt
PYTHONPATH=$(realpath ./utils/anonymization_metrics) \
python ./utils/compute_metrics.py \
-k ./data/${exp}/xvect_libri_test_trials_${dset}/meta/trials \
-s ./exp/cosine_scores.txt
done
index=1
fi
for dset in "f" "m";do
printf "**ASV ($slug): ${RED}test_trials_${dset} ${GREEN}anonymized${NC} <=> ${RED}test_enrolls - ${GREEN}anonymized${RED}${NC}**\n"
python compute_spk_cosine.py \
./data/${exp}/xvect_libri_test_trials_${dset}/meta/trials \
./data/${exp}/xvect_libri_test_trials_${dset}_anon/ \
./data/${exp}/xvect_libri_test_enrolls_anon/ \
./exp/cosine_scores.txt
PYTHONPATH=$(realpath ./utils/anonymization_metrics) \
python ./utils/compute_metrics.py \
-k ./data/${exp}/xvect_libri_test_trials_${dset}/meta/trials \
-s ./exp/cosine_scores.txt
done
printf "\n"
done
if $show_vpc_scores; then
anon_dset=xvect_libri_test_enrolls_anon
original_dset=xvect_libri_test_enrolls
printf "${RED}Spk verif scores:${NC}\n"
cat ./data/$anon_exp_parameter/results/results.txt | grep ".*$(echo $anon_dset | sed -e 's/xvect_//').*" -A 3
printf "${RED}with retrained x-vector:${NC}\n"
cat ./data/${anon_exp_parameter}${anon_xtractor}/results/results.txt | grep ".*$(echo $anon_dset | sed -e 's/xvect_//').*" -A 3
printf "${RED}---${NC}\n"
fi
fi
if [ $stage -le 1 ] && ! echo $skip_stage | grep -w -q 1; then
anon_dset=xvect_libri_test_enrolls_anon
original_dset=xvect_libri_test_enrolls
# Calculate theorical best likability after training procrustes on test datatest
if $oracle_f; then
filter_gender="f"
anon_dset=xvect_libri_test_trials_f_anon
original_dset=xvect_libri_test_trials_f
fi
# Calculate theorical best likability after training procrustes on test datatest
if $oracle_m; then
filter_gender="m"
anon_dset=xvect_libri_test_trials_m_anon
original_dset=xvect_libri_test_trials_m
fi
printf "${GREEN} == Data used to train rotation ==\n - $original_dset \n - $anon_dset${NC}\n"
expe_dir=exp/enroll_train_wp
mkdir -p $expe_dir
python ./prep_dset.py \
./data/$anon_exp_parameter/$original_dset/xvector.scp \
./data/${anon_exp_parameter}${anon_xtractor}/$anon_dset/xvector.scp \
"$expe_dir/Emb_U" "$expe_dir/User_U" \
"$expe_dir/Emb_L" "$expe_dir/User_L" \
--noplot \
--filter_gender $filter_gender \
# --spk_utt_all_combinations
printf "${GREEN}== Training rotation ==${NC}\n"
expe_dir=exp/enroll_train_wp
python ./get_align_procrustes.py \
--emb_src $expe_dir/Emb_U.npy \
--label_src $expe_dir/User_U.npy \
--emb_tgt $expe_dir/Emb_L.npy \
--label_tgt $expe_dir/User_L.npy \
--rotation exp/WP_R.npy \
$frontend_train $wass_procrustes_param $wp_flag $verbose
printf "${GREEN}Done${NC}\n"
fi
if [ $stage -le 2 ] && ! echo $skip_stage | grep -w -q 2; then
printf "${GREEN}== TEST rotation irreversibility ==${NC}\n"
expe_dir=exp/trials_test
mkdir -p $expe_dir
for dset in trials_f trials_m; do
gender_test=${dset: -1}
if [[ "${gender_test}" != "$filter_gender" ]] && [[ "${filter_gender}" != "" ]]; then
continue
fi
original_dset=xvect_libri_test_${dset}
anon_dset=xvect_libri_test_${dset}_anon
printf "**Accuracy ${RED}$dset ${GREEN}anonymized => procrustes${NC} => ${RED}$dset - ${GREEN}original${RED}${NC}**\n"
python ./prep_dset.py \
./data/$anon_exp_parameter/$original_dset/xvector.scp \
./data/${anon_exp_parameter}${anon_xtractor}/$anon_dset/xvector.scp \
"$expe_dir/Emb_U" "$expe_dir/User_U" \
"$expe_dir/Emb_L" "$expe_dir/User_L" \
--noplot # --test-only-train-spk # --test-remove-train-spk
python ./get_align_procrustes.py \
--emb_src $expe_dir/Emb_U.npy \
--label_src $expe_dir/User_U.npy \
--emb_tgt $expe_dir/Emb_L.npy \
--label_tgt $expe_dir/User_L.npy \
--rotation exp/WP_R.npy \
$frontend_test \
--test
done
fi
if [ $stage -le 3 ] && ! echo $skip_stage | grep -w -q 3; then
printf "==${GREEN} TEST likability between Anonymized and Orignal speech ==\\n\
Anonymized x-vector -> (extracted by a x-vector trained on anonymized speech)\\n\
Original x-vector -> (extracted by a x-vector trained on anonymized speech) ${NC}\n"
for dset in "f" "m";do
if [[ "${dset}" != "$filter_gender" ]] && [[ "${filter_gender}" != "" ]]; then
continue
fi
exp="$anon_exp_parameter${anon_xtractor}"
python ./apply_procrustes.py \
--emb_in ./data/${exp}/xvect_libri_test_trials_${dset}_anon/xvector.scp \
--emb_out ./data/${exp}/xvect_libri_test_trials_${dset}_anon/ \
--emb_src $expe_dir/nan --test \
--rotation ./exp/WP_R.npy \
$frontend_test
done
for dset in "f" "m";do
if [[ "${dset}" != "$filter_gender" ]] && [[ "${filter_gender}" != "" ]]; then
continue
fi
exp_o="$anon_exp_parameter"
exp_a="$anon_exp_parameter${anon_xtractor}"
printf "**ASV: ${RED}test_trials_${dset} ${GREEN}anonymized => procrustes${NC} <=> ${RED}test_enrolls - ${GREEN}original${RED}${NC}**\n"
python compute_spk_cosine.py \
./data/${exp_a}/xvect_libri_test_trials_${dset}/meta/trials \
./data/${exp_a}/xvect_libri_test_trials_${dset}_anon/ \
./data/${exp_o}/xvect_libri_test_enrolls/ \
./exp/cosine_scores.txt \
--trial-scp transformed_xvector.scp \
$frontend_test --test
PYTHONPATH=$(realpath ./utils/anonymization_metrics) \
python ./utils/compute_metrics.py \
-k ./data/${exp_a}/xvect_libri_test_trials_${dset}/meta/trials \
-s ./exp/cosine_scores.txt
done
fi