Skip to content

Commit 011427d

Browse files
committed
init
1 parent 28bd003 commit 011427d

24 files changed

+2421
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
3+
models/__pycache__/
34
*.py[cod]
45
*$py.class
56

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# privacy_and_aug
1+
# Privacy, DA, and AT
2+
3+
We take one DA method, Cutout, as an example:
4+
5+
Train the 128 shadow models for Cutout:
6+
7+
python train.py --train --s_model 0 --t_model 128 --aug_type cutout --dataset cifar10
8+
9+
Inference $\phi$ for each data point with multiple queries (Ensure all models trained):
10+
11+
python inference.py --mode eval --load_model --save_results --dataset cifar10 --query_mode multiple --aug_type cutout
12+
13+
Perform LiRA after all $\phi$ computed (multiple queries):
14+
15+
python eval_privacy.py --save_results --multi
16+

advtrain.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import torch
2+
import torch.nn as nn
3+
import torch.nn.functional as F
4+
from torch.utils import data
5+
6+
criterion_kl = nn.KLDivLoss(reduction='sum')
7+
8+
def cal_adv(model, criterion, aug_type, imgs, cids, eps = 8):
9+
steps = 3
10+
step_size = 1.25 * eps / steps
11+
# steps = 20
12+
# step_size = 1
13+
model.eval()
14+
x_natural = imgs
15+
x_adv = x_natural.detach() + torch.empty_like(x_natural).uniform_(-eps / 255, eps / 255)
16+
if aug_type == "trades" or aug_type == "TradesAWP":
17+
logits = model.base_forward(x_natural)
18+
for _ in range(steps):
19+
x_adv.requires_grad_()
20+
with torch.enable_grad():
21+
loss_kl = criterion_kl(model(x_adv), F.softmax(logits, dim=1))
22+
grad = torch.autograd.grad(loss_kl, [x_adv])[0]
23+
x_adv = x_adv.detach() + (step_size / 255) * torch.sign(grad.detach())
24+
x_adv = torch.min(torch.max(x_adv, x_natural - eps / 255), x_natural + eps / 255)
25+
x_adv = torch.clamp(x_adv, 0.0, 1.0)
26+
return x_adv
27+
elif aug_type == "pgdat" or aug_type == "AWP":
28+
for _ in range(steps):
29+
x_adv.requires_grad_()
30+
with torch.enable_grad():
31+
pred = model(x_adv)
32+
loss = criterion(pred, cids)
33+
grad = torch.autograd.grad(loss, [x_adv])[0]
34+
x_adv = x_adv.detach() + (step_size / 255) * torch.sign(grad.detach())
35+
x_adv = torch.min(torch.max(x_adv, x_natural - eps / 255), x_natural + eps / 255)
36+
x_adv = torch.clamp(x_adv, 0.0, 1.0)
37+
return x_adv

configs/config_10.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"note": "modified from https://github.com/yigitcankaya/augmentation_mia",
3+
"training_num_epochs": 100,
4+
"regular_batch_size": 256,
5+
"training_augmentations": ["none", "base", "smooth", "disturblabel", "noise", "cutout", "mixup", "jitter", "pgdat", "trades", "distillation", "AWP", "TradesAWP", "dandd"],
6+
"augmentation_params": {
7+
"distillation": [3, 1, 2, 5, 10],
8+
"smooth": [0.2, 0.05, 0.1, 0.01, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
9+
"disturblabel": [0.05, 0.01, 0.2, 0.1, 0.3, 0.4, 0.425, 0.45, 0.5, 0.525, 0.55, 0.575, 0.6],
10+
"noise": [0.01, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35],
11+
"cutout": [8, 4, 12, 16, 20],
12+
"mixup": [0.5, 0.1, 0.25, 1, 2, 4, 8, 16, 32, 64, 128, 256],
13+
"jitter": [0.05, 0.1, 0.2, 0.15, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5],
14+
"trades": [],
15+
"pgdat": [],
16+
"AWP": [],
17+
"TradesAWP": []
18+
}
19+
}

