Hi, I’m trying to make images which will fool model, but I have some problem with this code. In the second iteration I get TypeError: unsupported operand type(s) for -: 'Tensor' and 'NoneType'
Why is the grad NoneType even if it’s working for the first time?
X_fooling = X.clone()
X_fooling.requires_grad_()
loss_f = torch.nn.MSELoss()
for i in range(1000):
score = model(X_fooling)
y = torch.zeros(1000)
y[target_y] = 1
loss = loss_f(score, y)
print(loss)
loss.backward()
if target_y == torch.argmax(score):
break
X_fooling = X_fooling - X_fooling.grad