fra31 / sparse-rs

Sparse-RS: a versatile framework for query-efficient sparse black-box adversarial attacks
https://arxiv.org/abs/2006.12834
MIT License
44 stars 6 forks source link

Error occurs when using patches_universal #6

Open WillBuyingFrog opened 2 years ago

WillBuyingFrog commented 2 years ago

Hello, The error argument 'size' (position 1) must be tuple of ints, not Tensor always occur at 60% progress of the funciton attack_single_run() when I tried to run the code with the following command:

CUDA_VISIBLE_DEVICES=0 python eval.py \
    --norm=patches_universal --model=pt_vgg \
    --n_queries=100000 --alpha_init=0.3 \
    --data_path=../frogdata/ILSVRC2012_val --k=2500 \
    --n_ex=30 --targeted --target_class=530

Where ../frogdata/ILSVRC2012_val is the path to the imagenet validation set.

The error reports is like: sparse-rs-issue

I used the latest stable version of PyTorch at first. Then I tried to switch to PyTorch 1.8.0 and Python3.8.5 according to README.md in the repository, but that doesn't help, so I decided to post an issue here to seek for help.

Thank you for your fascinating work and any help given!

fra31 commented 2 years ago

Hi,

thanks for interest in our work! I think it's sufficient to modify https://github.com/fra31/sparse-rs/blob/21d875969a1455e4d5b26dcf32c843e6262d1f9c/rs_attacks.py#L572 to

new_clr = self.random_choice(new_clr.shape).clone().clamp(0., 1.)

If this solves your issue, I'll update the code too. Thanks for letting me know!

WillBuyingFrog commented 2 years ago

Thank you for your help! The program runs smoothly after 60% of attack_single_run().

Unfortunately, when attack_single_run() returns, it still reports error:

patch_universal_issues

It seems that n_queries is not defined in patches_universalpart of the code. I tried to add the following line of code after line 538 like what frames_universal implements:

n_queries = torch.ones_like(y).float()

After I added the code, the programs runs ok. The only concern is that the changes I made probably doesn't match the paper's algorithm(actually I'm quite new to research and I may miss something when reading papers). Could you please check my changes mentioned above?

Thank you again for your help!

fra31 commented 2 years ago

I think it should be fine, for the universal attacks all queries should anyway be used for all points i.e. there's no early stopping. I'll update that as well, thanks!