Giter Site home page Giter Site logo

cleverhans-lab / cleverhans Goto Github PK

View Code? Open in Web Editor NEW
6.1K 189.0 1.4K 9.15 MB

An adversarial example library for constructing attacks, building defenses, and benchmarking both

License: MIT License

Python 33.09% Dockerfile 0.02% Shell 0.45% Makefile 0.03% HTML 21.52% Jupyter Notebook 44.89%
machine-learning security benchmarking

cleverhans's Introduction

CleverHans (latest release: v4.0.0)

cleverhans logo

This repository contains the source code for CleverHans, a Python library to benchmark machine learning systems' vulnerability to adversarial examples. You can learn more about such vulnerabilities on the accompanying blog.

The CleverHans library is under continual development, always welcoming contributions of the latest attacks and defenses. In particular, we always welcome help towards resolving the issues currently open.

Since v4.0.0, CleverHans supports 3 frameworks: JAX, PyTorch, and TF2. We are currently prioritizing implementing attacks in PyTorch, but we very much welcome contributions for all 3 frameworks. In versions v3.1.0 and prior, CleverHans supported TF1; the code for v3.1.0 can be found under cleverhans_v3.1.0/ or by checking out a prior Github release.

The library focuses on providing reference implementation of attacks against machine learning models to help with benchmarking models against adversarial examples.

The directory structure is as follows: cleverhans/ contain attack implementations, tutorials/ contain scripts demonstrating the features of CleverHans, and defenses/ contains defense implementations. Each framework has its own subdirectory within these folders, e.g. cleverhans/jax.

Setting up CleverHans

Dependencies

This library uses Jax, PyTorch or TensorFlow 2 to accelerate graph computations performed by many machine learning models. Therefore, installing one of these libraries is a pre-requisite.

Installation

Once dependencies have been taken care of, you can install CleverHans using pip or by cloning this Github repository.

pip installation

If you are installing CleverHans using pip, run the following command:

pip install cleverhans

This will install the last version uploaded to Pypi. If you'd instead like to install the bleeding edge version, use:

pip install git+https://github.com/cleverhans-lab/cleverhans.git#egg=cleverhans

Installation for development

If you want to make an editable installation of CleverHans so that you can develop the library and contribute changes back, first fork the repository on GitHub and then clone your fork into a directory of your choice:

git clone https://github.com/<your-org>/cleverhans

You can then install the local package in "editable" mode in order to add it to your PYTHONPATH:

cd cleverhans
pip install -e .

Currently supported setups

Although CleverHans is likely to work on many other machine configurations, we currently test it with Python 3.6, Jax 0.2, PyTorch 1.7, and Tensorflow 2.4 on Ubuntu 18.04 LTS (Bionic Beaver).

Getting support

If you have a request for support, please ask a question on StackOverflow rather than opening an issue in the GitHub tracker. The GitHub issue tracker should only be used to report bugs or make feature requests.

Contributing

Contributions are welcomed! To speed the code review process, we ask that:

Bug fixes can be initiated through Github pull requests.

Tutorials: tutorials directory

To help you get started with the functionalities provided by this library, the tutorials/ folder comes with the following tutorials:

NOTE: the tutorials are maintained carefully, in the sense that we use continuous integration to make sure they continue working. They are not considered part of the API and they can change at any time without warning. You should not write 3rd party code that imports the tutorials and expect that the interface will not break. Only the main library is subject to our six month interface deprecation warning rule.

NOTE: please start a thread on the discussion board before writing a new tutorial. Because each new tutorial involves a large amount of duplicated code relative to the existing tutorials, and because every line of code requires ongoing testing and maintenance indefinitely, we generally prefer not to add new tutorials. Each tutorial should showcase an extremely different way of using the library. Just calling a different attack, model, or dataset is not enough to justify maintaining a parallel tutorial.

Examples : examples directory

The examples/ folder contains additional scripts to showcase different uses of the CleverHans library or get you started competing in different adversarial example contests. We do not offer nearly as much ongoing maintenance or support for this directory as the rest of the library, and if code in here gets broken we may just delete it without warning.

