def generateAdv(self, num_steps, epsilon, alpha): device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") if (torch.cuda.get_device_capability(0) < (5, 0)): device = torch.device("cpu") model = modelcnn.Net() model.loadModel(pretrained_model="saved_model_state_CNN_final.pth") adv = AdvGenerator() model = model.to(device) testloader = adv.loadData() for target_label in adv.labels[:4]: for data in testloader: image, labels = data image, labels = image.to(device), labels.to(device) image.requires_grad = True output = model.forward(image) adv.createIterativeAdversarial(image, target_label.item(), output, epsilon, alpha, num_steps, model) adv.moveUsedImage()
for data in testloader: image, labels = data image, labels = image.to(device), labels.to(device) image.requires_grad = True output = model.forward(image) adv.createIterativeAdversarial(image, target_label.item(), output, epsilon, alpha, num_steps, model) adv.moveUsedImage() if __name__ == "__main__": model = modelcnn.Net() model.loadModel(pretrained_model="saved_model_state_CNN_final.pth") adv = AdvGenerator() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model = model.to(device) testloader = adv.loadData() for target_label in adv.labels[:4]: for data in testloader: image, labels = data image, labels = image.to(device), labels.to(device) image.requires_grad = True output = model.forward(image) adv.createIterativeAdversarial(image, target_label.item(), output,