Parse input arguments (train.py).
()
| 9 | |
| 10 | |
| 11 | def parser_train(): |
| 12 | """ |
| 13 | Parse input arguments (train.py). |
| 14 | """ |
| 15 | parser = argparse.ArgumentParser(description='Standard + Adversarial Training.') |
| 16 | |
| 17 | parser.add_argument('--augment', type=str2bool, default=True, help='Augment training set.') |
| 18 | parser.add_argument('--batch-size', type=int, default=128, help='Batch size for training.') |
| 19 | parser.add_argument('--batch-size-validation', type=int, default=256, help='Batch size for testing.') |
| 20 | parser.add_argument('--num-samples-eval', type=int, default=512, help='Number of samples to use for margin calculations.') |
| 21 | |
| 22 | parser.add_argument('--data-dir', type=str, default='/cluster/scratch/rarade/data/') |
| 23 | parser.add_argument('--log-dir', type=str, default='/cluster/home/rarade/adversarial-hat/logs/') |
| 24 | parser.add_argument('--tmp-dir', type=str, default='/cluster/scratch/rarade/') |
| 25 | |
| 26 | parser.add_argument('-d', '--data', type=str, default='cifar10', choices=DATASETS, help='Data to use.') |
| 27 | parser.add_argument('--desc', type=str, required=True, |
| 28 | help='Description of experiment. It will be used to name directories.') |
| 29 | |
| 30 | parser.add_argument('-m', '--model', choices=MODELS, default='resnet18', help='Model architecture to be used.') |
| 31 | parser.add_argument('--normalize', type=str2bool, default=False, help='Normalize input.') |
| 32 | parser.add_argument('--pretrained-file', type=str, default=None, help='Pretrained weights file name.') |
| 33 | |
| 34 | parser.add_argument('-ns', '--num-std-epochs', type=int, default=0, help='Number of standard training epochs.') |
| 35 | parser.add_argument('-na', '--num-adv-epochs', type=int, default=0, help='Number of adversarial training epochs.') |
| 36 | parser.add_argument('--adv-eval-freq', type=int, default=30, help='Adversarial evaluation frequency (in epochs).') |
| 37 | |
| 38 | parser.add_argument('--h', default=2.0, type=float, help='Parameter h to compute helper examples (x + h*r) for HAT.') |
| 39 | parser.add_argument('--helper-model', type=str, default=None, help='Helper model weights file name for HAT.') |
| 40 | parser.add_argument('--beta', default=None, type=float, help='Stability regularization, i.e., 1/lambda in TRADES \ |
| 41 | or weight of robust loss in HAT.') |
| 42 | parser.add_argument('--gamma', default=1.0, type=float, help='Weight of helper loss in HAT.') |
| 43 | parser.add_argument('--robust-loss', default='kl', choices=['ce', 'kl'], type=str, help='Type of robust loss in HAT.') |
| 44 | |
| 45 | parser.add_argument('--lr', type=float, default=0.21, help='Learning rate for optimizer (SGD).') |
| 46 | parser.add_argument('--weight-decay', type=float, default=5e-4, help='Optimizer (SGD) weight decay.') |
| 47 | parser.add_argument('--scheduler', choices=SCHEDULERS, default='cyclic', help='Type of scheduler.') |
| 48 | parser.add_argument('--nesterov', type=str2bool, default=True, help='Use Nesterov momentum.') |
| 49 | parser.add_argument('--clip-grad', type=float, default=None, help='Gradient norm clipping.') |
| 50 | |
| 51 | parser.add_argument('-a', '--attack', type=str, choices=ATTACKS, default='linf-pgd', help='Type of attack.') |
| 52 | parser.add_argument('--attack-eps', type=str2float, default=8/255, help='Epsilon for the attack.') |
| 53 | parser.add_argument('--attack-step', type=str2float, default=2/255, help='Step size for PGD attack.') |
| 54 | parser.add_argument('--attack-iter', type=int, default=10, help='Max. number of iterations (if any) for the attack.') |
| 55 | parser.add_argument('--keep-clean', type=str2bool, default=False, help='Use clean samples during adversarial training.') |
| 56 | |
| 57 | parser.add_argument('--debug', action='store_true', default=False, |
| 58 | help='Debug code. Run 1 epoch of training and evaluation.') |
| 59 | parser.add_argument('--exp', action='store_true', default=False, |
| 60 | help='Store results for performing margin and curvature experiments later.') |
| 61 | parser.add_argument('--mart', action='store_true', default=False, help='MART training.') |
| 62 | |
| 63 | parser.add_argument('--unsup-fraction', type=float, default=0.5, help='Ratio of unlabelled data to labelled data.') |
| 64 | parser.add_argument('--aux-data-filename', type=str, help='Path to additional Tiny Images data.', |
| 65 | default='/cluster/scratch/rarade/cifar10s/ti_500K_pseudo_labeled.pickle') |
| 66 | |
| 67 | parser.add_argument('--seed', type=int, default=1, help='Random seed.') |
| 68 | return parser |
no outgoing calls
no test coverage detected
searching dependent graphs…