-
Notifications
You must be signed in to change notification settings - Fork 1
/
feature_speaker.py
223 lines (185 loc) · 9.39 KB
/
feature_speaker.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
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
import pandas as pd
import argparse
def load_unlabelled_train(train_trainl_csv, train_testl_csv, train_f):
# Load datasets
print ("=======================================")
print ("Loading: train_trainL_csv = {}".format(train_trainl_csv))
print (" train_testL_csv = {}".format(train_testl_csv))
train_trainL_set = pd.read_csv(train_trainl_csv)
train_testL_set = pd.read_csv(train_testl_csv)
# Set up ground truth for training set of our auditor
print ("Set up ground truth for each user...")
train_mem = 0
train_nonmem = 0
Labels_train = []
for n in range(len(train_trainL_set)):
Labels_train.append("member")
train_mem += 1
train_trainL_set['class'] = Labels_train
Labels_test = []
for nrow in range(len(train_testL_set)):
if train_testL_set.at[nrow, 'user'] in train_trainL_set['user']:
Labels_test.append("member")
train_mem += 1
else:
Labels_test.append("nonmember")
train_nonmem += 1
train_testL_set['class'] = Labels_test
train_set = train_trainL_set
train_set = train_set.append(train_testL_set)
pd.DataFrame(train_set).to_csv(train_f, index=None)
print (">>Training set for auditor: {} spk = {} train-clean-360-shd + "
"{} test-clean-1-shd.".format(len(train_set), len(train_trainL_set), len(train_testL_set)))
print (" Training set for auditor has {} mem and {} nonmem.".format(train_mem, train_nonmem))
print (" Training set saves as {}".format(train_f))
# Extract member in shadow model's testing set
train_testL_mem = train_testL_set.loc[train_testL_set['class'] == 'member']
print (" Training set include {} user'member in testing restult".format(len(train_testL_mem)))
# Training set for auditor (Exclude member in shadow model's testing set)
if len(train_testL_mem) != 0:
nonmem_set = train_testL_set.loc[train_testL_set['class'] == 'nonmember']
train_testL_new = train_trainL_set
train_testL_new = train_testL_new.append(nonmem_set)
path = train_f.split('.')[0] + '_inout.csv'
pd.DataFrame(train_testL_new).to_csv(path, index=None)
print("Training set exclude user'member has {} mem + {} nonmem.".format(len(train_trainL_set), len(nonmem_set)))
return train_set, train_trainL_set, train_testL_set
def load_unlabelled_test(test_trainl_csv, test_testl_csv, test_f):
# Load datasets
print ("=======================================")
print ("Loading: test_trainL_csv = {}".format(test_trainl_csv))
print (" test_testL_csv = {}".format(test_testl_csv))
test_trainL_set = pd.read_csv(test_trainl_csv)
test_testL_set = pd.read_csv(test_testl_csv)
# Set up ground truth for testing set of our auditor
print ("Set up ground truth for each user...")
test_mem = 0
test_nonmem = 0
Labels_train = []
for n in range(len(test_trainL_set)):
Labels_train.append("member")
test_mem += 1
test_trainL_set['class'] = Labels_train
Labels_test = []
for nrow in range(len(test_testL_set)):
if test_testL_set.at[nrow, 'user'] in test_trainL_set['user']:
Labels_test.append("member")
test_mem += 1
else:
Labels_test.append("nonmember")
test_nonmem += 1
test_testL_set['class'] = Labels_test
path = test_f.split('.')[0] + '_allout.csv'
pd.DataFrame(test_testL_set).to_csv(path, index=None)
test_set = test_trainL_set
test_set = test_set.append(test_testL_set)
pd.DataFrame(test_set).to_csv(test_f, index=None)
print (">>Testing set for auditor: {} spk = {} train-clean-100-user + "
"{} test-clean-2-user.".format(len(test_set), len(test_trainL_set), len(test_testL_set)))
print (" Testing set for auditor has {} mem and {} nonmem.".format(test_mem, test_nonmem))
print (" Testing set saves as {}".format(test_f))
# Extract member in target model's testing set
test_testL_mem = test_testL_set.loc[test_testL_set['class'] == 'member']
path = test_f.split('.')[0] + '_memout.csv'
pd.DataFrame(test_testL_mem).to_csv(path, index=None)
print (" Testing set include {} usermember in target model's testing set".format(len(test_testL_mem)))
# Extract member in target model's training set
path = test_f.split('.')[0] + '_memin.csv'
pd.DataFrame(test_trainL_set).to_csv(path, index=None)
print (" Testing set include {} usermember in target model's training set".format(len(test_trainL_set)))
# Training set for auditor (Exclude member in target model's testing set)
if len(test_testL_mem) != 0:
nonmem_set = test_testL_set.loc[test_testL_set['class'] == 'nonmember']
path = test_f.split('.')[0] + '_memnon.csv'
pd.DataFrame(nonmem_set).to_csv(path, index=None)
test_testL_new = test_trainL_set
test_testL_new = test_testL_new.append(nonmem_set)
path = test_f.split('.')[0] + '_inout.csv'
pd.DataFrame(test_testL_new).to_csv(path, index=None)
print("Testing set exclude user'member has {} mem + {} nonmem.".format(len(test_trainL_set), len(nonmem_set)))
return test_set, test_trainL_set, test_testL_set
def load_unlabelled(train_trainl_csv, train_testl_csv, test_trainl_csv, test_testl_csv, train_f, test_f):
# Load datasets
print ("=======================================")
print ("Loading: train_trainL_csv = {}".format(train_trainl_csv))
print (" train_testL_csv = {}".format(train_testl_csv))
print (" test_trainL_csv = {}".format(test_trainl_csv))
print (" test_testL_csv = {}".format(test_testl_csv))
train_trainL_set = pd.read_csv(train_trainl_csv)
train_testL_set = pd.read_csv(train_testl_csv)
test_trainL_set = pd.read_csv(test_trainl_csv)
test_testL_set = pd.read_csv(test_testl_csv)
# Set up ground truth for training and testing set of our auditor
print ("Set up ground truth for each user...")
# Ground truth for training set
train_mem = 0
train_nonmem = 0
Labels_train = []
for n in range(len(train_trainL_set)):
Labels_train.append("member")
train_mem += 1
train_trainL_set['class'] = Labels_train
Labels_test = []
for nrow in range(len(train_testL_set)):
if train_testL_set.at[nrow, 'user'] in train_trainL_set['user']:
Labels_test.append("member")
train_mem += 1
else:
Labels_test.append("nonmember")
train_nonmem += 1
train_testL_set['class'] = Labels_test
train_set = train_trainL_set
train_set = train_set.append(train_testL_set)
pd.DataFrame(train_set).to_csv(train_f, index=None)
print (">>Training set for auditor: {} spk = {} train-clean-360-shd + "
"{} test-clean-1-shd.".format(len(train_set), len(train_trainL_set), len(train_testL_set)))
print (" Training set for auditor has {} mem and {} nonmem.".format(train_mem, train_nonmem))
print (" Training set saves as {}".format(train_f))
# Ground truth for testing set
test_mem = 0
test_nonmem = 0
Labels_train = []
for n in range(len(test_trainL_set)):
Labels_train.append("member")
test_mem += 1
test_trainL_set['class'] = Labels_train
Labels_test = []
for nrow in range(len(test_testL_set)):
if test_testL_set.at[nrow, 'user'] in test_trainL_set['user']:
Labels_test.append("member")
test_mem += 1
else:
Labels_test.append("nonmember")
test_nonmem += 1
test_testL_set['class'] = Labels_test
test_set = test_trainL_set
test_set = test_set.append(test_testL_set)
pd.DataFrame(test_set).to_csv(test_f, index=None)
print (">>Testing set for auditor: {} spk = {} train-clean-100-user + "
"{} test-clean-2-user.".format(len(test_set), len(test_trainL_set),len(test_testL_set)))
print (" Testing set for auditor has {} mem and {} nonmem.".format(test_mem, test_nonmem))
print (" Testing set saves as {}".format(test_f))
return train_set, test_set
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('n_audio', type=int, help='# of querying audios')
# parser.add_argument('n_sample', type=int, help='the amount number of random users/features')
# parser.add_argument('n_time', type=int, help='nth time for average result.')
arguments = parser.parse_args()
return arguments
if __name__ == '__main__':
# args = get_arguments()
# n_audio = args.n_audio
# # Set up speaker level datasets
# train_trainL_csv = "data/gru_360_shd/feats5U5A1_gru_train-clean-360-shd.csv"
# train_testL_csv = "data/gru_360_shd/feats5U5A1_gru_test-clean-1-shd.csv"
test_trainL_csv = "data/lstm_100_user/feats5U5A13_train-clean-100-user.csv"
test_testL_csv = "data/lstm_100_user/feats5U5A13_test-clean-2-user.csv"
# train_f = "data/train/train_u55_360gru.csv"
test_f = "data/test2/test_u55A13_100.csv"
# # Load unlabelled datasets & Set up ground truth (user-level)
# [train_set, test_set] = load_unlabelled(train_trainL_csv, train_testL_csv, test_trainL_csv, test_testL_csv, train_f, test_f)
# [train_set, train_trainL_set, train_testL_set] = load_unlabelled_train(train_trainL_csv, train_testL_csv, train_f)
[test_set, test_trainL_set, test_testL_set] = load_unlabelled_test(test_trainL_csv, test_testL_csv, test_f)
# label = "nonmember"
# load_unlabelled_single(test_testL_csv, test_f, label)