I figure it out. The last line has to assign
img.data = torch.clamp(img + epsilon * torch.sign(img.grad.data), 0.0, 1.0) # make sure it is a valid image
not what I had originally
img = torch.clamp(img + epsilon * torch.sign(img.grad), 0.0, 1.0) # make sure it is a valid image
I’m not sure what this difference means… It seems like rather than creating a new tensor every loop, I simply change the data on the existing tensor… But I’m not sure. Would appreciate a clear explanation on what .data is of a tensor. Does it simply refer to the underlying values inside the tensor?