TensorFlow implementation of the algorithm for generating universal adversarial perturbations based on the (p, q) - singular vectors (see https://arxiv.org/abs/1709.03582 for details).
For the installation do the following
git clone https://github.com/KhrulkovV/singular-fool
cd singular-fool
python setup.py install
An example using Keras for loading pretrained models is given here.
In general, given a DNN with e.g. the following architecture
x = tf.placeholder(tf.float32, (None, 28, 28, 1))
w = tf.Variable(np.random.rand(784, 128), dtype=tf.float32)
fc1 = tf.nn.relu(tf.matmul(tf.reshape(x, (-1, 784)), w))
...
it is possible to call
v = singular_fool.get_adversary(x, fc1, img_batch, sess)
where
img_batch
is a collection of images (e.g. in this case it might be a numpy tensor of size [32, 28, 28, 1]). A very basic example is given here.