ddkang / advex-uar

Code for "Testing Robustness Against Unforeseen Adversaries"
Apache License 2.0
80 stars 15 forks source link

Gabor attack breaks in PyTorch 1.8 #5

Closed cassidylaidlaw closed 2 years ago

cassidylaidlaw commented 3 years ago

Trying to run a Gabor attack with PyTorch 1.8 produces the following error:

  File "/scratch1/claidlaw/gradient-robustness/venv/lib/python3.7/site-packages/advex_uar/attacks/attacks.py", line 89, in forward
    pixel_ret = self._forward(pixel_model, pixel_img, *args, **kwargs)
  File "/scratch1/claidlaw/gradient-robustness/venv/lib/python3.7/site-packages/advex_uar/attacks/gabor_attack.py", line 81, in _forward
    gabor_noise = gabor_rand_distributed(gabor_vars, gabor_kernel)
  File "/scratch1/claidlaw/gradient-robustness/venv/lib/python3.7/site-packages/advex_uar/attacks/gabor.py", line 66, in gabor_rand_distributed
    return normalize_var(sp_conv)
  File "/scratch1/claidlaw/gradient-robustness/venv/lib/python3.7/site-packages/advex_uar/attacks/gabor.py", line 44, in normalize_var
    spec_var = torch.rfft(torch.pow(orig -  mean, 2), 2)
AttributeError: module 'torch' has no attribute 'rfft'

It looks like PyTorch changed where the FFT functions are located; now they're under torch.fft. I would submit a PR to fix this myself but I don't know much about signal processing/FFTs.

ddkang commented 3 years ago

I believe you can just replace torch.rfft with torch.fft.rfft

cassidylaidlaw commented 3 years ago

I tried that, but it looks like the signatures have changed with the renaming and I couldn’t figure out the right parameters.

ddkang commented 3 years ago

I see, could you try torch.fft.rfft2(torch.pow(orig - mean, 2)) ?

cassidylaidlaw commented 2 years ago

Fixed in #9