forked from peterhan91/Medical-Robust-Training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargument.py
56 lines (48 loc) · 3 KB
/
argument.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
import argparse
def parser():
parser = argparse.ArgumentParser(description='Video Summarization')
parser.add_argument('--todo', choices=['train', 'valid', 'test', 'visualize'], default='train',
help='what behavior want to do: train | valid | test | visualize')
parser.add_argument('--dataset', default='chexpert', help='use what dataset')
parser.add_argument('--subsample', type=float, default=0)
parser.add_argument('--data_root', default='../CheXpert_Dataset/images_256/images/',
help='the directory to save the dataset')
parser.add_argument('--log_root', default='log',
help='the directory to save the logs or other imformations (e.g. images)')
parser.add_argument('--model_root', default='checkpoint', help='the directory to save the models')
parser.add_argument('--load_checkpoint', default='./oldmodel/')
parser.add_argument('--affix', default='default', help='the affix for the save folder')
# parameters for generating adversarial examples
parser.add_argument('--epsilon', '-e', type=float, default=0.005,
help='maximum perturbation of adversaries (4/255=0.0157)')
parser.add_argument('--alpha', '-a', type=float, default=0.0025,
help='movement multiplier per iteration when generating adversarial examples (2/255=0.00784)')
parser.add_argument('--k', '-k', type=int, default=10,
help='maximum iteration when generating adversarial examples')
parser.add_argument('--widefactor', type=int, default=1,
help='Factors for expanding the bottleneck layers of ResNet')
parser.add_argument('--pretrain', type=bool, default=False,
help='Use ImageNet pretraining or not')
parser.add_argument('--batch_size', '-b', type=int, default=64, help='batch size')
parser.add_argument('--max_epoch', '-m_e', type=int, default=300,
help='the maximum numbers of the model see a sample')
parser.add_argument('--learning_rate', '-lr', type=float, default=1e-2, help='learning rate')
parser.add_argument('--weight_decay', '-w', type=float, default=0,
help='the parameter of l2 restriction for weights')
parser.add_argument('--gpu', '-g', default='0', help='which gpu to use')
parser.add_argument('--n_eval_step', type=int, default=50,
help='number of iteration per one evaluation')
parser.add_argument('--n_checkpoint_step', type=int, default=5000,
help='number of iteration to save a checkpoint')
parser.add_argument('--n_store_image_step', type=int, default=5000,
help='number of iteration to save adversaries')
parser.add_argument('--perturbation_type', '-p', choices=['linf', 'l2'], default='linf',
help='the type of the perturbation (linf or l2)')
parser.add_argument('--adv_train', action='store_true')
return parser.parse_args()
def print_args(args, logger=None):
for k, v in vars(args).items():
if logger is not None:
logger.info('{:<16} : {}'.format(k, v))
else:
print('{:<16} : {}'.format(k, v))