cg563 / simple-blackbox-attack

Code for ICML 2019 paper "Simple Black-box Adversarial Attacks"
MIT License
191 stars 56 forks source link

The difference between predictions and labels #4

Closed postBG closed 4 years ago

postBG commented 4 years ago

Hi, Thanks for sharing your code. I have a question about labels and predictions in your code. It would be helpful if you answer to my question.

model = getattr(models, args.model)(pretrained=True).cuda()
batchfile = '%s/images_%s_%d.pth' % (args.sampled_image_dir, args.model, args.num_runs)
checkpoint = torch.load(batchfile)
images = checkpoint['images']
labels = checkpoint['labels']

preds, _ = utils.get_preds(model, images[args.image_idx].unsqueeze(0), 'imagenet', batch_size=args.batch_size)
print(preds)
print(labels[args.image_idx])

When I test the code with this code, the values of preds and labels[args.image_idx] are different. Can you explain why the values are different? I have run your code to generate the batchfile.

I used this script for set-up the val folder.

cg563 commented 4 years ago

They should be the same unless your model changed between when the batchfile was generated and when you run this snippet. One possibility that I can see is that the model is not run in .eval() mode, so the batch statistics is different than the stored batch normalization statistics. Can you verify this?

postBG commented 4 years ago

Hi, Thanks for helping me. Yes, that was the problem. I omitted the .eval. My bad.