Skip to content

Commit

Permalink
Merge pull request #1212 from redwrasse/arctanh
Browse files Browse the repository at this point in the history
use torch builtin arctanh method
  • Loading branch information
jonasguan authored Jul 24, 2021
2 parents 1115738 + 710e34b commit c83898f
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions cleverhans/torch/attacks/carlini_wagner_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,10 @@ class (int).
o_bestattack = x.clone().detach()

# Map images into the tanh-space
# TODO as of 01/06/2020, PyTorch does not natively support
# arctanh (see, e.g.,
# https://github.com/pytorch/pytorch/issues/10324).
# This particular implementation here is not numerically
# stable and should be substituted w/ PyTorch's native
# implementation when it comes out in the future
arctanh = lambda x: 0.5 * torch.log((1 + x) / (1 - x))
x = (x - clip_min) / (clip_max - clip_min)
x = torch.clamp(x, 0, 1)
x = x * 2 - 1
x = arctanh(x * 0.999999)
x = torch.arctanh(x * 0.999999)

# Prepare some variables
modifier = torch.zeros_like(x, requires_grad=True)
Expand Down

0 comments on commit c83898f

Please sign in to comment.