rwightman / pytorch-nips2017-attack-example

A PyTorch baseline attack example for the NIPS 2017 adversarial competition
https://www.kaggle.com/c/nips-2017-targeted-adversarial-attack
Apache License 2.0
84 stars 27 forks source link

clip min/max issue #3

Closed kkew3 closed 6 years ago

kkew3 commented 6 years ago

In Towards evaluating the robustness of neural network paper, the author clipped the pixel values to within range [0.0, 1.0]. Moreover, by convention, PyTorch converts pixel values to [0, 1] too. However, in your code the default clip range is [-1, 1], which doesn't make sense to me. Could you explain a little bit? Thank you so much!

samxuxiang commented 6 years ago

The reason is that in pytorch a transformation is applied first before getting the input from the data loader. So image in range [0,1] will subtract some mean and divide by std. The normalized input image will now be in range [-1,1]. For this implementation, clipping is actually performed on the image after normalization, not on the original image. I would recommend you use codes from tensorflow if you want to follow what is being implemented in the paper. Of course, you could also remove the transformation operation from data loader and add it after the data has been fetched.