LTS4 / SparseFool

A fast sparse attack on deep neural networks.
Apache License 2.0
50 stars 11 forks source link

An error run test_sparsefool.py #1

Closed gmt710 closed 5 years ago

gmt710 commented 5 years ago

Hi,I have read your published paper and benefited from it. Thank you very much! I downloaded the code and ran test_sparsefool.py. I don't know if it's because of the torch version .There is an error:

Traceback (most recent call last):
  File "D:/pythonwork/SparseFool-master/test_sparsefool.py", line 22, in <module>
    net = torch_models.vgg16(pretrained=True)
TypeError: vgg16() got an unexpected keyword argument 'pretrained'

Process finished with exit code 1

I hope I can get your help,Thanks!!!

amodas commented 5 years ago

@gmt710 My guess is that it's a pytorch/torchvision issue. I'm not sure about torchvision 0.2.4 though. The official repo provides up to 0.2.1. Can you please try torchvision:0.2.1 and tell me if that fixes the problem?

Thanks!

gmt710 commented 5 years ago

@amodas I am so sorry,the version of torchvision is 0.2.1. Pytorch/Torchvision also update to the lastest one.How about yours ?Maybe I should download some other dependencies?

amodas commented 5 years ago

@gmt710 I am using the latest versions of pytorch (0.4.1) and torchvision (0.2.1) with CUDA support and it works fine. Everything is installed through conda, on a CentOS Linux 7 system, using python 2.7.15. I'm sorry but I cannot reproduce your error...

You can search if it is a common pytorch/torchvision problem; maybe other people had similar problems.

Also, make sure to pull the latest version of SparseFool; I fixed a bug on a "device" argument.

gmt710 commented 5 years ago

@amodas Hi,I'll configure the torch environment and try on Ubuntu18.04. I will reply you soon whether I have solved this problem or not.

amodas commented 5 years ago

@gmt710 Great! Yes, please let me know so as soon as you have a solution!

gmt710 commented 5 years ago

@amodas

1.On Ubuntu18.04,the pth file automatically download.The error between them no longer appears. image

2.But I enter the following command.

python3 test_sparsefool.py

There is an another error.

Traceback (most recent call last):
  File "test_sparsefool.py", line 54, in <module>
    x_adv, r, pred_label, fool_label, loops = sparsefool(im, net, lb, ub, lambda_, max_iter, device)
  File "/home/gmt/Adversarial/SparseFool-master/sparsefool.py", line 21, in sparsefool
    normal, x_adv = deepfool(x_i, net, lambda_, device)
  File "/home/gmt/Adversarial/SparseFool-master/deepfool.py", line 15, in deepfool
    I = I[0:num_classes]
TypeError: slice indices must be integers or None or have an __index__ method

I modify sparsefool.py line 21 like this: normal, x_adv = deepfool(im = x_i, net = net, lambda_fac = lambda_, num_classes=10, overshoot=0.02, max_iter=50,device = device)

The mistake is gone.

3.I enter the following command again.

python3 test_sparsefool.py

There is an another error: RuntimeError: CUDA error: out of memory

So I'm curious how much GPU memory is required to run this program.

amodas commented 5 years ago

It's good that the error is not there anymore.

As for the new problem, did you pull the latest changes? I made some changes to the device argument; you should not have the same error anymore.

As for the out of memory error, it is not related to the program; it loads a network and an image to the GPU. An out of memory might occur if you are already running something else on the GPU, and thus there's no memory left. Unless your GPU has a very low memory capacity...

Another possible explanation for the out of memory error, might have to do with the device argument. It needs to be changed in one more place. Can you please pull the latest changes and try again?

Thanks!

gmt710 commented 5 years ago

@amodas ,hi. I see the change of the file sparsefool.py in line 21:

normal, x_adv = deepfool(x_i, net, lambda_, device)
-->normal, x_adv = deepfool(x_i, net, lambda_, device=device)

So upset, my GPU is only 2GB.I might try it tomorrow in other machine.Good night.Thank you very much!!!

amodas commented 5 years ago

@gmt710 You might need more memory unfortunately...

I guess I am closing the issue... Good luck!

gmt710 commented 5 years ago

@amodas ,hi. Okay,I made it.

image

Thanks!!!