-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
130 lines (113 loc) · 6.82 KB
/
run.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
import numpy as np
import os, pdb, sys
from pathlib import Path
import configparser
if __name__ == '__main__':
# read config files
config = configparser.ConfigParser()
config.sections()
config.read('config.ini')
# 1. feature processing
if config['mode'].getboolean('process_feature') is True:
for dataset in ['iemocap', 'iemocap', 'crema-d']:
if config['feature']['feature'] == 'emobase':
cmd_str = 'taskset 100 python3 feature_extraction/opensmile_feature_extraction.py --dataset ' + dataset
else:
cmd_str = 'taskset 100 python3 feature_extraction/pretrained_audio_feature_extraction.py --dataset ' + dataset
cmd_str += ' --feature_type ' + config['feature']['feature']
cmd_str += ' --data_dir ' + config['dir'][dataset]
cmd_str += ' --save_dir ' + config['dir']['save_dir']
print('Extract features')
print(cmd_str)
pdb.set_trace()
os.system(cmd_str)
# 2. process training data
if config['mode'].getboolean('process_training') is True:
for dataset in ['msp-improv', 'iemocap', 'crema-d']:
cmd_str = 'taskset 100 python3 preprocess_data/preprocess_federate_data.py --dataset ' + dataset
cmd_str += ' --feature_type ' + config['feature']['feature']
cmd_str += ' --data_dir ' + config['dir'][dataset]
cmd_str += ' --save_dir ' + config['dir']['save_dir']
cmd_str += ' --norm znorm'
print('Process training data')
print(cmd_str)
os.system(cmd_str)
# 3.1 Training SER model
if config['mode'].getboolean('ser_training') is True:
for dataset in [config['dataset']['private_dataset'], config['dataset']['adv_dataset']]:
for feature in ['emobase', 'apc', 'vq_apc', 'tera', 'decoar2']:
if config['model'].getboolean('udp'):
cmd_str = 'taskset 300 python3 mitigation/federated_ser_classifier_udp.py --dataset ' + dataset
cmd_str += ' --privacy_budget ' + config['model']['privacy_budget']
else:
cmd_str = 'taskset 300 python3 train/federated_ser_classifier.py --dataset ' + dataset
# cmd_str += ' --feature_type ' + config['feature']['feature']
cmd_str += ' --feature_type ' + feature
cmd_str += ' --dropout ' + config['model']['dropout']
cmd_str += ' --norm znorm --optimizer adam'
cmd_str += ' --model_type ' + config['model']['fed_model']
cmd_str += ' --learning_rate ' + config[config['model']['fed_model']]['lr']
cmd_str += ' --local_epochs ' + config[config['model']['fed_model']]['local_epochs']
cmd_str += ' --num_epochs ' + config[config['model']['fed_model']]['global_epochs']
cmd_str += ' --save_dir ' + config['dir']['save_dir']
print('Traing SER model')
print(cmd_str)
# pdb.set_trace()
os.system(cmd_str)
# 4. Training attack model
if config['mode'].getboolean('attack_training') is True:
for dataset_list in [['iemocap', 'msp-improv_crema-d'],
['crema-d', 'iemocap_msp-improv'],
['msp-improv', 'iemocap_crema-d']]:
for feature in ['emobase', 'apc', 'vq_apc', 'tera', 'decoar2']:
if config['model'].getint('attack_sample') == 1:
cmd_str = 'taskset 500 python3 train/federated_attribute_attack.py'
else:
cmd_str = 'taskset 500 python3 train/federated_attribute_attack_multiple.py --num_sample ' + config['model']['attack_sample']
cmd_str += ' --norm znorm --optimizer adam'
# cmd_str += ' --dataset ' + config['dataset']['private_dataset']
# cmd_str += ' --adv_dataset ' + config['dataset']['adv_dataset']
# cmd_str += ' --feature_type ' + config['feature']['feature']
cmd_str += ' --dataset ' + dataset_list[0]
cmd_str += ' --adv_dataset ' + dataset_list[1]
cmd_str += ' --feature_type ' + feature
cmd_str += ' --dropout ' + config['model']['dropout']
cmd_str += ' --model_type ' + config['model']['fed_model']
cmd_str += ' --learning_rate ' + config[config['model']['fed_model']]['lr']
cmd_str += ' --local_epochs ' + config[config['model']['fed_model']]['local_epochs']
cmd_str += ' --num_epochs ' + config[config['model']['fed_model']]['global_epochs']
cmd_str += ' --leak_layer first --model_learning_rate 0.0001'
cmd_str += ' --device 0'
cmd_str += ' --save_dir ' + config['dir']['save_dir']
print('Traing Attack model')
print(cmd_str)
# pdb.set_trace()
os.system(cmd_str)
# 5.1 Loading attack model
if config['mode'].getboolean('attack_result') is True:
for dataset_list in [['iemocap', 'msp-improv_crema-d'],
['crema-d', 'iemocap_msp-improv'],
['msp-improv', 'iemocap_crema-d']]:
for feature in ['tera', 'decoar2', 'emobase', 'apc', 'vq_apc']:
for privacy_budget in [0, 5, 10, 25, 50]:
# for privacy_budget in [5]:
cmd_str = 'taskset 500 python3 mitigation/federated_attribute_attack_result_per_speaker.py'
cmd_str += ' --norm znorm'
cmd_str += ' --dataset ' + dataset_list[0]
cmd_str += ' --adv_dataset ' + dataset_list[1]
cmd_str += ' --feature_type ' + feature
cmd_str += ' --dropout ' + config['model']['dropout']
cmd_str += ' --model_type ' + config['model']['fed_model']
cmd_str += ' --learning_rate ' + config[config['model']['fed_model']]['lr']
cmd_str += ' --local_epochs ' + config[config['model']['fed_model']]['local_epochs']
cmd_str += ' --num_epochs ' + config[config['model']['fed_model']]['global_epochs']
cmd_str += ' --leak_layer first --device 0'
cmd_str += ' --save_dir ' + config['dir']['save_dir']
cmd_str += ' --num_sample ' + config['model']['num_sample']
# if config['model'].getboolean('udp'):
if privacy_budget is not 0:
cmd_str += ' --privacy_budget ' + str(privacy_budget)
print('Attack model result')
print(cmd_str)
# pdb.set_trace()
os.system(cmd_str)