configs/config_100.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"note": "modified from https://github.com/yigitcankaya/augmentation_mia",
3+
"training_num_epochs": 100,
4+
"regular_batch_size": 256,
5+
"training_augmentations": ["none", "base", "smooth", "disturblabel", "noise", "cutout", "mixup", "jitter", "pgdat", "trades", "distillation", "AWP", "TradesAWP", "dandd"],
6+
"augmentation_params": {
7+
"distillation": [3, 1, 2, 5, 10],
8+
"smooth": [0.3, 0.2, 0.05, 0.1, 0.01, 0.4, 0.5, 0.6, 0.7, 0.8],
9+
"disturblabel": [0.3, 0.05, 0.01, 0.2, 0.1, 0.4, 0.425, 0.45, 0.5, 0.525, 0.55, 0.575, 0.6],
10+
"noise": [0.01, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35],
11+
"cutout": [8, 4, 12, 16, 20],
12+
"mixup": [0.5, 0.1, 0.25, 1, 2, 4, 8, 16, 32, 64, 128, 256],
13+
"jitter": [0.05, 0.1, 0.2, 0.15, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5],
14+
"trades": [],
15+
"pgdat": [],
16+
"AWP": [],
17+
"TradesAWP": []
18+
}
19+
}

configs/locations.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"note": "modified from https://github.com/yigitcankaya/augmentation_mia",
3+
"training_num_epochs": 50,
4+
"regular_batch_size": 256,
5+
"training_augmentations": ["none", "base", "smooth", "disturblabel", "noise", "distillation", "01flip"],
6+
"augmentation_params": {
7+
"distillation": [3, 1, 2, 5, 10],
8+
"smooth": [0.05, 0.01, 0.2, 0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
9+
"disturblabel": [0.05, 0.01, 0.2, 0.1, 0.3, 0.4, 0.425, 0.45, 0.5, 0.525, 0.55, 0.575, 0.6],
10+
"noise": [0.35, 0.01, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325],
11+
"trades": [],
12+
"pgdat": [],
13+
"AWP": [],
14+
"TradesAWP": [],
15+
"01flip": [0.1, 0.05, 0.2, 0.01, 0.3]
16+
}
17+
}

configs/purchase.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"note": "modified from https://github.com/yigitcankaya/augmentation_mia",
3+
"training_num_epochs": 50,
4+
"regular_batch_size": 256,
5+
"training_augmentations": ["none", "base", "smooth", "disturblabel", "noise", "distillation", "01flip"],
6+
"augmentation_params": {
7+
"distillation": [3, 1, 2, 5, 10],
8+
"smooth": [0.05, 0.2, 0.1, 0.01, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
9+
"disturblabel": [0.2, 0.01, 0.05, 0.1, 0.3, 0.4, 0.425, 0.45, 0.5, 0.525, 0.55, 0.575, 0.6],
10+
"noise": [0.01, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35],
11+
"trades": [],
12+
"pgdat": [],
13+
"AWP": [],
14+
"TradesAWP": [],
15+
"01flip": [0.01, 0.05, 0.2, 0.1, 0.3]
16+
}
17+
}

configs/svhn.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"note": "modified from https://github.com/yigitcankaya/augmentation_mia",
3+
"training_num_epochs": 100,
4+
"regular_batch_size": 256,
5+
"training_augmentations": ["none", "base", "smooth", "disturblabel", "noise", "cutout", "mixup", "jitter", "pgdat", "trades", "distillation", "AWP", "TradesAWP"],
6+
"augmentation_params": {
7+
"distillation": [3, 1, 2, 5, 10],
8+
"smooth": [0.2, 0.05, 0.1, 0.01, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
9+
"disturblabel": [0.05, 0.01, 0.2, 0.1, 0.3, 0.4, 0.425, 0.45, 0.5, 0.525, 0.55, 0.575, 0.6],
10+
"noise": [0.01, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35],
11+
"cutout": [8, 4, 12, 16, 20],
12+
"mixup": [0.5, 0.1, 0.25, 1, 2, 4, 8, 16, 32, 64, 128, 256],
13+
"jitter": [0.05, 0.1, 0.2, 0.15, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5],
14+
"trades": [],
15+
"pgdat": [],
16+
"AWP": [],
17+
"TradesAWP": []
18+
}
19+
}

0 commit comments

Comments
 (0)