Start with a linear binary classifier. When classifying by the sign of f(x)=wβ€x+b, the smallest perturbation that changes the prediction is the perpendicular dropped from x0β to the boundary hyperplane {x:f(x)=0}.
rβ(x0β)=ββ₯wβ₯22βf(x0β)βw
For a nonlinear classifier, this is repeated. Around the current point xiβ, f is approximated by a first-order expression (f(xiβ)+βf(xiβ)β€r), and the point moves by the perpendicular to the boundary of that approximation, riβ=ββ₯βf(xiβ)β₯22βf(xiβ)ββf(xiβ). The process stops when the prediction changes.
For a multiclass classifier (which predicts the class k with the largest output fkβ), consider the boundaries between the original prediction k^(x0β) and each other class k. For a linear classifier, the region predicted as k^(x0β) is a polyhedron bounded by boundary hyperplanes, and dropping a perpendicular to the nearest face gives the smallest perturbation (right side of the header figure).
The procedure for a nonlinear classifier (Algorithm 2 in the paper) is as follows.
- Set x0β=x and compute the original prediction k^(x0β).
- For each class k other than the original prediction, compute the output difference fkβ²β=fkβ(xiβ)βfk^(x0β)β(xiβ) and the gradient difference wkβ²β=βfkβ(xiβ)ββfk^(x0β)β(xiβ).
- Choose the class l^ with the smallest distance β£fkβ²ββ£/β₯wkβ²ββ₯2β to its linearized boundary.
- Step perpendicular to that boundary: riβ=β₯wl^β²ββ₯22ββ£fl^β²ββ£βwl^β²β, xi+1β=xiβ+riβ.
- Repeat steps 2β4 until the prediction changes from k^(x0β), and return r^=βiβriβ.
So that the point does not stop exactly on the linearized boundary, the paper multiplies the final perturbation by (1+Ξ·) (Ξ·=0.02 in the experiments).
It works for distances other than β2. When measuring by the maximum change of any pixel (ββ), steps 3 and 4 are replaced with the following.
l^=argkξ =k^(x0β)minββ₯wkβ²ββ₯1ββ£fkβ²ββ£β,riβ=β₯wl^β²ββ₯1ββ£fl^β²ββ£βsign(wl^β²β)
In the binary case, DeepFool has the same form as Newton's method for solving the equation f(x)=0 (in its variant for more unknowns than equations). It can also be viewed as gradient descent with an automatically chosen step size.