Since we recently discontinued support for TF1, the examples/ folder is currently empty, but you are welcome to submit your uses via a pull request :)

Old examples for CleverHans v3.1.0 and prior can be found under cleverhans_v3.1.0/examples/.

Reporting benchmarks

When reporting benchmarks, please:

  • Use a versioned release of CleverHans. You can find a list of released versions here.
  • Either use the latest version, or, if comparing to an earlier publication, use the same version as the earlier publication.
  • Report which attack method was used.
  • Report any configuration variables used to determine the behavior of the attack.

For example, you might report "We benchmarked the robustness of our method to adversarial attack using v4.0.0 of CleverHans. On a test set modified by the FastGradientMethod with a max-norm eps of 0.3, we obtained a test set accuracy of 71.3%."

Citing this work

If you use CleverHans for academic research, you are highly encouraged (though not required) to cite the following paper:

@article{papernot2018cleverhans,
  title={Technical Report on the CleverHans v2.1.0 Adversarial Examples Library},
  author={Nicolas Papernot and Fartash Faghri and Nicholas Carlini and
  Ian Goodfellow and Reuben Feinman and Alexey Kurakin and Cihang Xie and
  Yash Sharma and Tom Brown and Aurko Roy and Alexander Matyasko and
  Vahid Behzadan and Karen Hambardzumyan and Zhishuai Zhang and
  Yi-Lin Juang and Zhi Li and Ryan Sheatsley and Abhibhav Garg and
  Jonathan Uesato and Willi Gierke and Yinpeng Dong and David Berthelot and
  Paul Hendricks and Jonas Rauber and Rujun Long},
  journal={arXiv preprint arXiv:1610.00768},
  year={2018}
}

About the name

The name CleverHans is a reference to a presentation by Bob Sturm titled “Clever Hans, Clever Algorithms: Are Your Machine Learnings Learning What You Think?" and the corresponding publication, "A Simple Method to Determine if a Music Information Retrieval System is a 'Horse'." Clever Hans was a horse that appeared to have learned to answer arithmetic questions, but had in fact only learned to read social cues that enabled him to give the correct answer. In controlled settings where he could not see people's faces or receive other feedback, he was unable to answer the same questions. The story of Clever Hans is a metaphor for machine learning systems that may achieve very high accuracy on a test set drawn from the same distribution as the training data, but that do not actually understand the underlying task and perform poorly on other inputs.

Authors

This library is collectively maintained by the CleverHans Lab at the University of Toronto. The current point of contact is Jonas Guan. It was previously maintained by Ian Goodfellow and Nicolas Papernot.

The following authors contributed 100 lines or more (ordered according to the GitHub contributors page):

  • Ian Goodfellow (Google Brain)
  • Nicolas Papernot (Google Brain)
  • Nicholas Carlini (Google Brain)
  • Fartash Faghri (University of Toronto)
  • Tzu-Wei Sung (National Taiwan University)
  • Alexey Kurakin (Google Brain)
  • Reuben Feinman (New York University)
  • Shiyu Duan (University of Florida)
  • Phani Krishna (Video Analytics Lab)
  • David Berthelot (Google Brain)
  • Tom Brown (Google Brain)
  • Cihang Xie (Johns Hopkins)
  • Yash Sharma (The Cooper Union)
  • Aashish Kumar (HARMAN X)
  • Aurko Roy (Google Brain)
  • Alexander Matyasko (Nanyang Technological University)
  • Anshuman Suri (University of Virginia)
  • Yen-Chen Lin (MIT)
  • Vahid Behzadan (Kansas State)
  • Jonathan Uesato (DeepMind)
  • Florian Tramèr (Stanford University)
  • Haojie Yuan (University of Science & Technology of China)
  • Zhishuai Zhang (Johns Hopkins)
  • Karen Hambardzumyan (YerevaNN)
  • Jianbo Chen (UC Berkeley)
  • Catherine Olsson (Google Brain)
  • Aidan Gomez (University of Oxford)
  • Zhi Li (University of Toronto)
  • Yi-Lin Juang (NTUEE)
  • Pratyush Sahay (formerly HARMAN X)
  • Abhibhav Garg (IIT Delhi)
  • Aditi Raghunathan (Stanford University)
  • Yang Song (Stanford University)
  • Riccardo Volpi (Italian Institute of Technology)
  • Angus Galloway (University of Guelph)
  • Yinpeng Dong (Tsinghua University)
  • Willi Gierke (Hasso Plattner Institute)
  • Bruno López
  • Jonas Rauber (IMPRS)
  • Paul Hendricks (NVIDIA)
  • Ryan Sheatsley (Pennsylvania State University)
  • Rujun Long (0101.AI)
  • Bogdan Kulynych (EPFL)
  • Erfan Noury (UMBC)
  • Robert Wagner (Case Western Reserve University)
  • Erh-Chung Chen (National Tsing Hua University)
  • Joel Frank (Ruhr-University Bochum)

