Harry24k / adversarial-attacks-pytorch

PyTorch implementation of adversarial attacks [torchattacks].
https://adversarial-attacks-pytorch.readthedocs.io/en/latest/index.html
MIT License
1.79k stars 337 forks source link

[QUESTION]The 'inf' in 'deepfool.py' #156

Closed songty21110133 closed 1 year ago

songty21110133 commented 1 year ago

❔ Any questions

Dear author, I was using the DeepFool method for my classification task. But I have been getting this error(using CPU) :

Traceback (most recent call last):
  File "train.py", line 198, in <module>
    main()
  File "train.py", line 195, in main
    train(args.fold)
  File "train.py", line 162, in train
    generate_attack_data(net,train_dataloader,fold,config.data_config)
  File "/root/workspace/SDAANet/attack.py", line 16, in generate_attack_data
    adv_images = attack(images, labels)
  File "/root/miniconda3/lib/python3.8/site-packages/torchattacks/attack.py", line 452, in __call__
    adv_inputs = self.forward(inputs, labels, *args, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/torchattacks/attacks/deepfool.py", line 57, in forward
    early_stop, pre, adv_image = self._forward_indiv(adv_images[idx], labels[idx])
  File "/root/miniconda3/lib/python3.8/site-packages/torchattacks/attacks/deepfool.py", line 92, in _forward_indiv
    value[label] = float('inf')
IndexError: index 1 is out of bounds for dimension 0 with size 1

I found that value[label] = float('inf') doesn't show in the github repositories but in the v3.4.0. I think it is a bug, isn't it?

rikonaka commented 1 year ago

Hi @songty21110133, this is a bug, please reinstall torchattacks from source. 😜

songty21110133 commented 1 year ago

thank you very much!