Foolbox:对抗性LBFGS

时间:2018-06-29 20:48:15

标签: resnet

const req = yield call(request, `${requestURL}?idUser=10&search=something`, {
   method: 'GET'
});

import foolbox import torch import torchvision.models as models import numpy as np from foolbox.criteria import TargetClassProbability target_class = 404 #https://gist.github.com/ageitgey/4e1342c10a71981d0b491e1b8227328b criterion = TargetClassProbability(target_class, p=0.85) # instantiate the model resnet18 = models.resnet18(pretrained=True).eval() if torch.cuda.is_available(): resnet18 = resnet18.cuda() mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1)) std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1)) fmodel = foolbox.models.PyTorchModel( resnet18, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std)) # get source image and label image, label = foolbox.utils.imagenet_example(data_format='channels_first') image = image / 255. # because our model expects values in [0, 1] print('label', label) print('predicted class', np.argmax(fmodel.predictions(image))) # apply attack on source image attack = foolbox.attacks.LBFGSAttack(fmodel,criterion) adversarial = attack(image, label) print('adversarial class', np.argmax(fmodel.predictions(adversarial))) 是否应该给出最大概率,为什么它会在11.00左右而不是应该的> 85?

0 个答案:

没有答案