Copyright

Copyright 2021 - Google Inc., OpenAI, Pennsylvania State University, University of Toronto.

cleverhans's People

Contributors

aam-at avatar aashish-kumar avatar alexeykurakin avatar alkaet avatar behzadanksu avatar carlini avatar catherio avatar cihangxie avatar david-berthelot avatar fartashf avatar feedforward avatar goodfeli avatar haojieyuan avatar iamgroot42 avatar iarunava avatar jianbo-lab avatar jonasguan avatar joool avatar lorenzhw avatar michaelshiyu avatar nottombrown avatar npapernot avatar rfeinman avatar royaurko avatar shreyashankar avatar steverab avatar tejuafonja avatar windqaq avatar yaq007 avatar ysharma1126 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cleverhans's Issues

image order

was i meant to need to set image order to 'th' in ~/.keras?

Standardize whitespace

vim is showing me red marks on indentations in test_mnist_accuracy.py. We should set up a standard way to configure our editors.

New release

We should do a new release with a major version increment because of #25 . Because the loss was used as part of the attacks, this bug made the attacks appear too weak.

TensorFlow issues weird error message

This seems harmless, but it is annoying. Not sure if we can fix it, since it may be a bug in TensorFlow itself.

At the end of the MNIST tutorial, I get this error message:
Exception AttributeError: AttributeError("'NoneType' object has no attribute 'raise_exception_on_not_ok_status'",) in <bound method Session.del of <tensorflow.python.client.session.Session object at 0x7fb09c05ad50>> ignored

TensorFlow MNIST accuracy test is failing

Completed model training.
Traceback (most recent call last):
File "test_mnist_accuracy.py", line 71, in
app.run()
File "/home/mahnerak/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "test_mnist_accuracy.py", line 67, in main
assert float(accuracy) >= 0.98, accuracy
AssertionError: 0.9639

JSMA tutorial crashes while trying to save

Traceback (most recent call last):
File "tutorials/mnist_tutorial_jsma.py", line 140, in
app.run()
File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 43, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "tutorials/mnist_tutorial_jsma.py", line 83, in main
saver.save(sess, save_path)
File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1329, in save
self.last_checkpoints, latest_filename)
File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 745, in update_checkpoint_state
text_format.MessageToString(ckpt))
File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/lib/io/file_io.py", line 351, in atomic_write_string_to_file
rename(temp_pathname, filename, overwrite=True)
File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/lib/io/file_io.py", line 333, in rename
compat.as_bytes(oldname), compat.as_bytes(newname), overwrite, status)
File "/opt/anaconda/4.2.0/lib/python3.5/contextlib.py", line 66, in exit
next(self.gen)
File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 469, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.PermissionDeniedError: /tmp/checkpoint.tmp87146825c2f043aa9c3fd9f92e3efa98

naive training seems slow

I'm getting 3.7 seconds per 100 batches.
In "Explaining and Harnessing", I think it took something like 4 seconds per full epoch, with older hardware.
Maybe the model in the tutorial is just a lot bigger.

FGSM loss computation

