-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattack.py
More file actions
31 lines (22 loc) · 975 Bytes
/
Copy pathattack.py
File metadata and controls
31 lines (22 loc) · 975 Bytes
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
import pickle
import numpy as np
import argparse
import os
import importlib
from utils.metric import eval_attack, compute_metric
from utils.shadow_utils import get_test
parser = argparse.ArgumentParser()
parser.add_argument("--dataset", default="cifar10", type=str)
parser.add_argument("--attack", default="lira", type=str)
parser.add_argument("--n_shadows", default=256, type=int)
args = parser.parse_args()
print(args)
test_logits, test_mask = get_test(
args.dataset, args.n_shadows, attack_type=args.attack, data_type="shadow", model_type="shadow"
)
attack_module = importlib.import_module(f"attacks.{args.attack}")
final_score = attack_module.attack(args.dataset, args.n_shadows, test_logits)
auc, acc, lw0, lw1, lw2, lw3, lw4 = eval_attack(final_score, test_mask.astype(bool))
print(
f"Final {args.attack.upper()} attack \nAUC = {auc}\nACC = {acc}\nTPR@10%FPR: {lw0}\nTPR@1%FPR: {lw1}\nTPR@0.1%FPR: {lw2}\nTPR@0.01%FPR: {lw3} \nTPR@0.001%FPR: {lw4}",
)