I wanted to reproduce:

Screen Shot 2018-03-29 at 10.26.56 AM.png1342×106 11.9 KB

from the paper https://arxiv.org/pdf/1312.6199.pdf 13. I was wondering, how does one actually implement this in pytorch? My main confusion is that for loss_f I am using a torch.nn.CrossEntropy() criterion for example. Do i just need to change the code that I already have from:
loss = criterion(outputs+r, labels)
loss.backward()

to:
loss = criterion(outputs+r, labels)
loss = loss + c * r.norm(2)
loss.backward()

or something along those lines. I know its not quite right cuz I did not explicitly show how I implemented x+r or the hypercube constraint but those are parts that I still need to figure out.


  
      stackoverflow.com
  
  
      
    
  

  How does one implement adversarial examples in pytorch? 29



  python, machine-learning, neural-network, conv-neural-network



  asked by
  
  
    Charlie Parker
  
  on 01:20AM - 21 Apr 18 UTC