cg563 / simple-blackbox-attack

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

why the code run slowly? #11

Closed 1374839016 closed 3 years ago

1374839016 commented 4 years ago

I have read the paper and run the code,but I can't understand the function of some code below. while preds.ne(labels).sum() > 0: idx = torch.arange(0, images.size(0)).long()[preds.ne(labels)] for i in list(idx): images[i], labels[i] = testset[random.randint(0, len(testset) - 1)] preds[idx], _ = utils.get_preds(model, images[idx], 'imagenet', batch_size=args.batch_size) I don't know what your want to do with these code,but I run your code with P100 GPU,these five lines code will speed more than five hours when I attack about 1200 images.So can your explain the function of these code?If I can attack imagenet images without these code? Thanks.

cg563 commented 4 years ago

This part of the code is trying to sample a batch of images that are all correctly labeled. I think the reason why it will hang is if the model has a very low accuracy, so it takes a lot of time to resample the images until all of them are correctly labeled. It would be helpful for you to check the model's accuracy on the set of attacked images.

Sorry for the confusion. Let me know if this resolves your issue.

1374839016 commented 4 years ago

Thanks for your help,I understand the code with your explanation. But I use the inception_v3 model provided by Pytorch,so I think it's not because the low accuracy of my model.I will check for other reasons.

maithal commented 3 years ago

I am facing the same issue, were you able to solve it? I am using the original code ResNet50 model and reduced the batch size to 16 since the CUDA error was occurring. Please assist!