parser = argparse.ArgumentParser() parser.add_argument('--val', action='store_true', help='weither to run validation') parser.add_argument('--bench', action='store_true', help = 'weither to generate results on benchmark dataset') parser.add_argument('--smooth', action='store_true', help = 'weither to generator smootGrad results on benchmark dataset') parser.add_argument('--gen', action = 'store_true', help = 'weither to generate Large eps adversarial examples on benchmark data') parser.add_argument('--resume', type=str, default=None, help='checkpoint path') args = parser.parse_args() clock = TrainClock() clock.epoch = 21 net = ant_model() net.cuda() if args.resume: if os.path.isfile(args.resume): print("=> loading checkpoint '{}'".format(args.resume)) check_point = torch.load(args.resume) net.load_state_dict(check_point['state_dict']) print('Modeled loaded from {} with metrics:'.format(args.resume)) else: print("=> no checkpoint found at '{}'".format(args.resume)) base_path = os.path.split(args.resume)[0] else: base_path = './'
best_prec = 0.0 if args.resume: if os.path.isfile(args.resume): print("=> loading checkpoint '{}'".format(args.resume)) check_point = torch.load(args.resume) args.start_epoch = check_point['epoch'] net.load_state_dict(check_point['state_dict']) best_prec = check_point['best_prec'] print('Modeled loaded from {} with metrics:'.format(args.resume)) print(results) else: print("=> no checkpoint found at '{}'".format(args.resume)) clock.epoch = args.start_epoch #for epoch in ds_train.epoch_generator(): while True: if clock.epoch > args.epochs: break adjust_learning_rate(optimizer, clock.epoch) Trainresults = adversairal_train_one_epoch(net, optimizer, ds_train, criterion, PgdAttack, clock, attack_freq=args.adv_freq, use_adv=not args.no_adv, DEVICE=DEVICE)