logger("=================FLAGS==================") for k, v in args.__dict__.items(): logger('{}: {}'.format(k, v)) logger("========================================") # seed args.cuda = torch.cuda.is_available() torch.manual_seed(args.seed) if args.cuda: torch.cuda.manual_seed(args.seed) # data loader and model assert args.type in ['cifar10', 'cifar100'], args.type train_loader, test_loader = dataset.get10(batch_size=args.batch_size, num_workers=1) model = model.cifar10(args=args, logger=logger) if args.cuda: model.cuda() optimizer = optim.SGD(model.parameters(), lr=1) decreasing_lr = list(map(int, args.decreasing_lr.split(','))) logger('decreasing_lr: ' + str(decreasing_lr)) best_acc, old_file = 0, None t_begin = time.time() grad_scale = args.grad_scale try: # ready to go for epoch in range(args.epochs): model.train()
logger('{}: {}'.format(k, v)) logger("========================================") # seed args.cuda = torch.cuda.is_available() torch.manual_seed(args.seed) if args.cuda: torch.cuda.manual_seed(args.seed) model_path = './log/default/batch_size=200/decreasing_lr=200,250/grad_scale=8/seed=117/type=cifar10/wl_activate=8/wl_error=8/wl_grad=8/wl_weight=8/latest.pth' # data loader and model assert args.type in ['cifar10', 'cifar100'], args.type train_loader, test_loader = dataset.get10(batch_size=args.batch_size, num_workers=1) modelCF = model.cifar10(args=args, logger=logger, pretrained=model_path) print(args.cuda) if args.cuda: modelCF.cuda() best_acc, old_file = 0, None t_begin = time.time() # ready to go modelCF.eval() test_loss = 0 correct = 0 trained_with_quantization = True # for data, target in test_loader: for i, (data, target) in enumerate(test_loader): if i == 0: hook_handle_list = hook.hardware_evaluation(modelCF, args.wl_weight,
import os from PIL import ImageOps from models import CompletionNetwork from utils import poisson_blend_old from grad_cam import GradCam ################################################## # PARAMETER SETTING ################################################## MODEL = 'cifar10_net.pth' MASK_COND = 0.7 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') BATCH_SIZE = 32 ################################################## # Load the backdoored model net = cifar10(128) net = net.to(device) net.load_state_dict(torch.load(MODEL)) net.eval() gcam = GradCam(net, True, device) print("Loading model successfully\n") # Data Loader # -------------- data_transforms = { 'train': transforms.Compose([ transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) ]),