device = torch.device("cuda:0") device2 = torch.device("cuda:0") seed = 2018 np.random.seed(seed=seed) torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) cudnn.benchmark = True sub_x, test_data, test_label = get_data(train_size=args.train_size) # oracle_model = Substitute(model=ResNet18(), save_path='stl10_checkpoint0/resnet_ckpt.t7', device=device) # net = torch.load('stl10_checkpoint0/rdcnn32_10000.pkl') # oracle_model = Oracle(model=Rh(num_layers=2, kernel_size=3, n=n_features),save_path='None',\ # svm_path='model/checkpoints_svm_3_2/svm.pkl', device=device) oracle_model = Oracle(model=None, save_path='None',\ svm_path='checkpoints/%s.pkl' % args.target, device=device) substitute_model = Substitute(model=LinearModel(in_node=32*32*3,num_classes=2), device=device2) a, b = stl10_bbox_sub(param=param, oracle_model=oracle_model, substitute_model=substitute_model, \ x_sub=sub_x, test_data=test_data, test_label=test_label, aug_epoch=param['data_aug'],\ samples_max=6400, n_epoch=param['nb_epochs'], fixed_lambda=param['lambda']) print('\n\nFinal results:') print('Oracle model evaluation on clean data #%d:'%(test_data.size(0))) oracle_model.eval(x=test_data, y=test_label, batch_size=oracle_size) print('Substitute model evaluation on clean data: #%d:'%(test_data.size(0))) substitute_model.eval(x=test_data, y=test_label, batch_size=512) # test_adv = get_adv(model=substitute_model, x=test_data, y=test_label, epsilon=param['epsilon']) # print('Substitute model FGSM attack itself\'s accuracy on adversarial samples #%d:'%(test_adv.size(0))) # substitute_model.eval(x=test_adv, y=test_label, batch_size=512) # print('Oracle model FGSM attack\'s accuracy on adversarial samples #%d:'%(test_adv.size(0))) # oracle_model.eval(x=test_adv, y=test_label, batch_size=512)
torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) cudnn.benchmark = True binarize = True if args.binarize else False sub_x, test_data, test_label = get_data(train_size=args.train_size) # nd_1 = noise_data(test_data, 0.3) # nd_2 = noise_data(test_data, 0.5) # oracle_model = Substitute(model=ResNet18(), save_path='stl10_checkpoint0/resnet_ckpt.t7', device=device) # net = torch.load('stl10_checkpoint0/rdcnn32_10000.pkl') # oracle_model = Oracle(model=Rh(num_layers=2, kernel_size=3, n=n_features),save_path='None',\ # svm_path='model/checkpoints_svm_3_2/svm.pkl', device=device) oracle_model = Oracle(model=None, save_path='None', \ # svm_path='checkpoints/%s' % args.target, svm_path=['checkpoints/%s_%d.h5' % (args.target, i) for i in range(100)], device=device) substitute_model = Substitute(model=LinearModel(in_node=image_shape, num_classes=args.n_classes), device=device) a, b, c, d = stl10_bbox_sub(param=param, oracle_model=oracle_model, substitute_model=substitute_model, \ x_sub=sub_x, test_data=test_data, test_label=test_label, aug_epoch=param['data_aug'], \ samples_max=6400, n_epoch=param['nb_epochs'], fixed_lambda=param['lambda']) print('\n\nFinal results:') print('Oracle model evaluation on clean data #%d:' % (test_data.size(0))) oracle_model.eval(x=test_data, y=test_label, batch_size=oracle_size) print('Substitute model evaluation on clean data: #%d:' % (test_data.size(0))) substitute_model.eval(x=test_data, y=test_label, batch_size=512) if not os.path.exists('results/%s' % args.dataset): os.makedirs('results/%s' % args.dataset) filename = 'results/%s/%s_%s_%s_%d.csv' % (args.dataset, args.target, str(param['epsilon']),
device = torch.device("cuda:0") device2 = torch.device("cuda:0") seed = 2018 np.random.seed(seed=seed) torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) cudnn.benchmark = True sub_x, test_data, test_label = get_data(train_size=args.train_size) # oracle_model = Substitute(model=ResNet18(), save_path='imagenet_checkpoint0/resnet_ckpt.t7', device=device) # net = torch.load('imagenet_checkpoint0/rdcnn32_10000.pkl') # oracle_model = Oracle(model=Rh(num_layers=2, kernel_size=3, n=n_features),save_path='None',\ # svm_path='model/checkpoints_svm_3_2/svm.pkl', device=device) oracle_model = Oracle(model=None, save_path='None',\ svm_path='checkpoints/%s.pkl' % args.target, device=device) substitute_model = Substitute(model=LinearModel(in_node=224 * 224 * 3, num_classes=2), device=device2) a, b = imagenet_bbox_sub(param=param, oracle_model=oracle_model, substitute_model=substitute_model, \ x_sub=sub_x, test_data=test_data, test_label=test_label, aug_epoch=param['data_aug'],\ samples_max=6400, n_epoch=param['nb_epochs'], fixed_lambda=param['lambda']) print('\n\nFinal results:') print('Oracle model evaluation on clean data #%d:' % (test_data.size(0))) oracle_model.eval(x=test_data, y=test_label, batch_size=oracle_size) print('Substitute model evaluation on clean data: #%d:' % (test_data.size(0))) substitute_model.eval(x=test_data, y=test_label, batch_size=512) # test_adv = get_adv(model=substitute_model, x=test_data, y=test_label, epsilon=param['epsilon']) # print('Substitute model FGSM attack itself\'s accuracy on adversarial samples #%d:'%(test_adv.size(0))) # substitute_model.eval(x=test_adv, y=test_label, batch_size=512)