-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_programs.py
More file actions
55 lines (47 loc) · 2.48 KB
/
run_programs.py
File metadata and controls
55 lines (47 loc) · 2.48 KB
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
import sys
import subprocess
attacks = ["badnet"]
dset = 'office-home'#'office'
sources = 3 if dset == 'office' else 4
# sources = 4
if sys.argv[1] == 'source':
idx = 0
for attack in attacks:
for s in range(sources):
subprocess.call(f"nohup python ./train_source.py \
--dset={dset} --max_epoch=100 --attack_type={attack} --device=cuda:{idx} \
--s={s} > logs/{dset}_{attack}_s{s}.log &", shell=True)
print(f"Nohup log for train_source with attack: {attack} on dataset: {dset} and source: {s} > logs/{dset}_{attack}_s{s}.log")
idx += 1
idx = idx % 3
elif sys.argv[1] == 'target_wo_defense':
idx = 0
for _, attack in enumerate(attacks):
for s in range(sources):
subprocess.call(f"nohup python ./train_target.py \
--dset={dset} --max_epoch=15 --attack_type={attack} --device=cuda:{idx} \
--s={s} --save_knowledge > logs/{dset}_{attack}_s{s}_target_wo_defense.log &", shell=True)
print(f"Nohup log for train_target without defense with attack: {attack} on dataset: {dset} and source: {s} > logs/{dset}_{attack}_s{s}_target_wo_defense.log")
idx += 1
idx = idx % 3
elif sys.argv[1] == 'pp':
idx = 0
for _, attack in enumerate(attacks):
# idx = 2
for s in range(sources):
subprocess.call(f"nohup python ./pruned_performance.py \
--dset={dset} --attack_type={attack} --device=cuda:{idx} \
--s={s} --plot > logs/{dset}_{attack}_pp_{s}.log &", shell=True)
print(f"Nohup log for pp with attack: {attack} on dataset: {dset} and source: {s} > logs/{dset}_{attack}_pp_{s}.log")
idx += 1
idx = idx % 3
elif sys.argv[1] == 'target_with_defense':
idx = 0
for _, attack in enumerate(attacks):
for s in range(sources):
subprocess.call(f"nohup python ./train_target_defend_new.py --clip --clip_val=1.0\
--dset={dset} --max_epoch=15 --attack_type={attack} --device=cuda:{idx} \
--s={s} --defend > logs/{dset}_{attack}_s{s}_target_with_defense_with_snorm.log &", shell=True)
print(f"Nohup log for train_target with defense with attack: {attack} on dataset: {dset} and source: {s} > logs/{dset}_{attack}_s{s}_target_with_defense_with_snorm.log")
idx += 1
idx = idx % 3