According to the paper Adversarial examples in the physical world, FGSM uses y_true, the true label, to generate the adversarial images, instead of model predictions. Besides, it does not really make sense to me to use y_pred and logits to compute the loss since y_pred = softmax(logits). Instead of

def fgsm(x, predictions, eps, clip_min=None, clip_max=None)

The second parameter should be

def fgsm(x, y_true, eps, clip_min=None, clip_max=None)

make a test preventing accuracy regressions

with current model, after 5 epochs of adversarial training, clean accuracy should definitely be .97 or better, adv accuracy should definitely be .79 or better. usually better than this but things aren't seeded so it fluctuates

MNIST tutorials not working with new Keras

Running mnist_tutorial_th.py gives:

Using gpu device 0: GeForce GTX TITAN X (CNMeM is disabled, cuDNN 5103)
Using Theano backend.
X_train shape: (60000, 1, 28, 28)
60000 train samples
10000 test samples
Loaded MNIST test data.
Traceback (most recent call last):
  File "/part/01/Tmp/lisa/os_v5/anaconda/lib/python2.7/site-packages/ipdb/__main__.py", line 164, in main
    pdb._runscript(mainpyfile)
  File "/Tmp/lisa/os_v5/anaconda/lib/python2.7/pdb.py", line 1233, in _runscript
    self.run(statement)
  File "/Tmp/lisa/os_v5/anaconda/lib/python2.7/bdb.py", line 400, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "tutorials/mnist_tutorial_th.py", line 1, in <module>
    from __future__ import absolute_import
  File "tutorials/mnist_tutorial_th.py", line 46, in main
    model = model_mnist()
  File "/u/jastrzes/deep_protein/notebooks/cleverhans/cleverhans/utils_mnist.py", line 66, in model_mnist
    model.add(Dense(nb_classes))
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/models.py", line 331, in add
    output_tensor = layer(self.outputs[0])
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/engine/topology.py", line 543, in __call__
    self.build(input_shapes[0])
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/layers/core.py", line 752, in build
    constraint=self.W_constraint)
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/engine/topology.py", line 415, in add_weight
    weight = initializer(shape, name=name)
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/initializations.py", line 60, in glorot_uniform
    return uniform(shape, s, name=name)
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/initializations.py", line 33, in uniform
    return K.random_uniform_variable(shape, -scale, scale, name=name)
  File "/u/jastrzes/.local/lib/python2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/backend/theano_backend.py", line 178, in random_uniform_variable
    return variable(np.random.uniform(low=low, high=high, size=shape),
  File "mtrand.pyx", line 1252, in mtrand.RandomState.uniform (numpy/random/mtrand/mtrand.c:13528)
OverflowError: Range exceeds valid bounds

This happens because default dim ordering in Keras is now "tf", which means that `Convolution2D in https://github.com/openai/cleverhans/blob/master/cleverhans/utils_mnist.py#L53 interprets "1" as the width of image

Saving fooling images

How can I save only the images generated from either FGSM or JSMA attacks?

It looks like the tensor of images returned out of batch_eval(sess, [x], [adv_x], [X_train], args=eval_params) only give the noise that will be added to the original images.

I'm training a detector, and this library looks much better than the way I was generating fooling images before. I just can't figure out how to get the actual perturbed images.

Thanks.

remove all flags from cleverhans module

Having flags (tf flags) is ok in the tutorials, but it would be easier to import functions from the cleverhans module if they didn't reuse flags directly but rather got these values as arguments (e.g., learning rate in model train)

ValueError

I run the test_mnist_accuracy.py, meet the following error:
Using TensorFlow backend.
X_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
/anaconda/lib/python2.7/site-packages/cleverhans-1.0.0-py2.7.egg/cleverhans/utils.py:143: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(64, (8, 8), padding="same", strides=(2, 2))
border_mode="same"
/anaconda/lib/python2.7/site-packages/cleverhans-1.0.0-py2.7.egg/cleverhans/utils.py:147: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(128, (6, 6), padding="valid", strides=(2, 2))
border_mode="valid"),
/anaconda/lib/python2.7/site-packages/cleverhans-1.0.0-py2.7.egg/cleverhans/utils.py:149: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(128, (5, 5), strides=(1, 1))
Convolution2D(nb_filters * 2, 5, 5, subsample=(1, 1)),
Defined TensorFlow model graph.
Epoch 0
Epoch took 8.60225486755 seconds
Epoch 1
Epoch took 8.84567499161 seconds
Completed model training.
Traceback (most recent call last):

File "", line 1, in
runfile('/Users/adhockuang/myworkspace/cleverhans-master/tests_tf/test_mnist_accuracy.py', wdir='/Users/adhockuang/myworkspace/cleverhans-master/tests_tf')

File "/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

File "/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)

File "/Users/adhockuang/myworkspace/cleverhans-master/tests_tf/test_mnist_accuracy.py", line 84, in
app.run()

File "/anaconda/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))

File "/Users/adhockuang/myworkspace/cleverhans-master/tests_tf/test_mnist_accuracy.py", line 76, in main
args=eval_params)

File "/anaconda/lib/python2.7/site-packages/cleverhans-1.0.0-py2.7.egg/cleverhans/utils_tf.py", line 206, in model_eval
keras.backend.learning_phase(): 0})

ValueError: operands could not be broadcast together with shapes (128,) (80,) (128,)

make the saliency maps more general

right now the map definitions are biased towards image data (because of row x col). We should clean up the code to define them for any input vector. We can do that once the tutorial is fully merged (branch saliency is closed)

theano tutorial is broken

python tutorials/mnist_tutorial_th.py Using TensorFlow backend. I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally X_train shape: (60000, 1, 28, 28) 60000 train samples 10000 test samples Loaded MNIST test data. Traceback (most recent call last): File "tutorials/mnist_tutorial_th.py", line 98, in <module> main() File "tutorials/mnist_tutorial_th.py", line 48, in main predictions = model(x) File "/home/ian/.local/lib/python3.5/site-packages/keras/engine/topology.py", line 574, in __call__ outputs = to_list(self.call(x, mask)) File "/home/ian/.local/lib/python3.5/site-packages/keras/models.py", line 381, in call return self.model.call(x, mask) File "/home/ian/.local/lib/python3.5/site-packages/keras/engine/topology.py", line 2240, in call output_tensors, output_masks, output_shapes = self.run_internal_graph(inputs, masks) File "/home/ian/.local/lib/python3.5/site-packages/keras/engine/topology.py", line 2383, in run_internal_graph computed_mask)) File "/home/ian/.local/lib/python3.5/site-packages/keras/layers/core.py", line 90, in call x = K.in_train_phase(K.dropout(x, self.p, noise_shape), x) File "/home/ian/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 2051, in dropout return tf.nn.dropout(x * 1., retain_prob, noise_shape, seed=seed) File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/ops/nn_ops.py", line 1743, in dropout x = ops.convert_to_tensor(x, name="x") File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 165, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 441, in make_tensor_proto tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values]) File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 441, in <listcomp> tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values]) File "/home/ian/.local/lib/python3.5/site-packages/tensorflow/python/util/compat.py", line 65, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got Elemwise{mul,no_inplace}.0

Occasional `KeyError` with JSMA depending on input

I was using the JSMA attack (with the increase=False option) on "tutorial" MNIST classifier from the TensorFlow website. However, it occasionally dies when trying to remove a key that does not exist:

Current iteration: 5 - Current Prediction: 1
Current iteration: 10 - Current Prediction: 1
Current iteration: 15 - Current Prediction: 1
Current iteration: 20 - Current Prediction: 1
Current iteration: 25 - Current Prediction: 3
Traceback (most recent call last):
  File "mnist_test_updated.py", line 245, in <module>
    max_distortion/100, False, 0, 1)
  File "/net/af11/apn4za/AdversarialMachineLearning/fjsma/cleverhans/cleverhans/attacks_tf.py", line 246, in jsma_tf
    grads_target, grads_others, search_domain, increase)
  File "/net/af11/apn4za/AdversarialMachineLearning/fjsma/cleverhans/cleverhans/attacks_tf.py", line 124, in saliency_map
    search_domain.remove(p1)
KeyError: 0

Link to offending lines.

This occurs when there are no pixels that satisfy the saliency map condition of alpha < 0 and beta > 0 (using the terms from Papernot, et al), so then "best" is 0. However, for MNIST, the 0 pixel is rarely set, so it is not in the search_domain set and the removal fails.

I did a temporary fix on my side by using discard instead of remove, which fails silently. The downside of this is that the saliency map will continue to delete the 0, 0 pixels until the max_iters value is exceeded in the main jsma_tf loop; this wastes resources, but is a simple fix.

JSMA API suggestion

IMHO, there might be a couple of improvements over the JSMA API.

  1. increase and theta are duplicates.
    increase=True <-> theta=+x
    increase=False <-> theta=-x
  2. jacobian_graph is like a loose ends to me.
    I think the gradients should be calculated internally in the JSMA function, it is, at least to me, counter-intuitive to called some random function before calling the jsma.

wrong order in tf_model_loss

In utils_tf.py, line 26 and 29, it should be categorical_crossentropy(model, y) instead of categorical_crossentropy(y, model). This won't affect training in a noticeable way for mnist but will make the training fail to work when I tried a deeper model on cifar-10.

Tutorials not working with new keras 2.0

I get this when I run the unmodified version of the tutorial on CPU, with the latest keras.
The error does not show up with keras 1.2

(tensorflow) rva5120@cse-p336mcro05:~/tensorflow/cleverhans/tutorials$ python mnist_tutorial_tf.py
Using TensorFlow backend.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
X_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
/home/grads/rva5120/tensorflow/cleverhans/cleverhans/utils.py:143: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (8, 8), padding="same", strides=(2, 2))`
  border_mode="same"
/home/grads/rva5120/tensorflow/cleverhans/cleverhans/utils.py:147: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (6, 6), padding="valid", strides=(2, 2))`
  border_mode="valid"),
/home/grads/rva5120/tensorflow/cleverhans/cleverhans/utils.py:149: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (5, 5), strides=(1, 1))`
  Convolution2D(nb_filters * 2, 5, 5, subsample=(1, 1)),
