Closed hechtlinger closed 5 years ago
It seems that one way to solve the issue is just to define the preprocessing transformation to be the identity and feed in the attack the input post preprocessing, adjusting the bounds accordingly. I'd close the issue, but it'll be great if there is more elegant solution.
images_preprocess = preprocess_input(images.copy())
preprocessing = (np.array([0, 0, 0]), 1)
fmodel = foolbox.models.KerasModel(kmodel, bounds=(images_preprocess.min(), images_preprocess.max()), preprocessing=preprocessing)
ix = 0
image = images_preprocess[ix]
label = labels[ix]
FGSM_attack = foolbox.attacks.FGSM(fmodel)
FGSM_adversarial = FGSM_attack(image, label)
I'm having problems implementing attacks on ResNet50. The documentation example works, but as I try to run it on the imagenet samples from foolbox.utils.samples it stops working. Unlike the example, the samples doesn't need the RGB -> BGR transformation,which might be what cause the problem with the preprocessing step.
Here is a short code showing the problem. The problem is happening with all the pictures, also when loading independently from imagenet validation, therefore likely related to the way the pictures are loaded into the model.