-
Notifications
You must be signed in to change notification settings - Fork 18
/
train_v23.py
91 lines (74 loc) · 4.16 KB
/
train_v23.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
import argparse
from pprint import pprint
import torch
from experiments.classification_private import ClassificationPrivateExperiment
torch.backends.cudnn.benchmark = True
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--arch', default='alexnet', choices=['alexnet', 'resnet'],
help='architecture (default: alexnet)')
parser.add_argument('--batch-size', type=int, default=64,
help='batch size (default: 64)')
parser.add_argument('--epochs', type=int, default=200,
help='training epochs (default: 200)')
parser.add_argument('--lr', type=float, default=0.01,
help='learning rate (default: 0.01)')
parser.add_argument('--dataset', default='cifar10', choices=['cifar10',
'cifar100',
'caltech-101',
'caltech-256',
'imagenet1000'],
help='training dataset (default: cifar10)')
parser.add_argument('--norm-type', default='bn', choices=['bn', 'gn', 'in', 'none'],
help='norm type (default: bn)')
# passport argument
parser.add_argument('--key-type', choices=['random', 'image', 'shuffle'], default='shuffle',
help='passport key type (default: shuffle)')
parser.add_argument('--sign-loss', type=float, default=0.1,
help='sign loss to avoid scale not trainable (default: 0.1)')
parser.add_argument('--use-trigger-as-passport', action='store_true', default=False,
help='use trigger data as passport')
parser.add_argument('--train-passport', action='store_true', default=False,
help='train passport')
parser.add_argument('--train-backdoor', action='store_true', default=False,
help='train backdoor, adding backdoor images for blackbox detection')
parser.add_argument('--train-private', action='store_true', default=True,
help='train private') # always true for v2 and v3
# paths
parser.add_argument('--pretrained-path',
help='load pretrained path')
parser.add_argument('--lr-config', default='lr_configs/default.json',
help='lr config json file')
parser.add_argument('--passport-config', default='passport_configs/alexnet_passport.json',
help='should be same json file as arch')
# misc
parser.add_argument('--save-interval', type=int, default=0,
help='save model interval')
parser.add_argument('--eval', action='store_true', default=False,
help='for evaluation')
parser.add_argument('--exp-id', type=int, default=1,
help='experiment id')
parser.add_argument('--tag',
help='tag')
# transfer learning
parser.add_argument('--transfer-learning', action='store_true', default=False,
help='turn on transfer learning')
parser.add_argument('--tl-dataset', default='cifar100', choices=['cifar10',
'cifar100',
'caltech-101',
'caltech-256',
'imagenet1000'],
help='transfer learning dataset (default: cifar100)')
parser.add_argument('--tl-scheme', default='rtal', choices=['rtal',
'ftal'],
help='transfer learning scheme (default: rtal)')
args = parser.parse_args()
pprint(vars(args))
exp = ClassificationPrivateExperiment(vars(args))
if exp.is_tl:
exp.transfer_learning()
else:
exp.training()
print('Training done at', exp.logdir)
if __name__ == '__main__':
main()