Hi,



 Oualid:

# FGSM
def fgsm(model, X, y, epsilon):
    """ Construct FGSM adversarial examples on the examples X"""
    delta = torch.zeros_like(X, requires_grad=True)
    loss = nn.CrossEntropyLoss()(model(X + delta), y)
    loss.backward()
    return epsilon * delta.grad.detach().sign()



In the quoted part, I would check what’s the return value of model(x + delta), and I guess model(x+delta) returns a tuple of Tensors.



 Oualid:

# Initialize the model
# The model is defined in the class AlexnetTS in the file class_alexnetTS.py

from class_alexnetTS import AlexnetTS



Therefore, I’d reference the implementation of AlexnetTS.forward.