Defined TensorFlow model graph.
Epoch 0
	Epoch took 52.5618000031 seconds
Traceback (most recent call last):
  File "mnist_tutorial_tf.py", line 122, in <module>
    app.run()
  File "/home/grads/rva5120/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "mnist_tutorial_tf.py", line 81, in main
    evaluate=evaluate, args=train_params)
  File "/home/grads/rva5120/tensorflow/cleverhans/cleverhans/utils_tf.py", line 142, in model_train
    evaluate()
  File "mnist_tutorial_tf.py", line 70, in evaluate
    args=eval_params)
  File "/home/grads/rva5120/tensorflow/cleverhans/cleverhans/utils_tf.py", line 206, in model_eval
    keras.backend.learning_phase(): 0})
ValueError: operands could not be broadcast together with shapes (128,) (16,) (128,) 

Fool model toward specified target class using FSGM

Hello @goodfeli and @npapernot ,

In my understanding, these two lines get the result of what trained model is gonna classify the clean example.

Then by adding this gradient to the image, the trained model will tend to not classify it as the same label as before.

However, I'm wondering how can I use FSGM to fool model so that it will classify all examples to a specified label, e.g., 0.

theano tutorial is incredible slow

ian@11:~/cleverhans/tutorials$ KERAS_BACKEND="theano" python mnist_tutorial_th.py 
Using Theano backend.
INFO: '~/.keras/keras.json' sets 'image_dim_ordering' to 'tf', temporarily setting to 'th'
X_train shape: (60000, 1, 28, 28)
60000 train samples
10000 test samples
Loaded MNIST test data.
Defined Theano model graph.
Starting model training using Theano.
Defined optimizer.
Epoch 0
    Epoch took 338.5225307941437 seconds

Make tests automated

For now, I guess we have to run each of them manually? We should either copy the docker setup from OpenAI Gym or the nose setup from Pylearn2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.