Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-084

FGSM Attack Step

Problem

One fast gradient sign method step: x_adv = x + epsilon * sign(grad), where sign(0) = 0. Both x and grad are 2D matrices of the same shape.

The signature is fgsm_step(x, grad, epsilon).

Hint

FGSM moves every input in the direction that most increases the loss, by a fixed step.

Test cases

case 1
in: [[[1,2],[1,-1]],[[1,1],[1,-1]],0.1]
expected: [[1.1,2.1],[1.1,-1.1]]
case 2
in: [[[0],[5]],[[1],[1]],0.5]
expected: [[0.5],[5.5]]
case 3
in: [[[-1,1],[-1,1]],[[-1,1],[-1,1]],1]
expected: [[-2,2],[-2,2]]
case 4
in: [[[1],[0]],[[0],[0]],0.5]
expected: [[1],[0]]
Starter codePython
def fgsm_step(x, grad, epsilon):
    # Your code here
    pass

4 test cases · run your code against them in the editor