cleverhans-lab / cleverhans

An adversarial example library for constructing attacks, building defenses, and benchmarking both
MIT License
6.16k stars 1.39k forks source link

Implement HopSkipJump in PyTorch #1148

Closed iamgroot42 closed 4 years ago

iamgroot42 commented 4 years ago

Tested attack locally (in both modes) with some models of my own as well. Ported tests from main TF version as well.

Jianbo-Lab commented 4 years ago

Great thanks for taking your time to implement HopSkipJumpAttack in PyTorch, @iamgroot42 ! I have read through the script and there remains one question to this line: Line 287: _, idx = torch.min(dists, 0) Suppose in the extreme case when several values in dists are equal. Then idx will become a k-hot vector, with k boolean Trues. That will cause some unexpected behaviors in Line 290: out_image = out_images[idx].unsqueeze(0). Of course this only affects grid search which does not the default choice of HSJA.

iamgroot42 commented 4 years ago

@Jianbo-Lab thanks for your feedback! I see what you mean here, but I think Pytorch handles equal values in torch.min() the same way numpy does. So even if some values are the same, it won't be a k-hot vector. You can try it yourself in Pytorch and see:

image

Jianbo-Lab commented 4 years ago

@iamgroot42 Thanks for the clarification! BTW, feel free to @ me when future changes are made to HSJA, so that I can review them without delay.

I have gone through the code and think it is ready to merge @npapernot .

iamgroot42 commented 4 years ago

Messed up the commits in here. Opening another PR for this attack