Hello all !
New in pytorch trying to code PGD .
I have this error for the second iteration :
sign(): argument ‘input’ (position 1) must be Tensor, not NoneType
I don’t understand why.
Any help/ advice would be appreciated .
Find bellow the code .
Thanks
def compute(self, x, y):
    #  x ( 100,1,28, 28) and  y = [100]
    x_adv = x.requires_grad_(True)
    for i in range(0,self.num_iter):
      print("--------iteration"+str(i)+"-----------------")
      print("x_adv", x_adv)
      criterion = nn.NLLLoss()
      prediction = self.model(x_adv) 
      loss =  criterion(prediction, y) 
      print("loss", loss)  
      loss.backward() 
      
      print(type(x_adv), x_adv.shape)
      x_adv.requires_grad_() 
      gradients = x_adv.grad
      print("gradients",gradients)
      gradients = self.alpha*torch.sign(gradients)
      print("gradients with sign and alpha ", gradients)
      x_adv = x_adv + gradients  
      print("x_adv + gradients ", x_adv )
      print(type(x_adv))
      #x_adv = torch.max(torch.min(x_adv, x + self.eps), x - self.eps) # Project back into l_norm ball and correct range