# argument parser parser = argparse.ArgumentParser(description='Joint Adversarial Defense') parser.add_argument('--lr', default=0.01, type=float, help='learning rate') parser.add_argument('--steps', default=10, type=int, help='adv. steps') parser.add_argument('--eps', required=True, type=float, help='max norm') parser.add_argument('--dataset', required=True, type=str, help='dataset name') parser.add_argument('--network', required=True, type=str, help='network name') parser.add_argument('--data_root', required=True, type=str, help='path to dataset') parser.add_argument('--epoch', default=60, type=int, help='epoch number') parser.add_argument('--attack', default='pgd', type=str, help='attack type') parser.add_argument('--save_dir', default='./experiment', type=str, help='save directory') args = parser.parse_args() # loading dataset, network, and attack trainloader, testloader = dataset_loader(args) net = network_loader(args, mean=args.mean, std=args.std).cuda() attack = attack_loader(args, net) # Adam Optimizer with KL divergence, and Scheduling Learning rate optimizer = torch.optim.SGD(net.parameters(), lr=args.lr, momentum=0.9, weight_decay=1e-2) scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=20, gamma=0.2) # Setting checkpoint date time date_time = datetime.today().strftime("%m%d%H%M") # checkpoint_name checkpoint_name = 'LP_'+args.network+'_'+args.dataset+'_'+date_time+'.pth' # argument print argument_print(args, checkpoint_name)
parser.add_argument('--eps', default=0.03, type=float, help='max norm') parser.add_argument('--dataset', default='cifar10', type=str, help='dataset name') parser.add_argument('--network', default='vgg', type=str, help='network name') parser.add_argument('--data_root', default='./datasets', type=str, help='path to dataset') parser.add_argument('--save_dir', default='./experiment', type=str, help='save directory') parser.add_argument('--datetime', default=10, type=str, help='checkpoint datetime') parser.add_argument('--baseline', default='LP', type=str, help='baseline') # 0: plain, 1: AT, 2: RFM, 3: mAT, 4: LP, 5: trade args = parser.parse_args() checkpoint_name = args.baseline+'_'+args.network+'_'+args.dataset+'_'+args.datetime+'.pth' # loading dataset, network, attack _, testloader = dataset_loader(args) if "OEM" in args.baseline: args.isinitialize=True net = OEM_network_loader(args, mean=args.mean, std=args.std).cuda() net.load_state_dict(torch.load(os.path.join(args.save_dir, checkpoint_name))['model_state_dict']) net.eval() else: if "Plain" in args.baseline: args.attack="Plain" else: args.attack="AT" net = network_loader(args, mean=args.mean, std=args.std).cuda() net.load_state_dict(torch.load(os.path.join(args.save_dir, checkpoint_name))['model_state_dict']) print('Total number of Model Parameters is: {}M\n'.format(sum(p.numel() for p in net.parameters() if p.requires_grad)/1000000))