Showing preview only (9,889K chars total). Download the full file or copy to clipboard to get everything.
Repository: cleverhans-lab/cleverhans
Branch: master
Commit: 574efc1d2f5c
Files: 494
Total size: 9.3 MB
Directory structure:
gitextract_jw024m5z/
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ └── feature_request.md
│ ├── cml_gpu_test.yaml
│ └── workflows/
│ ├── style_type_check.yml
│ ├── tests-pytorch.yml
│ ├── tutorials-jax.yml
│ ├── tutorials-pytorch.yml
│ └── tutorials-tf2.yml
├── .gitignore
├── .pre-commit-config.yaml
├── .pylintrc
├── .setup_vm_and_run_tests.sh
├── CODE_OF_CONDUCT.rst
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── README.md
├── assets/
│ └── logo.psd
├── cleverhans/
│ ├── __init__.py
│ ├── devtools/
│ │ ├── LICENSE.txt
│ │ ├── __init__.py
│ │ ├── autopep8_all.py
│ │ ├── checks.py
│ │ ├── list_files.py
│ │ ├── mocks.py
│ │ ├── tests/
│ │ │ ├── __init__.py
│ │ │ └── test_format.py
│ │ └── version.py
│ ├── experimental/
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── certification/
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── certify.py
│ │ ├── dual_formulation.py
│ │ ├── nn.py
│ │ ├── optimization.py
│ │ ├── tests/
│ │ │ ├── dual_formulation_test.py
│ │ │ ├── nn_test.py
│ │ │ ├── optimization_test.py
│ │ │ └── utils_test.py
│ │ └── utils.py
│ ├── generic/
│ │ ├── README.md
│ │ └── __init__.py
│ ├── jax/
│ │ ├── __init__.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── fast_gradient_method.py
│ │ │ └── projected_gradient_descent.py
│ │ └── utils.py
│ ├── plot/
│ │ ├── __init__.py
│ │ ├── image.py
│ │ ├── pyplot_defaults.py
│ │ ├── pyplot_image.py
│ │ ├── save_pdf.py
│ │ └── success_fail.py
│ ├── tf2/
│ │ ├── __init__.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── basic_iterative_method.py
│ │ │ ├── carlini_wagner_l2.py
│ │ │ ├── fast_gradient_method.py
│ │ │ ├── madry_et_al.py
│ │ │ ├── momentum_iterative_method.py
│ │ │ ├── projected_gradient_descent.py
│ │ │ └── spsa.py
│ │ └── utils.py
│ ├── torch/
│ │ ├── __init__.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── carlini_wagner_l2.py
│ │ │ ├── fast_gradient_method.py
│ │ │ ├── hop_skip_jump_attack.py
│ │ │ ├── noise.py
│ │ │ ├── projected_gradient_descent.py
│ │ │ ├── semantic.py
│ │ │ ├── sparse_l1_descent.py
│ │ │ └── spsa.py
│ │ ├── tests/
│ │ │ ├── __init__.py
│ │ │ ├── test_attacks.py
│ │ │ └── test_utils.py
│ │ └── utils.py
│ └── utils.py
├── cleverhans_v3.1.0/
│ ├── CODE_OF_CONDUCT.rst
│ ├── CONTRIBUTING.md
│ ├── Dockerfile
│ ├── LICENSE
│ ├── README.md
│ ├── assets/
│ │ └── logo.psd
│ ├── cleverhans/
│ │ ├── __init__.py
│ │ ├── attack_bundling.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── attack.py
│ │ │ ├── basic_iterative_method.py
│ │ │ ├── carlini_wagner_l2.py
│ │ │ ├── deep_fool.py
│ │ │ ├── elastic_net_method.py
│ │ │ ├── fast_feature_adversaries.py
│ │ │ ├── fast_gradient_method.py
│ │ │ ├── hop_skip_jump_attack.py
│ │ │ ├── lbfgs.py
│ │ │ ├── madry_et_al.py
│ │ │ ├── max_confidence.py
│ │ │ ├── momentum_iterative_method.py
│ │ │ ├── noise.py
│ │ │ ├── projected_gradient_descent.py
│ │ │ ├── saliency_map_method.py
│ │ │ ├── semantic.py
│ │ │ ├── sparse_l1_descent.py
│ │ │ ├── spatial_transformation_method.py
│ │ │ ├── spsa.py
│ │ │ └── virtual_adversarial_method.py
│ │ ├── attacks_tf.py
│ │ ├── attacks_tfe.py
│ │ ├── augmentation.py
│ │ ├── canary.py
│ │ ├── compat.py
│ │ ├── confidence_report.py
│ │ ├── dataset.py
│ │ ├── devtools/
│ │ │ ├── LICENSE.txt
│ │ │ ├── __init__.py
│ │ │ ├── autopep8_all.py
│ │ │ ├── checks.py
│ │ │ ├── list_files.py
│ │ │ ├── mocks.py
│ │ │ ├── tests/
│ │ │ │ ├── __init__.py
│ │ │ │ └── test_format.py
│ │ │ └── version.py
│ │ ├── evaluation.py
│ │ ├── experimental/
│ │ │ ├── README.md
│ │ │ ├── __init__.py
│ │ │ └── certification/
│ │ │ ├── README.md
│ │ │ ├── __init__.py
│ │ │ ├── certify.py
│ │ │ ├── dual_formulation.py
│ │ │ ├── nn.py
│ │ │ ├── optimization.py
│ │ │ ├── tests/
│ │ │ │ ├── dual_formulation_test.py
│ │ │ │ ├── nn_test.py
│ │ │ │ ├── optimization_test.py
│ │ │ │ └── utils_test.py
│ │ │ └── utils.py
│ │ ├── initializers.py
│ │ ├── loss.py
│ │ ├── model.py
│ │ ├── model_zoo/
│ │ │ ├── __init__.py
│ │ │ ├── all_convolutional.py
│ │ │ ├── basic_cnn.py
│ │ │ ├── deep_k_nearest_neighbors/
│ │ │ │ ├── README.md
│ │ │ │ ├── __init__.py
│ │ │ │ └── dknn.py
│ │ │ ├── madry_lab_challenges/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── cifar10_model.py
│ │ │ │ └── make_cifar10_joblib.py
│ │ │ └── soft_nearest_neighbor_loss/
│ │ │ ├── SNNL_regularized_model.py
│ │ │ ├── SNNL_regularized_train.py
│ │ │ └── __init__.py
│ │ ├── picklable_model.py
│ │ ├── plot/
│ │ │ ├── __init__.py
│ │ │ ├── image.py
│ │ │ ├── pyplot_defaults.py
│ │ │ ├── pyplot_image.py
│ │ │ ├── save_pdf.py
│ │ │ └── success_fail.py
│ │ ├── serial.py
│ │ ├── train.py
│ │ ├── utils.py
│ │ ├── utils_keras.py
│ │ ├── utils_mnist.py
│ │ ├── utils_pytorch.py
│ │ ├── utils_tf.py
│ │ └── utils_tfe.py
│ ├── cleverhans_tutorials/
│ │ ├── __init__.py
│ │ ├── cifar10_tutorial_tf.py
│ │ ├── evaluate_pickled_model.py
│ │ ├── mnist_blackbox.py
│ │ ├── mnist_tutorial_cw.py
│ │ ├── mnist_tutorial_jsma.py
│ │ ├── mnist_tutorial_keras.py
│ │ ├── mnist_tutorial_keras_tf.py
│ │ ├── mnist_tutorial_picklable.py
│ │ ├── mnist_tutorial_pytorch.py
│ │ ├── mnist_tutorial_tf.py
│ │ ├── mnist_tutorial_tfe.py
│ │ ├── tutorial_models.py
│ │ └── tutorial_models_tfe.py
│ ├── docs/
│ │ ├── .nojekyll
│ │ ├── README.html
│ │ ├── _modules/
│ │ │ ├── abc.html
│ │ │ ├── cleverhans/
│ │ │ │ ├── attacks/
│ │ │ │ │ ├── attack.html
│ │ │ │ │ ├── basic_iterative_method.html
│ │ │ │ │ ├── carlini_wagner_l2.html
│ │ │ │ │ ├── deep_fool.html
│ │ │ │ │ ├── elastic_net_method.html
│ │ │ │ │ ├── fast_feature_adversaries.html
│ │ │ │ │ ├── fast_gradient_method.html
│ │ │ │ │ ├── hop_skip_jump_attack.html
│ │ │ │ │ ├── lbfgs.html
│ │ │ │ │ ├── madry_et_al.html
│ │ │ │ │ ├── max_confidence.html
│ │ │ │ │ ├── momentum_iterative_method.html
│ │ │ │ │ ├── noise.html
│ │ │ │ │ ├── projected_gradient_descent.html
│ │ │ │ │ ├── saliency_map_method.html
│ │ │ │ │ ├── semantic.html
│ │ │ │ │ ├── sparse_l1_descent.html
│ │ │ │ │ ├── spatial_transformation_method.html
│ │ │ │ │ ├── spsa.html
│ │ │ │ │ └── virtual_adversarial_method.html
│ │ │ │ ├── compat.html
│ │ │ │ ├── model.html
│ │ │ │ └── utils_tf.html
│ │ │ └── index.html
│ │ ├── _sources/
│ │ │ ├── README.md.txt
│ │ │ ├── index.md.txt
│ │ │ └── source/
│ │ │ ├── attacks.md.txt
│ │ │ ├── devtools.md.txt
│ │ │ ├── future.md.txt
│ │ │ └── model.md.txt
│ │ ├── _static/
│ │ │ ├── alabaster.css
│ │ │ ├── basic.css
│ │ │ ├── custom.css
│ │ │ ├── doctools.js
│ │ │ ├── documentation_options.js
│ │ │ ├── jquery-3.5.1.js
│ │ │ ├── jquery.js
│ │ │ ├── language_data.js
│ │ │ ├── pygments.css
│ │ │ ├── searchtools.js
│ │ │ ├── underscore-1.3.1.js
│ │ │ └── underscore.js
│ │ ├── genindex.html
│ │ ├── index.html
│ │ ├── objects.inv
│ │ ├── py-modindex.html
│ │ ├── search.html
│ │ ├── searchindex.js
│ │ └── source/
│ │ ├── attacks.html
│ │ ├── devtools.html
│ │ ├── future.html
│ │ └── model.html
│ ├── docsource/
│ │ ├── Makefile
│ │ ├── README.md
│ │ ├── _templates/
│ │ │ └── layout.html
│ │ ├── conf.py
│ │ ├── docs_requirements.txt
│ │ ├── index.md
│ │ └── source/
│ │ ├── attacks.md
│ │ ├── devtools.md
│ │ ├── future.md
│ │ └── model.md
│ ├── examples/
│ │ ├── README.md
│ │ ├── RL-attack/
│ │ │ ├── README.md
│ │ │ ├── enjoy-adv.py
│ │ │ ├── model.py
│ │ │ └── train.py
│ │ ├── adversarial_asr/
│ │ │ ├── LibriSpeech/
│ │ │ │ └── LICENSE.TXT
│ │ │ ├── README.md
│ │ │ ├── generate_imperceptible_adv.py
│ │ │ ├── generate_masking_threshold.py
│ │ │ ├── generate_robust_adv.py
│ │ │ ├── model/
│ │ │ │ ├── checkpoint
│ │ │ │ ├── ckpt-00908156.index
│ │ │ │ ├── ckpt-00908156.meta
│ │ │ │ └── events.out.tfevents.1543301105.e33cfcb49883
│ │ │ ├── read_data.txt
│ │ │ ├── room_simulator.py
│ │ │ ├── test_imperceptible_adv.py
│ │ │ ├── test_robust_adv.py
│ │ │ ├── tool.py
│ │ │ └── util/
│ │ │ ├── convert_name_format.sh
│ │ │ └── read_data_full.txt
│ │ ├── adversarial_patch/
│ │ │ ├── AdversarialPatch.ipynb
│ │ │ └── README.md
│ │ ├── facenet_adversarial_faces/
│ │ │ ├── README.md
│ │ │ ├── facenet_fgsm.py
│ │ │ └── set_loader.py
│ │ ├── imagenet_featadvs/
│ │ │ └── model.py
│ │ ├── madry_lab_challenges/
│ │ │ ├── LICENSE
│ │ │ ├── README
│ │ │ ├── cifar10/
│ │ │ │ └── attack_model.py
│ │ │ └── mnist/
│ │ │ ├── attack_model.py
│ │ │ └── madry_mnist_model.py
│ │ ├── multigpu_advtrain/
│ │ │ ├── README.md
│ │ │ ├── attacks_multigpu.py
│ │ │ ├── evaluator.py
│ │ │ ├── make_model.py
│ │ │ ├── model.py
│ │ │ ├── resnet_tf.py
│ │ │ ├── run_multigpu.py
│ │ │ ├── runner.py
│ │ │ ├── test_attack_multigpu.py
│ │ │ ├── test_run_multigpu.py
│ │ │ ├── test_runner.py
│ │ │ ├── trainer.py
│ │ │ ├── utils.py
│ │ │ ├── utils_cifar.py
│ │ │ └── utils_svhn.py
│ │ ├── nips17_adversarial_competition/
│ │ │ ├── .gitignore
│ │ │ ├── README.md
│ │ │ ├── dataset/
│ │ │ │ ├── README.md
│ │ │ │ ├── dev_dataset.csv
│ │ │ │ ├── download_images.py
│ │ │ │ └── final_dataset.csv
│ │ │ ├── dev_toolkit/
│ │ │ │ ├── .gitignore
│ │ │ │ ├── README.md
│ │ │ │ ├── download_data.sh
│ │ │ │ ├── run_attacks_and_defenses.py
│ │ │ │ ├── run_attacks_and_defenses.sh
│ │ │ │ ├── sample_attacks/
│ │ │ │ │ ├── download_checkpoints.sh
│ │ │ │ │ ├── fgsm/
│ │ │ │ │ │ ├── attack_fgsm.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_attack.sh
│ │ │ │ │ ├── noop/
│ │ │ │ │ │ ├── attack_noop.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_attack.sh
│ │ │ │ │ └── random_noise/
│ │ │ │ │ ├── attack_random_noise.py
│ │ │ │ │ ├── metadata.json
│ │ │ │ │ └── run_attack.sh
│ │ │ │ ├── sample_defenses/
│ │ │ │ │ ├── adv_inception_v3/
│ │ │ │ │ │ ├── defense.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_defense.sh
│ │ │ │ │ ├── base_inception_model/
│ │ │ │ │ │ ├── defense.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_defense.sh
│ │ │ │ │ ├── download_checkpoints.sh
│ │ │ │ │ └── ens_adv_inception_resnet_v2/
│ │ │ │ │ ├── defense.py
│ │ │ │ │ ├── inception_resnet_v2.py
│ │ │ │ │ ├── metadata.json
│ │ │ │ │ └── run_defense.sh
│ │ │ │ ├── sample_targeted_attacks/
│ │ │ │ │ ├── download_checkpoints.sh
│ │ │ │ │ ├── iter_target_class/
│ │ │ │ │ │ ├── attack_iter_target_class.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_attack.sh
│ │ │ │ │ └── step_target_class/
│ │ │ │ │ ├── attack_step_target_class.py
│ │ │ │ │ ├── metadata.json
│ │ │ │ │ └── run_attack.sh
│ │ │ │ └── validation_tool/
│ │ │ │ ├── README.md
│ │ │ │ ├── submission_validator_lib.py
│ │ │ │ └── validate_submission.py
│ │ │ └── eval_infra/
│ │ │ ├── README.md
│ │ │ ├── code/
│ │ │ │ ├── eval_lib/
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── classification_results.py
│ │ │ │ │ ├── cloud_client.py
│ │ │ │ │ ├── dataset_helper.py
│ │ │ │ │ ├── image_batches.py
│ │ │ │ │ ├── submissions.py
│ │ │ │ │ ├── tests/
│ │ │ │ │ │ ├── __init__.py
│ │ │ │ │ │ ├── classification_results_test.py
│ │ │ │ │ │ ├── fake_cloud_client.py
│ │ │ │ │ │ ├── fake_cloud_client_test.py
│ │ │ │ │ │ ├── image_batches_test.py
│ │ │ │ │ │ ├── submissions_test.py
│ │ │ │ │ │ └── work_data_test.py
│ │ │ │ │ └── work_data.py
│ │ │ │ ├── master.py
│ │ │ │ ├── run_worker_locally.sh
│ │ │ │ ├── start_worker_in_tmux.sh
│ │ │ │ └── worker.py
│ │ │ ├── run_master.sh
│ │ │ ├── scripts/
│ │ │ │ ├── config.sh
│ │ │ │ ├── copy_baselines.sh
│ │ │ │ ├── copy_dataset_to_vm.sh
│ │ │ │ ├── copy_eval_infra_to_vm.sh
│ │ │ │ ├── create_workers.sh
│ │ │ │ ├── prepare_virtualenv.sh
│ │ │ │ ├── scp_cloud_vm.sh
│ │ │ │ └── start_workers.sh
│ │ │ └── validation_tool/
│ │ │ ├── validate_and_copy_submissions.py
│ │ │ └── validate_submission_lib.py
│ │ ├── robust_vision_benchmark/
│ │ │ ├── README.md
│ │ │ └── cleverhans_attack_example/
│ │ │ ├── Dockerfile
│ │ │ ├── main.py
│ │ │ ├── requirements.txt
│ │ │ └── utils.py
│ │ └── test_imagenet_attacks.py
│ ├── scripts/
│ │ ├── compute_accuracy.py
│ │ ├── make_confidence_report.py
│ │ ├── make_confidence_report_bundle_examples.py
│ │ ├── make_confidence_report_bundled.py
│ │ ├── make_confidence_report_spsa.py
│ │ ├── plot_success_fail_curve.py
│ │ ├── print_report.py
│ │ └── show_images.py
│ ├── setup.py
│ └── tests_tf/
│ ├── test_attack_bundling.py
│ ├── test_attacks.py
│ ├── test_attacks_tf.py
│ ├── test_confidence_report.py
│ ├── test_dataset.py
│ ├── test_defenses.py
│ ├── test_evaluation.py
│ ├── test_mnist_blackbox.py
│ ├── test_mnist_tutorial_cw.py
│ ├── test_mnist_tutorial_jsma.py
│ ├── test_mnist_tutorial_keras.py
│ ├── test_mnist_tutorial_keras_tf.py
│ ├── test_mnist_tutorial_tf.py
│ ├── test_model.py
│ ├── test_picklable_model.py
│ ├── test_projected_gradient_descent.py
│ ├── test_serial.py
│ ├── test_utils.py
│ ├── test_utils_keras.py
│ └── test_utils_tf.py
├── defenses/
│ ├── README.md
│ ├── generic/
│ │ ├── README.md
│ │ └── __init__.py
│ ├── jax/
│ │ └── README.md
│ ├── tf2/
│ │ └── README.md
│ └── torch/
│ ├── README.md
│ └── audio/
│ └── input_tranformation/
│ └── resampling.py
├── docs/
│ ├── .nojekyll
│ ├── README.html
│ ├── _modules/
│ │ ├── abc.html
│ │ ├── cleverhans/
│ │ │ ├── attacks/
│ │ │ │ ├── attack.html
│ │ │ │ ├── basic_iterative_method.html
│ │ │ │ ├── carlini_wagner_l2.html
│ │ │ │ ├── deep_fool.html
│ │ │ │ ├── elastic_net_method.html
│ │ │ │ ├── fast_feature_adversaries.html
│ │ │ │ ├── fast_gradient_method.html
│ │ │ │ ├── hop_skip_jump_attack.html
│ │ │ │ ├── lbfgs.html
│ │ │ │ ├── madry_et_al.html
│ │ │ │ ├── max_confidence.html
│ │ │ │ ├── momentum_iterative_method.html
│ │ │ │ ├── noise.html
│ │ │ │ ├── projected_gradient_descent.html
│ │ │ │ ├── saliency_map_method.html
│ │ │ │ ├── semantic.html
│ │ │ │ ├── sparse_l1_descent.html
│ │ │ │ ├── spatial_transformation_method.html
│ │ │ │ ├── spsa.html
│ │ │ │ └── virtual_adversarial_method.html
│ │ │ ├── compat.html
│ │ │ ├── model.html
│ │ │ └── utils_tf.html
│ │ └── index.html
│ ├── _sources/
│ │ ├── README.md.txt
│ │ ├── index.md.txt
│ │ └── source/
│ │ ├── attacks.md.txt
│ │ ├── devtools.md.txt
│ │ ├── future.md.txt
│ │ └── model.md.txt
│ ├── _static/
│ │ ├── alabaster.css
│ │ ├── basic.css
│ │ ├── custom.css
│ │ ├── doctools.js
│ │ ├── documentation_options.js
│ │ ├── jquery-3.5.1.js
│ │ ├── jquery.js
│ │ ├── language_data.js
│ │ ├── pygments.css
│ │ ├── searchtools.js
│ │ ├── underscore-1.3.1.js
│ │ └── underscore.js
│ ├── genindex.html
│ ├── index.html
│ ├── objects.inv
│ ├── py-modindex.html
│ ├── search.html
│ ├── searchindex.js
│ └── source/
│ ├── attacks.html
│ ├── devtools.html
│ ├── future.html
│ └── model.html
├── docsource/
│ ├── Makefile
│ ├── README.md
│ ├── _templates/
│ │ └── layout.html
│ ├── conf.py
│ ├── docs_requirements.txt
│ ├── index.md
│ └── source/
│ ├── attacks.md
│ ├── devtools.md
│ ├── future.md
│ └── model.md
├── examples/
│ └── README.md
├── requirements/
│ ├── requirements-dev.txt
│ ├── requirements-gpu.txt
│ ├── requirements-jax.txt
│ ├── requirements-pytorch.txt
│ ├── requirements-tf2.txt
│ └── requirements.txt
├── setup.py
└── tutorials/
├── README.md
├── generic/
│ ├── README.md
│ └── __init__.py
├── jax/
│ ├── __init__.py
│ ├── datasets.py
│ └── mnist_tutorial.py
├── tf2/
│ ├── __init__.py
│ ├── cifar10_tutorial.py
│ └── mnist_tutorial.py
└── torch/
├── __init__.py
├── cifar10_tutorial.py
├── datasets.py
└── mnist_tutorial.py
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: Bug report
about: Report a bug in the CleverHans library
---
***The issue tracker should only be used to report bugs or feature requests. If you are looking for support from other library users, please ask a question on [StackOverflow](https://stackoverflow.com/questions/tagged/cleverhans).***
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**System configuration**
- OS
- Python version
- TensorFlow version
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: Feature request
about: Suggest an idea for the CleverHans library
---
***The issue tracker should only be used to report bugs or feature requests. If you are looking for support from other library users, please ask a question on [StackOverflow](https://stackoverflow.com/questions/tagged/cleverhans).***
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
================================================
FILE: .github/cml_gpu_test.yaml
================================================
name: CML Single GPU Test
on: [push]
jobs:
run:
runs-on: [self-hosted,cml,gpu]
steps:
- uses: actions/checkout@v2
- name: cml_run
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
nvidia-smi
python -m pip install --upgrade pip
pip install -e "."
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-pytorch.txt
pip install -r requirements/requirements-jax.txt
pip install -r requirements/requirements-tf2.txt
pip install -r requirements/requirements-dev.txt
pip install -r requirements/requirements-gpu.txt
find tutorials/future/jax/ -name '*.py' | while read f
do
python $f
if [ $? -ne 0 ]
then
exit 1
fi
done
find tutorials/future/torch/ -name '*.py' | while read f
do
python $f
if [ $? -ne 0 ]
then
exit 1
fi
done
find tutorials/future/tf2/ -name '*.py' | while read f
do
python $f
if [ $? -ne 0 ]
then
exit 1
fi
done
================================================
FILE: .github/workflows/style_type_check.yml
================================================
name: Style and type checks
on:
push:
paths:
- 'cleverhans/**/*'
- 'tutorials/**/*'
pull_request:
paths:
- 'cleverhans/**/*'
- 'tutorials/**/*'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e "."
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-pytorch.txt
pip install -r requirements/requirements-tf2.txt
pip install -r requirements/requirements-jax.txt
pip install -r requirements/requirements-dev.txt
- name: Code reformat check
run: |
black --check cleverhans/
black --check tutorials/
# - name: flake8 linting check
# run: |
# flake8 cleverhans/
# flake8 tutorials/
# - name: Type check
# run: |
# mypy cleverhans/future/
================================================
FILE: .github/workflows/tests-pytorch.yml
================================================
name: PyTorch Tests
on:
push:
paths:
- 'cleverhans/torch/**/*'
pull_request:
paths:
- 'cleverhans/torch/**/*'
jobs:
run:
runs-on: [self-hosted,cml,gpu]
steps:
- uses: actions/checkout@v2
- name: cml_run
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install -e "."
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-pytorch.txt
pip install -r requirements/requirements-dev.txt
pip install -r requirements/requirements-gpu.txt
pytest cleverhans/torch/tests
================================================
FILE: .github/workflows/tutorials-jax.yml
================================================
name: JAX Tutorials
on:
push:
paths:
- 'cleverhans/jax/**/*'
- 'tutorials/jax/**/*'
pull_request:
paths:
- 'cleverhans/jax/**/*'
- 'tutorials/jax/**/*'
jobs:
run:
runs-on: [self-hosted,cml,gpu]
steps:
- uses: actions/checkout@v2
- name: cml_run
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install -e "."
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-jax.txt
pip install -r requirements/requirements-dev.txt
pip install -r requirements/requirements-gpu.txt
find tutorials/jax/ -name '*.py' | while read f
do
python $f
if [ $? -ne 0 ]
then
exit 1
fi
done
================================================
FILE: .github/workflows/tutorials-pytorch.yml
================================================
name: PyTorch Tutorials
on:
push:
paths:
- 'cleverhans/torch/**/*'
- 'tutorials/torch/**/*'
pull_request:
paths:
- 'cleverhans/torch/**/*'
- 'tutorials/torch/**/*'
jobs:
run:
runs-on: [self-hosted,cml,gpu]
steps:
- uses: actions/checkout@v2
- name: cml_run
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install -e "."
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-pytorch.txt
pip install -r requirements/requirements-dev.txt
pip install -r requirements/requirements-gpu.txt
find tutorials/torch/ -name '*.py' | while read f
do
python $f
if [ $? -ne 0 ]
then
exit 1
fi
done
================================================
FILE: .github/workflows/tutorials-tf2.yml
================================================
name: TensorFlow 2 Tutorials
on:
push:
paths:
- 'cleverhans/tf2/**/*'
- 'tutorials/tf2/**/*'
pull_request:
paths:
- 'cleverhans/tf2/**/*'
- 'tutorials/tf2/**/*'
jobs:
run:
runs-on: [self-hosted,cml,gpu]
steps:
- uses: actions/checkout@v2
- name: cml_run
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install -e "."
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-tf2.txt
pip install -r requirements/requirements-dev.txt
pip install -r requirements/requirements-gpu.txt
find tutorials/tf2/ -name '*.py' | while read f
do
python $f
if [ $? -ne 0 ]
then
exit 1
fi
done
================================================
FILE: .gitignore
================================================
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docsource/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# PyCharm related
.idea/
# Mac related
.DS_Store
================================================
FILE: .pre-commit-config.yaml
================================================
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
================================================
FILE: .pylintrc
================================================
# Config file for pylint for CleverHans
# Used by cleverhans.devtools
[FORMAT]
# TensorFlow 2 space style
indent-string=' '
max-line-length=120
# pylint should print out the file path, line number, and ID code for the
# messages it prints. This is partly so we can turn off the ID codes that
# we do not actually want to enforce.
msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'
# ID codes to disable
# E1130: has a bug.
# The type of the output of softmax_cross_entropy_with_logits is weird
# and pylint does not realize it is safe to negate it.
# C0103: Complains about the variable name 'x'
# W0613: Unused argument
# This one is disabled because pylint does not implement it well.
# In many cases we use all arguments via `locals()` and pylint does not
# detect them as used.
# E1101: pylint seems to have a bug. Says numpy.random has no member RandomState
# R0913: Too many arguments
# R0914: Too many local variables
# W0223: doesn't allow subclass of an abstract base class to still be abstract
# E0203: pylint seems to have a bug. Doesn't know self.x can be defined before
# method call.
# W0201: doesn't let any attributes be added outside __init__
# C1801: do not use len(s) to tell if s is empty
# E1129: a check on context managers
# This is disabled because it complains about "with sess.as_default".
# pylint does not seem to believe that that is a real context manager.
# C0325: unnecessary parens (sometimes we use them to be extra-explicit)
# R1705: "unnecessary else after return"
# We disable this one because it is annoying. It forbids
# if a:
# return b
# else:
# return c
# The name "unnecessary else after return" seems misleading, and it would be
# annoying and use more lines to rewrite everything as:
# if a:
# out = b
# else:
# out = c
# return out
# W0703: catching too general exception
# W0101: unreachable code
# We disable this one because it does not allow:
#
# class A(object):
# def f(self):
# raise NotImplementedError("Subclass must implement f")
# return 0
#
# W0101 complains that the `return 0` is never reached.
# However, if we do not have the return statement, we get E1111 on lines
# such as:
#
# x = a.f()
#
# because pylint sees no return statement in f.
# We can't have both W0101 and E1111, and between them, it is better to
# disable W0101 because dead code is less likely to be a bug than using a
# null return value. Also, as of this writing, the only instance of W0101 is
# an abstract method like in the example shown here, so we are not writing
# any dead code by accident in practice.
#
# W0122: use of exec
# R0912: too many branches
# R0903: too few public methods
# W0221: parameters differ from overridden method
# W0212: protected access
# R1703: simplifiable if statement
# R0201: method could be a function
# W0603: global statement
# R0915: too many statements
# R0902: too many attributes
# C0200: consider using enumerate
# W1201: logging not lazy
# Disabled because it forbids things like
# logging.info('#' * pad + msg + '#' * pad)
# Doesn't seem useful to refactor this to
# padded_msg = '#' * pad + msg + '#' * pad
# logging.info(padded_msg)
# or to refactor it to
# logging.info('%s%s%s', pad, msg, pad)
# The speedup of avoiding a string concatenation is presumably negligible
# compared to most of the ML operations we do to generate log messages.
# C0302: too many lines in module
# W0511: forbids TODOs
# R0911: too many return statements
# E0401: cannot import module
# R0205: this one is apparently asking us to drop python 2 support?
# R1714: use x in [a,b] instead of x == a or x == b
# R0801: duplicate code across files
# (We have a lot of intentional duplication, like the tutorials)
disable=C0103,W0613,E1101,R0913,R0914,W0223,E0203,W0201,C1801,E1129,C0325,R1705,W0622,W0703,W0101,W0122,R0912,R0903,W0221,W0212,R1703,R0201,W0603,R0915,R0902,C0200,W1201,C0302,W0511,R0911,E0401,R0205,R1714,R0801,E1130
[IMPORTS]
# Explicitly specifying this helps pylint to behave more consistently across multiple platforms.
# If not specified, the method used to install each library seems to change whether it is considered third party, etc.
known-third-party=joblib,keras,numpy,PIL,six,tensorflow
================================================
FILE: .setup_vm_and_run_tests.sh
================================================
#!/bin/sh
set -e
# Run update once so apt-get will work at all
sudo apt-get update
# Install apt-add-repository
sudo apt-get install -y software-properties-common
# Add universe repository so python-pip is available
sudo apt-add-repository universe
# Run update again now that universe is a source
apt-get update
apt-get -y install curl
apt-get install -y wget
rm -rf /var/lib/apt/lists/*
# code below is taken from http://conda.pydata.org/docs/travis.html
# We do this conditionally because it saves us some downloading if the
# version is the same.
export CLOUD_BUILD_PYTHON_VERSION=2.7
if [[ "$CLOUD_BUILD_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
export TENSORFLOW_V="1.8.0"
hash -r
conda config --set always_yes yes --set changeps1 no
conda update -q conda
# Useful for debugging any issues with conda
conda info -a
conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy pyqt=4.11 matplotlib pandas h5py six mkl-service
# Enable `conda activate`
sudo ln -s /root/miniconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
conda activate test-environment
# install TensorFlow
if [[ "$CLOUD_BUILD_PYTHON_VERSION" == "2.7" && "$TENSORFLOW_V" == "1.4.1" ]]; then
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.1-cp27-none-linux_x86_64.whl;
elif [[ "$COULD_BUILD_PYTHON_VERSION" == "2.7" && "$TENSORFLOW_V" == "1.8.0" ]]; then
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp27-none-linux_x86_64.whl;
elif [[ "$CLOUD_BUILD_PYTHON_VERSION" == "3.5" && "$TENSORFLOW_V" == "1.4.1" ]]; then
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.1-cp35-cp35m-linux_x86_64.whl;
elif [[ "$CLOUD_BUILD_PYTHON_VERSION" == "3.5" && "$TENSORFLOW_V" == "1.8.0" ]]; then
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp35-cp35m-linux_x86_64.whl;
fi
time pip install -q -e ".[test]"
PYTORCH=True
if [[ "$PYTORCH" == True ]]; then
pip install torch==0.4.0 torchvision==0.2.1 -q;
fi
# workaround for version incompatibility between the scipy version in conda
# and the system-provided /usr/lib/x86_64-linux-gnu/libstdc++.so.6
# by installing a conda-provided libgcc and adding it to the load path
conda install libgcc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/travis/miniconda/envs/test-environment/lib
# install serialization dependencies
pip install joblib
# install dependencies for adversarial competition eval infra tests
pip install google-cloud==0.33.1
pip install Pillow
# Style checks
pip install pylint
================================================
FILE: CODE_OF_CONDUCT.rst
================================================
CleverHans is dedicated to providing a harassment-free experience for
everyone, regardless of gender, gender identity and expression, sexual
orientation, disability, physical appearance, body size, age, race, or
religion. We do not tolerate harassment of participants in any form.
This code of conduct applies to all CleverHans spaces (including Gist
comments) both online and off. Anyone who violates this code of
conduct may be sanctioned or expelled from these spaces at the
discretion of the OpenAI / Pennsylvania State University team.
We may add additional rules over time, which will be made clearly
available to participants. Participants are responsible for knowing
and abiding by these rules.
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing to CleverHans
First off, thank you for considering contributing to CleverHans.
Following these guidelines helps to communicate that you respect
the time of the researchers and developers managing and developing this open
source project. In return, they should reciprocate that respect in
addressing your issue, assessing changes, and helping you finalize
your pull requests.
Adding new features, improving documentation, bug triaging, or
writing tutorials are all
examples of helpful contributions.
Furthermore, if you are publishing a new attack or defense,
we strongly encourage you to add it to CleverHans so that others
may evaluate it fairly in their own work.
To speed the code review process, we ask that:
* New efforts and features be coordinated on the [discussion board](https://github.com/cleverhans-lab/cleverhans/discussions).
* When making code contributions to CleverHans, you should follow the
[`Black`](https://black.readthedocs.io/en/stable/index.html) coding style in your pull requests.
* We do not accept pull requests that add git submodules because of [the
problems that arise when maintaining git
submodules](https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407)
Bug fixes can be initiated through Github pull requests.
## Development setup
Please follow the usual
[git forking workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow)
when contributing.
### Setting up Cleverhans on your machine
Then create a new Conda or Virtualenv environment.
Conda:
```
$ conda create --name cleverhans python=3.6
$ conda activate cleverhans
```
Virtualenv:
```
$ python3 -m venv /path/to/new/virtual/environment
$ cd /path/to/new/virtual/environment
$ source ./bin/activate
```
Then, after `cd`-ing into the `cleverhans` directory, install the
Cleverhans library and all corresponding requirements into your
newly created environment.
```
$ pip install -e "."
$ pip install -r requirements/requirements.txt
$ pip install -r requirements/requirements-pytorch.txt
$ pip install -r requirements/requirements-jax.txt
$ pip install -r requirements/requirements-tf2.txt
$ pip install -r requirements/requirements-dev.txt
```
Optionally also install GPU dependencies for JAX (PyTorch and
TF2 already come with GPU as part of their default package):
```
$ pip install -r requirements/requirements-gpu.txt
```
### Add git pre-commit hooks
Install our pre-commit hooks that ensure that your code is always formatted
via `black` before committing.
```
$ pre-commit install
```
Note that we do have code style checks in place for every submitted
PR and will reject PRs that do not meet these checks. By installing the
pre-commit hooks, this will be taken care of automatically
================================================
FILE: Dockerfile
================================================
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y python
RUN apt-get install -y python-pip
RUN pip install --upgrade pip
COPY .setup_vm_and_run_tests.sh /
RUN chmod +x /.setup_vm_and_run_tests.sh
CMD ["/.setup_vm_and_run_tests.sh"]
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2019 Google Inc., OpenAI and Pennsylvania State University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# CleverHans (latest release: v4.0.0)
<img src="https://github.com/tensorflow/cleverhans/blob/master/assets/logo.png?raw=true" alt="cleverhans logo">
This repository contains the source code for CleverHans, a Python library to
benchmark machine learning systems' vulnerability to
[adversarial examples](http://karpathy.github.io/2015/03/30/breaking-convnets/).
You can learn more about such vulnerabilities on the accompanying [blog](http://cleverhans.io).
The CleverHans library is under continual development, always welcoming
[contributions](https://github.com/cleverhans-lab/cleverhans#contributing)
of the latest attacks and defenses.
In particular, we always welcome help towards resolving the [issues](https://github.com/cleverhans-lab/cleverhans/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](https://github.com/google/jax), [PyTorch](https://pytorch.org/) or [TensorFlow 2](https://www.tensorflow.org/) 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](https://pypi.org/project/cleverhans).
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](https://stackoverflow.com/questions/tagged/cleverhans)
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:
* New efforts and features be coordinated on the [discussion board](https://github.com/cleverhans-lab/cleverhans/discussions).
* When making code contributions to CleverHans, you should follow the [`Black`](https://black.readthedocs.io/en/stable/index.html)
coding style in your pull requests.
* We do not accept pull requests that add git submodules because of [the
problems that arise when maintaining git
submodules](https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407).
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:
* **MNIST with FGSM and PGD** ([jax](tutorials/jax/mnist_tutorial.py), [tf2](tutorials/tf2/mnist_tutorial.py):
this tutorial covers how to train an MNIST model and craft adversarial examples using the
[fast gradient sign method](https://arxiv.org/abs/1412.6572) and
[projected gradient descent](https://arxiv.org/abs/1706.06083).
* **CIFAR10 with FGSM and PGD** ([pytorch](tutorials/torch/cifar10_tutorial.py), [tf2](tutorials/tf2/cifar10_tutorial.py)):
this tutorial covers how to train a CIFAR10 model and
craft adversarial examples using the [fast gradient sign method](https://arxiv.org/abs/1412.6572) and
[projected gradient descent](https://arxiv.org/abs/1706.06083).
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](https://github.com/cleverhans-lab/cleverhans/discussions) 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](https://github.com/cleverhans-lab/cleverhans/releases).
* 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](https://arxiv.org/abs/1610.00768):
```
@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'."](http://ieeexplore.ieee.org/document/6847693/) 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](https://cleverhans-lab.github.io/)
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.
================================================
FILE: cleverhans/__init__.py
================================================
"""The CleverHans adversarial example library"""
from cleverhans.devtools.version import append_dev_version
# If possible attach a hex digest to the version string to keep track of
# changes in the development branch
__version__ = append_dev_version("4.0.0")
================================================
FILE: cleverhans/devtools/LICENSE.txt
================================================
The devtools module is a derivative work from the devtools module of pylearn2.
We reproduce the corresponding license here.
Copyright (c) 2011--2014, Université de Montréal
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: cleverhans/devtools/__init__.py
================================================
================================================
FILE: cleverhans/devtools/autopep8_all.py
================================================
"""
Run this script to run autopep8 on everything in the library
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from cleverhans.devtools.list_files import list_files
from cleverhans.utils import shell_call
for f in list_files(".py"):
command = ["autopep8", "-i", "--indent-size", "2", f]
shell_call(command)
================================================
FILE: cleverhans/devtools/checks.py
================================================
"""Functionality for building tests.
We have to call this file "checks" and not anything with "test" as a
substring or nosetests will execute it.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
import unittest
import numpy as np
class CleverHansTest(unittest.TestCase):
"""TestCase with some extra features"""
def setUp(self):
self.test_start = time.time()
# seed the randomness
np.random.seed(1234)
def tearDown(self):
print(self.id(), "took", time.time() - self.test_start, "seconds")
def assertClose(self, x, y, *args, **kwargs):
"""Assert that `x` and `y` have close to the same value"""
# self.assertTrue(np.allclose(x, y)) doesn't give a useful message
# on failure
assert np.allclose(x, y, *args, **kwargs), (x, y)
================================================
FILE: cleverhans/devtools/list_files.py
================================================
"""Code for listing files that belong to the library."""
import os
import cleverhans
def list_files(suffix=""):
"""
Returns a list of all files in CleverHans with the given suffix.
Parameters
----------
suffix : str
Returns
-------
file_list : list
A list of all files in CleverHans whose filepath ends with `suffix`.
"""
cleverhans_path = os.path.abspath(cleverhans.__path__[0])
# In some environments cleverhans_path does not point to a real directory.
# In such case return empty list.
if not os.path.isdir(cleverhans_path):
return []
repo_path = os.path.abspath(os.path.join(cleverhans_path, os.pardir))
file_list = _list_files(cleverhans_path, suffix)
extra_dirs = [
"cleverhans_tutorials",
"examples",
"scripts",
"tests_tf",
"tests_pytorch",
]
for extra_dir in extra_dirs:
extra_path = os.path.join(repo_path, extra_dir)
if os.path.isdir(extra_path):
extra_files = _list_files(extra_path, suffix)
extra_files = [os.path.join(os.pardir, path) for path in extra_files]
file_list = file_list + extra_files
return file_list
def _list_files(path, suffix=""):
"""
Returns a list of all files ending in `suffix` contained within `path`.
Parameters
----------
path : str
a filepath
suffix : str
Returns
-------
l : list
A list of all files ending in `suffix` contained within `path`.
(If `path` is a file rather than a directory, it is considered
to "contain" itself)
"""
if os.path.isdir(path):
incomplete = os.listdir(path)
complete = [os.path.join(path, entry) for entry in incomplete]
lists = [_list_files(subpath, suffix) for subpath in complete]
flattened = []
for one_list in lists:
for elem in one_list:
flattened.append(elem)
return flattened
else:
assert os.path.exists(path), "couldn't find file '%s'" % path
if path.endswith(suffix):
return [path]
return []
================================================
FILE: cleverhans/devtools/mocks.py
================================================
"""Utility functions for mocking up tests.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import copy
import numpy as np
from cleverhans.dataset import Dataset, np_utils
def random_feed_dict(rng, placeholders):
"""
Returns random data to be used with `feed_dict`.
:param rng: A numpy.random.RandomState instance
:param placeholders: List of tensorflow placeholders
:return: A dict mapping placeholders to random numpy values
"""
output = {}
for placeholder in placeholders:
if placeholder.dtype != "float32":
raise NotImplementedError()
value = rng.randn(*placeholder.shape).astype("float32")
output[placeholder] = value
return output
class SimpleDataset(Dataset):
"""
A dataset containing random values.
Values are uniformly distributed, either in [0, max_val] or [-1, max_val].
"""
def __init__(
self,
dim=2,
train_start=0,
train_end=3,
test_start=0,
test_end=5,
center=False,
max_val=1.0,
nb_classes=5,
):
kwargs = copy.copy(locals())
del kwargs["self"]
if "__class__" in kwargs:
del kwargs["__class__"]
super(SimpleDataset, self).__init__(kwargs)
self.__dict__.update(kwargs)
train_x_rng = np.random.RandomState([2018, 11, 9, 1])
# Even if train_start is not 0, we should still generate the first training examples from the rng.
# This way the dataset looks like it is an array of deterministic data that we index using train_start.
self.x_train = train_x_rng.uniform(
-center * max_val, max_val, (train_end, dim)
)[train_start:]
# Use a second rng for the test set so that it also looks like an array of deterministic data that we
# index into, unaffected by the number of training examples.
test_x_rng = np.random.RandomState([2018, 11, 9, 2])
self.x_test = test_x_rng.uniform(-center * max_val, max_val, (test_end, dim))[
test_start:
]
# Likewise, to keep the number of examples read from the rng affecting the values of the labels, we
# must generate the labels from a different rng
train_y_rng = np.random.RandomState([2018, 11, 9, 3])
self.y_train = train_y_rng.randint(low=0, high=nb_classes, size=(train_end, 1))[
train_start:
]
test_y_rng = np.random.RandomState([2018, 11, 9, 4])
self.y_test = test_y_rng.randint(low=0, high=nb_classes, size=(test_end, 1))[
test_start:
]
assert self.x_train.shape[0] == self.y_train.shape[0]
assert self.x_test.shape[0] == self.y_test.shape[0]
self.y_train = np_utils.to_categorical(self.y_train, nb_classes)
self.y_test = np_utils.to_categorical(self.y_test, nb_classes)
================================================
FILE: cleverhans/devtools/tests/__init__.py
================================================
================================================
FILE: cleverhans/devtools/tests/test_format.py
================================================
"""
Unit tests for format checking
"""
from __future__ import print_function
import os
import subprocess
import cleverhans
from cleverhans.devtools.list_files import list_files
from cleverhans.utils import shell_call
# Enter a manual list of files that are allowed to violate PEP8 here
whitelist_pep8 = [
# This file is broken but could be fixed
"../examples/multigpu_advtrain/test_attack_multigpu.py"
]
all_py_files = list_files(".py")
def update_whitelist():
"""Add files to the whitelist"""
global whitelist_pep8
# We don't want to test RL-attack because it has so many dependencies
# not used elsewhere, and pylint wants to import them all
whitelist_pep8.extend(
[
os.path.relpath(path, cleverhans.__path__[0])
for path in all_py_files
if "RL-attack" in path
]
)
# Similarly, we don't want to require robust_vision_benchmark installed
whitelist_pep8.extend(
[
os.path.relpath(path, cleverhans.__path__[0])
for path in all_py_files
if "robust_vision_benchmark" in path
]
)
# Similarly, we don't want to require that cloud be installed
whitelist_pep8.extend(
[
os.path.relpath(path, cleverhans.__path__[0])
for path in all_py_files
if "cloud_client" in path
]
)
# This example has more dependencies too
whitelist_pep8.extend(
[
os.path.relpath(path, cleverhans.__path__[0])
for path in all_py_files
if "facenet_adversarial_faces" in path
]
)
# This too
whitelist_pep8.extend(
[
os.path.relpath(path, cleverhans.__path__[0])
for path in all_py_files
if "madry_lab_challenges" in path
]
)
# This code is no longer compatible with new versions of cleverhans / scipy and will be removed soon
whitelist_pep8.extend(
[
os.path.relpath(path, cleverhans.__path__[0])
for path in all_py_files
if "nips17_adversarial_competition" in path
]
)
update_whitelist()
whitelist_docstrings = []
def test_format_pep8():
"""
Test if pep8 is respected.
"""
files_to_check = []
module_dir = cleverhans.__path__[0]
for path in all_py_files:
rel_path = os.path.relpath(path, module_dir)
if rel_path in whitelist_pep8:
continue
else:
files_to_check.append(path)
repo_dir = os.path.join(module_dir, os.pardir)
rcpath = os.path.join(repo_dir, ".pylintrc")
assert os.path.exists(rcpath)
# We must run pylint via the command line and subprocess because of
# problems with the pylint module.
# The documentation claims you can run it as a python module, but
# the documentation is wrong: https://github.com/PyCQA/pylint/issues/1870
# If you run the version described in the linked issue, pylint
# calls sys.exit once it is done, so it kills the test.
# Running all files in one pylint command is important for 2 reasons:
# 1) Correctness: pylint can detect issues that require access to multiple
# files, such as cyclic imports
# 2) Speed: pylint imports modules for deep analysis, so if you run
# multiple subprocesses each needs to re-import tensorflow.
# On Ian's laptop, pylint takes about 10s per file to run on the repo,
# and there are about 90 files as of the writing of this comment.
# Running pylint on all files simultaneously takes about 70s, so it
# is a little better than a 10X speedup.
# Running multiple jobs in parallel helps but far less than linearly.
# On Ian's 4-core laptop, running 4 jobs drops the runtime from 70s
# to 45s.
# Some of the work is I/O, so it actually makes some sense to run
# more jobs than cores. On Ian's 4-core laptop, running 8 jobs drops
# the runtime to 40s.
# There's a further complication though: I think each job needs to
# redo imports, so the total amount of work to do increases with
# the number of jobs. On Ian's laptop, using 64 jobs causes the
# runtime to increase to 220s. There is not an obvious simple
# formula like "use one job per CPU core" or "use way more jobs
# than cores to saturate I/O". For now I'm hoping that 8 will be
# a reasonable default: it gets good performance on my laptop,
# and on machines with fewer than 4 cores there should still be
# a benefit to not being blocked on I/O.
try:
shell_call(["pylint", "--rcfile", rcpath, "--jobs", "8"] + files_to_check)
except subprocess.CalledProcessError as e:
raise ValueError(e.output.decode("utf-8"))
if __name__ == "__main__":
test_format_pep8()
================================================
FILE: cleverhans/devtools/version.py
================================================
"""
Utility functions for keeping track of the version of CleverHans.
These functions provide a finer level of granularity than the
manually specified version string attached to each release.
"""
import hashlib
from cleverhans.devtools.list_files import list_files
def dev_version():
"""
Returns a hexdigest of all the python files in the module.
"""
md5_hash = hashlib.md5()
py_files = sorted(list_files(suffix=".py"))
if not py_files:
return ""
for filename in py_files:
with open(filename, "rb") as fobj:
content = fobj.read()
md5_hash.update(content)
return md5_hash.hexdigest()
def append_dev_version(release_version):
"""
If dev version is not empty appends it to release_version.
"""
dev_version_value = dev_version()
if dev_version_value:
return release_version + "-" + dev_version_value
else:
return release_version
================================================
FILE: cleverhans/experimental/README.md
================================================
This directory contains experimental features of CleverHans, which are not
integrated into the main API yet.
================================================
FILE: cleverhans/experimental/__init__.py
================================================
================================================
FILE: cleverhans/experimental/certification/README.md
================================================
# Certification of adversarial robustness
This code performs certification of adversarial robustness of given network on
given example.
Original author: [Aditi Raghunathan](https://github.com/RAditi)
## Dependencies
TensorFlow 1.9.0 or higher (to have support of necessary
[autograph](https://www.tensorflow.org/guide/autograph) features)
## Usage
Example usage for two-layer network trained on MNIST:
```bash
# Meaning of the arguments:
# checkpoint - TensorFlow checkpoint of the model parameters
# model_json - JSON file which describes the model (see below)
# test_input - numpy file with input to certify
# true_class - true class of the input
# adv_class - adversarial class for which we're checking certificate,
# -1 means that all adversarial classes will be checked
# epsilon - maximum size of adversarial perturbation
# init_nu and small_eig_num_steps - optimization parameters
python cleverhans/experimental/certification/certify.py \
--checkpoint "${MODEL_DIR}/model.ckpt" \
--model_json "${MODEL_DIR}/model.json" \
--test_input "${INPUTS_DIR}/image.npy" \
--true_class 4 \
--adv_class 5 \
--epsilon 0.2 \
--init_nu 100.0 \
--small_eig_num_steps 100
```
JSON file which accompany checkpoint and describes layers of the network:
```json
[
{
"weight_var": "Model/layer0/logits/kernel",
"bias_var": "Model/layer0/logits/bias",
"type": "ff_relu",
"is_transpose": true
},
{
"weight_var": "Model/logits/kernel",
"bias_var": "Model/logits/bias",
"type": "ff",
"is_transpose": true
}
]
```
================================================
FILE: cleverhans/experimental/certification/__init__.py
================================================
================================================
FILE: cleverhans/experimental/certification/certify.py
================================================
"""Code for running the certification problem."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
import numpy as np
import tensorflow as tf
from cleverhans.experimental.certification import dual_formulation
from cleverhans.experimental.certification import nn
from cleverhans.experimental.certification import optimization
from cleverhans.experimental.certification import utils
flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_string(
"checkpoint", None, "Path of checkpoint with trained model to verify"
)
flags.DEFINE_string("model_json", None, "Path of json file with model description")
flags.DEFINE_string(
"init_dual_file", None, "Path of numpy file with dual variables to initialize"
)
flags.DEFINE_string("test_input", None, "Path of numpy file with test input to certify")
flags.DEFINE_integer("true_class", 0, "True class of the test input")
flags.DEFINE_integer(
"adv_class", -1, "target class of adversarial example; all classes if -1"
)
flags.DEFINE_float("input_minval", -1, "Minimum value of valid input")
flags.DEFINE_float("input_maxval", 1, "Maximum value of valid input")
flags.DEFINE_float("epsilon", 0.2, "Size of perturbation")
# Nu might need tuning based on the network
flags.DEFINE_float("init_nu", 300.0, "Initialization of nu variable.")
flags.DEFINE_float("init_penalty", 100.0, "Initial penalty")
flags.DEFINE_integer(
"small_eig_num_steps", 500, "Number of eigen value steps in intermediate iterations"
)
flags.DEFINE_integer(
"large_eig_num_steps", 5000, "Number of eigen value steps in each outer iteration"
)
flags.DEFINE_integer("inner_num_steps", 600, "Number of steps to run in inner loop")
flags.DEFINE_float("outer_num_steps", 10, "Number of steps to run in outer loop")
flags.DEFINE_float("beta", 2, "Multiplicative factor to increase penalty by")
flags.DEFINE_float(
"smoothness_parameter", 0.001, "Smoothness parameter if using eigen decomposition"
)
flags.DEFINE_float(
"eig_learning_rate", 0.001, "Learning rate for computing min eigen value"
)
flags.DEFINE_string("optimizer", "adam", "Optimizer to use for entire optimization")
flags.DEFINE_float("init_learning_rate", 0.1, "Initial learning rate")
flags.DEFINE_float("learning_rate_decay", 0.1, "Decay of learning rate")
flags.DEFINE_float(
"momentum_parameter", 0.9, "Momentum parameter if using momentum optimizer"
)
flags.DEFINE_integer("print_stats_steps", 50, "Number of steps to print stats after")
flags.DEFINE_string("stats_folder", None, "Folder to save stats of the iterations")
flags.DEFINE_integer(
"projection_steps", 200, "Number of steps to compute projection after"
)
flags.DEFINE_integer("num_classes", 10, "Total number of classes")
flags.DEFINE_enum(
"verbosity",
"INFO",
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
"Logging verbosity level.",
)
flags.DEFINE_string(
"eig_type", "LZS", "Method to compute eigenvalues (TF, SCIPY, or LZS), LZS"
)
flags.DEFINE_integer(
"lanczos_steps", 20, "Number of steps to perform in Lanczos method."
)
flags.DEFINE_integer("num_rows", 28, "Number of rows in image")
flags.DEFINE_integer("num_columns", 28, "Number of columns in image")
flags.DEFINE_integer("num_channels", 1, "Number of channels in image")
MIN_LANCZOS_ITER = 5
def main(_):
# pylint: disable=missing-docstring
tf.logging.set_verbosity(FLAGS.verbosity)
start_time = time.time()
# Initialize neural network based on config files
input_shape = [FLAGS.num_rows, FLAGS.num_columns, FLAGS.num_channels]
nn_params = nn.load_network_from_checkpoint(
FLAGS.checkpoint, FLAGS.model_json, input_shape
)
tf.logging.info("Loaded neural network with size of layers: %s", nn_params.sizes)
tf.logging.info(
"Loaded neural network with input shapes: %s", nn_params.input_shapes
)
tf.logging.info(
"Loaded neural network with output shapes: %s", nn_params.output_shapes
)
dual_var = utils.initialize_dual(
nn_params, FLAGS.init_dual_file, init_nu=FLAGS.init_nu
)
# Reading test input and reshaping
with tf.gfile.Open(FLAGS.test_input) as f:
test_input = np.load(f)
test_input = np.reshape(test_input, [np.size(test_input), 1])
if FLAGS.adv_class == -1:
start_class = 0
end_class = FLAGS.num_classes
else:
start_class = FLAGS.adv_class
end_class = FLAGS.adv_class + 1
for adv_class in range(start_class, end_class):
tf.logging.info("Running certification for adversarial class %d", adv_class)
if adv_class == FLAGS.true_class:
continue
optimization_params = {
"init_penalty": FLAGS.init_penalty,
"large_eig_num_steps": FLAGS.large_eig_num_steps,
"small_eig_num_steps": FLAGS.small_eig_num_steps,
"inner_num_steps": FLAGS.inner_num_steps,
"outer_num_steps": FLAGS.outer_num_steps,
"beta": FLAGS.beta,
"smoothness_parameter": FLAGS.smoothness_parameter,
"eig_learning_rate": FLAGS.eig_learning_rate,
"optimizer": FLAGS.optimizer,
"init_learning_rate": FLAGS.init_learning_rate,
"learning_rate_decay": FLAGS.learning_rate_decay,
"momentum_parameter": FLAGS.momentum_parameter,
"print_stats_steps": FLAGS.print_stats_steps,
"stats_folder": FLAGS.stats_folder,
"projection_steps": FLAGS.projection_steps,
"eig_type": FLAGS.eig_type,
"has_conv": nn_params.has_conv,
"lanczos_steps": FLAGS.lanczos_steps,
}
lzs_params = {"min_iter": MIN_LANCZOS_ITER, "max_iter": FLAGS.lanczos_steps}
with tf.Session() as sess:
dual = dual_formulation.DualFormulation(
sess,
dual_var,
nn_params,
test_input,
FLAGS.true_class,
adv_class,
FLAGS.input_minval,
FLAGS.input_maxval,
FLAGS.epsilon,
lzs_params,
)
optimization_object = optimization.Optimization(
dual, sess, optimization_params
)
is_cert_found = optimization_object.run_optimization()
if not is_cert_found:
print("Example could not be verified")
exit()
print("Example successfully verified")
print("Elapsed time: " + str(time.time() - start_time))
if __name__ == "__main__":
tf.app.run(main)
================================================
FILE: cleverhans/experimental/certification/dual_formulation.py
================================================
"""Code with dual formulation for certification problem."""
# pylint: disable=missing-docstring
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from scipy.sparse.linalg import eigs, LinearOperator
import tensorflow as tf
from tensorflow.contrib import autograph
import numpy as np
from cleverhans.experimental.certification import utils
flags = tf.app.flags
FLAGS = flags.FLAGS
# Tolerance value for eigenvalue computation
TOL = 1e-5
# Binary search constants
MAX_BINARY_SEARCH_ITER = 10
NU_UPDATE_CONSTANT = 1.3
# Bound on lowest value of certificate to check for numerical errors
LOWER_CERT_BOUND = -5.0
DEFAULT_LZS_PARAMS = {"min_iter": 5, "max_iter": 50}
class DualFormulation(object):
"""DualFormulation is a class that creates the dual objective function
and access to matrix vector products for the matrix that is constrained
to be Positive semidefinite
"""
def __init__(
self,
sess,
dual_var,
neural_net_param_object,
test_input,
true_class,
adv_class,
input_minval,
input_maxval,
epsilon,
lzs_params=None,
project_dual=True,
):
"""Initializes dual formulation class.
Args:
sess: Tensorflow session
dual_var: dictionary of dual variables containing a) lambda_pos
b) lambda_neg, c) lambda_quad, d) lambda_lu
neural_net_param_object: NeuralNetParam object created for the network
under consideration
test_input: clean example to certify around
true_class: the class label of the test input
adv_class: the label that the adversary tried to perturb input to
input_minval: minimum value of valid input range
input_maxval: maximum value of valid input range
epsilon: Size of the perturbation (scaled for [0, 1] input)
lzs_params: Parameters for Lanczos algorithm (dictionary) in the form:
{
'min_iter': 5
'max_iter': 50
}
project_dual: Whether we should create a projected dual object
"""
self.sess = sess
self.nn_params = neural_net_param_object
self.test_input = tf.convert_to_tensor(test_input, dtype=tf.float32)
self.true_class = true_class
self.adv_class = adv_class
self.input_minval = tf.convert_to_tensor(input_minval, dtype=tf.float32)
self.input_maxval = tf.convert_to_tensor(input_maxval, dtype=tf.float32)
self.epsilon = tf.convert_to_tensor(epsilon, dtype=tf.float32)
self.lzs_params = lzs_params or DEFAULT_LZS_PARAMS.copy()
self.final_linear = (
self.nn_params.final_weights[adv_class, :]
- self.nn_params.final_weights[true_class, :]
)
self.final_linear = tf.reshape(
self.final_linear, shape=[tf.size(self.final_linear), 1]
)
self.final_constant = (
self.nn_params.final_bias[adv_class] - self.nn_params.final_bias[true_class]
)
self.lanczos_dtype = tf.float64
self.nn_dtype = tf.float32
# Computing lower and upper bounds
# Note that lower and upper are of size nn_params.num_hidden_layers + 1
self.lower = []
self.upper = []
# Also computing pre activation lower and upper bounds
# to compute always-off and always-on units
self.pre_lower = []
self.pre_upper = []
# Initializing at the input layer with \ell_\infty constraints
self.lower.append(tf.maximum(self.test_input - self.epsilon, self.input_minval))
self.upper.append(tf.minimum(self.test_input + self.epsilon, self.input_maxval))
self.pre_lower.append(self.lower[0])
self.pre_upper.append(self.upper[0])
for i in range(0, self.nn_params.num_hidden_layers):
lo_plus_up = self.nn_params.forward_pass(self.lower[i] + self.upper[i], i)
lo_minus_up = self.nn_params.forward_pass(
self.lower[i] - self.upper[i], i, is_abs=True
)
up_minus_lo = self.nn_params.forward_pass(
self.upper[i] - self.lower[i], i, is_abs=True
)
current_lower = 0.5 * (lo_plus_up + lo_minus_up) + self.nn_params.biases[i]
current_upper = 0.5 * (lo_plus_up + up_minus_lo) + self.nn_params.biases[i]
self.pre_lower.append(current_lower)
self.pre_upper.append(current_upper)
self.lower.append(tf.nn.relu(current_lower))
self.upper.append(tf.nn.relu(current_upper))
# Run lower and upper because they don't change
self.pre_lower = self.sess.run(self.pre_lower)
self.pre_upper = self.sess.run(self.pre_upper)
self.lower = self.sess.run(self.lower)
self.upper = self.sess.run(self.upper)
# Using the preactivation lower and upper bounds
# to compute the linear regions
self.positive_indices = []
self.negative_indices = []
self.switch_indices = []
for i in range(0, self.nn_params.num_hidden_layers + 1):
# Positive index = 1 if the ReLU is always "on"
self.positive_indices.append(
np.asarray(self.pre_lower[i] >= 0, dtype=np.float32)
)
# Negative index = 1 if the ReLU is always off
self.negative_indices.append(
np.asarray(self.pre_upper[i] <= 0, dtype=np.float32)
)
# Switch index = 1 if the ReLU could be either on or off
self.switch_indices.append(
np.asarray(
np.multiply(self.pre_lower[i], self.pre_upper[i]) < 0,
dtype=np.float32,
)
)
# Computing the optimization terms
self.lambda_pos = [x for x in dual_var["lambda_pos"]]
self.lambda_neg = [x for x in dual_var["lambda_neg"]]
self.lambda_quad = [x for x in dual_var["lambda_quad"]]
self.lambda_lu = [x for x in dual_var["lambda_lu"]]
self.nu = dual_var["nu"]
self.vector_g = None
self.scalar_f = None
self.matrix_h = None
self.matrix_m = None
self.matrix_m_dimension = 1 + np.sum(self.nn_params.sizes)
# The primal vector in the SDP can be thought of as [layer_1, layer_2..]
# In this concatenated version, dual_index[i] that marks the start
# of layer_i
# This is useful while computing implicit products with matrix H
self.dual_index = [0]
for i in range(self.nn_params.num_hidden_layers + 1):
self.dual_index.append(self.dual_index[-1] + self.nn_params.sizes[i])
# Construct objectives, matrices, and certificate
self.set_differentiable_objective()
if not self.nn_params.has_conv:
self.get_full_psd_matrix()
# Setup Lanczos functionality for compute certificate
self.construct_lanczos_params()
# Create projected dual object
if project_dual:
self.projected_dual = self.create_projected_dual()
def create_projected_dual(self):
"""Function to create variables for the projected dual object.
Function that projects the input dual variables onto the feasible set.
Returns:
projected_dual: Feasible dual solution corresponding to current dual
"""
# TODO: consider whether we can use shallow copy of the lists without
# using tf.identity
projected_nu = tf.placeholder(tf.float32, shape=[])
min_eig_h = tf.placeholder(tf.float32, shape=[])
projected_lambda_pos = [tf.identity(x) for x in self.lambda_pos]
projected_lambda_neg = [tf.identity(x) for x in self.lambda_neg]
projected_lambda_quad = [tf.identity(x) for x in self.lambda_quad]
projected_lambda_lu = [tf.identity(x) for x in self.lambda_lu]
for i in range(self.nn_params.num_hidden_layers + 1):
# Making H PSD
projected_lambda_lu[i] = (
self.lambda_lu[i] + 0.5 * tf.maximum(-min_eig_h, 0) + TOL
)
# Adjusting the value of \lambda_neg to make change in g small
projected_lambda_neg[i] = self.lambda_neg[i] + tf.multiply(
(self.lower[i] + self.upper[i]),
(self.lambda_lu[i] - projected_lambda_lu[i]),
)
projected_lambda_neg[i] = tf.multiply(
self.negative_indices[i], projected_lambda_neg[i]
) + tf.multiply(
self.switch_indices[i], tf.maximum(projected_lambda_neg[i], 0)
)
projected_dual_var = {
"lambda_pos": projected_lambda_pos,
"lambda_neg": projected_lambda_neg,
"lambda_lu": projected_lambda_lu,
"lambda_quad": projected_lambda_quad,
"nu": projected_nu,
}
projected_dual_object = DualFormulation(
self.sess,
projected_dual_var,
self.nn_params,
self.test_input,
self.true_class,
self.adv_class,
self.input_minval,
self.input_maxval,
self.epsilon,
self.lzs_params,
project_dual=False,
)
projected_dual_object.min_eig_val_h = min_eig_h
return projected_dual_object
def construct_lanczos_params(self):
"""Computes matrices T and V using the Lanczos algorithm.
Args:
k: number of iterations and dimensionality of the tridiagonal matrix
Returns:
eig_vec: eigen vector corresponding to min eigenvalue
"""
# Using autograph to automatically handle
# the control flow of minimum_eigen_vector
self.min_eigen_vec = autograph.to_graph(utils.tf_lanczos_smallest_eigval)
def _m_vector_prod_fn(x):
return self.get_psd_product(x, dtype=self.lanczos_dtype)
def _h_vector_prod_fn(x):
return self.get_h_product(x, dtype=self.lanczos_dtype)
# Construct nodes for computing eigenvalue of M
self.m_min_vec_estimate = np.zeros(
shape=(self.matrix_m_dimension, 1), dtype=np.float64
)
zeros_m = tf.zeros(shape=(self.matrix_m_dimension, 1), dtype=tf.float64)
self.m_min_vec_ph = tf.placeholder_with_default(
input=zeros_m, shape=(self.matrix_m_dimension, 1), name="m_min_vec_ph"
)
self.m_min_eig, self.m_min_vec = self.min_eigen_vec(
_m_vector_prod_fn,
self.matrix_m_dimension,
self.m_min_vec_ph,
self.lzs_params["max_iter"],
dtype=self.lanczos_dtype,
)
self.m_min_eig = tf.cast(self.m_min_eig, self.nn_dtype)
self.m_min_vec = tf.cast(self.m_min_vec, self.nn_dtype)
self.h_min_vec_estimate = np.zeros(
shape=(self.matrix_m_dimension - 1, 1), dtype=np.float64
)
zeros_h = tf.zeros(shape=(self.matrix_m_dimension - 1, 1), dtype=tf.float64)
self.h_min_vec_ph = tf.placeholder_with_default(
input=zeros_h, shape=(self.matrix_m_dimension - 1, 1), name="h_min_vec_ph"
)
self.h_min_eig, self.h_min_vec = self.min_eigen_vec(
_h_vector_prod_fn,
self.matrix_m_dimension - 1,
self.h_min_vec_ph,
self.lzs_params["max_iter"],
dtype=self.lanczos_dtype,
)
self.h_min_eig = tf.cast(self.h_min_eig, self.nn_dtype)
self.h_min_vec = tf.cast(self.h_min_vec, self.nn_dtype)
def set_differentiable_objective(self):
"""Function that constructs minimization objective from dual variables."""
# Checking if graphs are already created
if self.vector_g is not None:
return
# Computing the scalar term
bias_sum = 0
for i in range(0, self.nn_params.num_hidden_layers):
bias_sum = bias_sum + tf.reduce_sum(
tf.multiply(self.nn_params.biases[i], self.lambda_pos[i + 1])
)
lu_sum = 0
for i in range(0, self.nn_params.num_hidden_layers + 1):
lu_sum = lu_sum + tf.reduce_sum(
tf.multiply(
tf.multiply(self.lower[i], self.upper[i]), self.lambda_lu[i]
)
)
self.scalar_f = -bias_sum - lu_sum + self.final_constant
# Computing the vector term
g_rows = []
for i in range(0, self.nn_params.num_hidden_layers):
if i > 0:
current_row = (
self.lambda_neg[i]
+ self.lambda_pos[i]
- self.nn_params.forward_pass(
self.lambda_pos[i + 1], i, is_transpose=True
)
+ tf.multiply(self.lower[i] + self.upper[i], self.lambda_lu[i])
+ tf.multiply(self.lambda_quad[i], self.nn_params.biases[i - 1])
)
else:
current_row = -self.nn_params.forward_pass(
self.lambda_pos[i + 1], i, is_transpose=True
) + tf.multiply(self.lower[i] + self.upper[i], self.lambda_lu[i])
g_rows.append(current_row)
# Term for final linear term
g_rows.append(
(
self.lambda_pos[self.nn_params.num_hidden_layers]
+ self.lambda_neg[self.nn_params.num_hidden_layers]
+ self.final_linear
+ tf.multiply(
(
self.lower[self.nn_params.num_hidden_layers]
+ self.upper[self.nn_params.num_hidden_layers]
),
self.lambda_lu[self.nn_params.num_hidden_layers],
)
+ tf.multiply(
self.lambda_quad[self.nn_params.num_hidden_layers],
self.nn_params.biases[self.nn_params.num_hidden_layers - 1],
)
)
)
self.vector_g = tf.concat(g_rows, axis=0)
self.unconstrained_objective = self.scalar_f + 0.5 * self.nu
def get_h_product(self, vector, dtype=None):
"""Function that provides matrix product interface with PSD matrix.
Args:
vector: the vector to be multiplied with matrix H
Returns:
result_product: Matrix product of H and vector
"""
# Computing the product of matrix_h with beta (input vector)
# At first layer, h is simply diagonal
if dtype is None:
dtype = self.nn_dtype
beta = tf.cast(vector, self.nn_dtype)
h_beta_rows = []
for i in range(self.nn_params.num_hidden_layers):
# Split beta of this block into [gamma, delta]
gamma = beta[self.dual_index[i] : self.dual_index[i + 1]]
delta = beta[self.dual_index[i + 1] : self.dual_index[i + 2]]
# Expanding the product with diagonal matrices
if i == 0:
h_beta_rows.append(
tf.multiply(2 * self.lambda_lu[i], gamma)
- self.nn_params.forward_pass(
tf.multiply(self.lambda_quad[i + 1], delta),
i,
is_transpose=True,
)
)
else:
h_beta_rows[i] = (
h_beta_rows[i]
+ tf.multiply(self.lambda_quad[i] + self.lambda_lu[i], gamma)
- self.nn_params.forward_pass(
tf.multiply(self.lambda_quad[i + 1], delta),
i,
is_transpose=True,
)
)
new_row = tf.multiply(
self.lambda_quad[i + 1] + self.lambda_lu[i + 1], delta
) - tf.multiply(
self.lambda_quad[i + 1], self.nn_params.forward_pass(gamma, i)
)
h_beta_rows.append(new_row)
# Last boundary case
h_beta_rows[self.nn_params.num_hidden_layers] = h_beta_rows[
self.nn_params.num_hidden_layers
] + tf.multiply(
(
self.lambda_quad[self.nn_params.num_hidden_layers]
+ self.lambda_lu[self.nn_params.num_hidden_layers]
),
delta,
)
h_beta = tf.concat(h_beta_rows, axis=0)
return tf.cast(h_beta, dtype)
def get_psd_product(self, vector, dtype=None):
"""Function that provides matrix product interface with PSD matrix.
Args:
vector: the vector to be multiplied with matrix M
Returns:
result_product: Matrix product of M and vector
"""
# For convenience, think of x as [\alpha, \beta]
if dtype is None:
dtype = self.nn_dtype
vector = tf.cast(vector, self.nn_dtype)
alpha = tf.reshape(vector[0], shape=[1, 1])
beta = vector[1:]
# Computing the product of matrix_h with beta part of vector
# At first layer, h is simply diagonal
h_beta = self.get_h_product(beta)
# Constructing final result using vector_g
result = tf.concat(
[
alpha * self.nu + tf.reduce_sum(tf.multiply(beta, self.vector_g)),
tf.multiply(alpha, self.vector_g) + h_beta,
],
axis=0,
)
return tf.cast(result, dtype)
def get_full_psd_matrix(self):
"""Function that returns the tf graph corresponding to the entire matrix M.
Returns:
matrix_h: unrolled version of tf matrix corresponding to H
matrix_m: unrolled tf matrix corresponding to M
"""
if self.matrix_m is not None:
return self.matrix_h, self.matrix_m
# Computing the matrix term
h_columns = []
for i in range(self.nn_params.num_hidden_layers + 1):
current_col_elems = []
for j in range(i):
current_col_elems.append(
tf.zeros([self.nn_params.sizes[j], self.nn_params.sizes[i]])
)
# For the first layer, there is no relu constraint
if i == 0:
current_col_elems.append(utils.diag(self.lambda_lu[i]))
else:
current_col_elems.append(
utils.diag(self.lambda_lu[i] + self.lambda_quad[i])
)
if i < self.nn_params.num_hidden_layers:
current_col_elems.append(
tf.matmul(
utils.diag(-1 * self.lambda_quad[i + 1]),
self.nn_params.weights[i],
)
)
for j in range(i + 2, self.nn_params.num_hidden_layers + 1):
current_col_elems.append(
tf.zeros([self.nn_params.sizes[j], self.nn_params.sizes[i]])
)
current_column = tf.concat(current_col_elems, 0)
h_columns.append(current_column)
self.matrix_h = tf.concat(h_columns, 1)
self.matrix_h = self.matrix_h + tf.transpose(self.matrix_h)
self.matrix_m = tf.concat(
[
tf.concat(
[tf.reshape(self.nu, (1, 1)), tf.transpose(self.vector_g)], axis=1
),
tf.concat([self.vector_g, self.matrix_h], axis=1),
],
axis=0,
)
return self.matrix_h, self.matrix_m
def make_m_psd(self, original_nu, feed_dictionary):
"""Run binary search to find a value for nu that makes M PSD
Args:
original_nu: starting value of nu to do binary search on
feed_dictionary: dictionary of updated lambda variables to feed into M
Returns:
new_nu: new value of nu
"""
feed_dict = feed_dictionary.copy()
_, min_eig_val_m = self.get_lanczos_eig(compute_m=True, feed_dict=feed_dict)
lower_nu = original_nu
upper_nu = original_nu
num_iter = 0
# Find an upper bound on nu
while min_eig_val_m - TOL < 0 and num_iter < (MAX_BINARY_SEARCH_ITER / 2):
num_iter += 1
upper_nu *= NU_UPDATE_CONSTANT
feed_dict.update({self.nu: upper_nu})
_, min_eig_val_m = self.get_lanczos_eig(compute_m=True, feed_dict=feed_dict)
final_nu = upper_nu
# Perform binary search to find best value of nu
while lower_nu <= upper_nu and num_iter < MAX_BINARY_SEARCH_ITER:
num_iter += 1
mid_nu = (lower_nu + upper_nu) / 2
feed_dict.update({self.nu: mid_nu})
_, min_eig_val_m = self.get_lanczos_eig(compute_m=True, feed_dict=feed_dict)
if min_eig_val_m - TOL < 0:
lower_nu = mid_nu
else:
upper_nu = mid_nu
final_nu = upper_nu
return final_nu
def get_lanczos_eig(self, compute_m=True, feed_dict=None):
"""Computes the min eigen value and corresponding vector of matrix M or H
using the Lanczos algorithm.
Args:
compute_m: boolean to determine whether we should compute eig val/vec
for M or for H. True for M; False for H.
feed_dict: dictionary mapping from TF placeholders to values (optional)
Returns:
min_eig_vec: Corresponding eigen vector to min eig val
eig_val: Minimum eigen value
"""
if compute_m:
min_eig, min_vec = self.sess.run(
[self.m_min_eig, self.m_min_vec], feed_dict=feed_dict
)
else:
min_eig, min_vec = self.sess.run(
[self.h_min_eig, self.h_min_vec], feed_dict=feed_dict
)
return min_vec, min_eig
def compute_certificate(self, current_step, feed_dictionary):
"""Function to compute the certificate based either current value
or dual variables loaded from dual folder"""
feed_dict = feed_dictionary.copy()
nu = feed_dict[self.nu]
second_term = self.make_m_psd(nu, feed_dict)
tf.logging.info("Nu after modifying: " + str(second_term))
feed_dict.update({self.nu: second_term})
computed_certificate = self.sess.run(
self.unconstrained_objective, feed_dict=feed_dict
)
tf.logging.info(
"Inner step: %d, current value of certificate: %f",
current_step,
computed_certificate,
)
# Sometimes due to either overflow or instability in inverses,
# the returned certificate is large and negative -- keeping a check
if LOWER_CERT_BOUND < computed_certificate < 0:
_, min_eig_val_m = self.get_lanczos_eig(feed_dict=feed_dict)
tf.logging.info("min eig val from lanczos: " + str(min_eig_val_m))
input_vector_m = tf.placeholder(
tf.float32, shape=(self.matrix_m_dimension, 1)
)
output_vector_m = self.get_psd_product(input_vector_m)
def np_vector_prod_fn_m(np_vector):
np_vector = np.reshape(np_vector, [-1, 1])
feed_dict.update({input_vector_m: np_vector})
output_np_vector = self.sess.run(output_vector_m, feed_dict=feed_dict)
return output_np_vector
linear_operator_m = LinearOperator(
(self.matrix_m_dimension, self.matrix_m_dimension),
matvec=np_vector_prod_fn_m,
)
# Performing shift invert scipy operation when eig val estimate is available
min_eig_val_m_scipy, _ = eigs(linear_operator_m, k=1, which="SR", tol=TOL)
tf.logging.info("min eig val m from scipy: " + str(min_eig_val_m_scipy))
if min_eig_val_m - TOL > 0:
tf.logging.info("Found certificate of robustness!")
return True
return False
================================================
FILE: cleverhans/experimental/certification/nn.py
================================================
"""This file defines the neural network class, where a network is reinitialized from configuration files.
The class also has a forward propagation method.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import json
import numpy as np
import tensorflow as tf
class NeuralNetwork(object):
"""NeuralNetwork is a class that interfaces the verification code with
the neural net parameters (weights).
"""
def __init__(
self,
net_weights,
net_biases,
net_layer_types,
input_shape=None,
cnn_params=None,
):
"""Function to initialize NeuralNetParams class.
Args:
net_weights: list of numpy matrices of weights of each layer
[convention: x[i+1] = W[i] x[i]
net_biases: list of numpy arrays of biases of each layer
net_layer_types: type of each layer ['ff' or 'ff_relu' or 'ff_conv' or
'ff_conv_relu']
'ff': Simple feedforward layer with no activations
'ff_relu': Simple feedforward layer with ReLU activations
'ff_conv': Convolution layer with no activation
'ff_conv_relu': Convolution layer with ReLU activation
input_shape: [num_rows, num_columns, num_channels] at the input layer
cnn_params: list of dictionaries containing stride and padding for
each layer
Raises:
ValueError: the input lists of net params are not of the same length
"""
if (len(net_weights) != len(net_biases)) or len(net_biases) != len(
net_layer_types
):
raise ValueError("Inputs of net params are not of same length ....")
if net_layer_types[len(net_layer_types) - 1] != "ff":
raise ValueError("Final layer is not linear")
self.num_hidden_layers = len(net_weights) - 1
self.weights = []
self.biases = []
self.layer_types = []
self.sizes = []
self.input_shapes = []
self.output_shapes = []
self.has_conv = False
if input_shape is not None:
current_num_rows = input_shape[0]
current_num_columns = input_shape[1]
current_num_channels = input_shape[2]
self.cnn_params = cnn_params
# Setting the sizes of the layers of the network
# sizes[i] contains the size of x_i
for i in range(self.num_hidden_layers):
shape = np.shape(net_weights[i])
self.weights.append(tf.convert_to_tensor(net_weights[i], dtype=tf.float32))
self.layer_types.append(net_layer_types[i])
if self.layer_types[i] in {"ff", "ff_relu"}:
self.sizes.append(int(shape[1]))
# For feedforward networks, no unraveling the bias terms
small_bias = tf.convert_to_tensor(net_biases[i], dtype=tf.float32)
self.biases.append(tf.reshape(small_bias, [-1, 1]))
# Assumes that x^{i+1} = W_i x^i
self.input_shapes.append([int(shape[1]), 1])
self.output_shapes.append([int(shape[0]), 1])
# Convolution type
else:
self.has_conv = True
num_filters = shape[3]
self.input_shapes.append(
[1, current_num_rows, current_num_columns, current_num_channels]
)
self.sizes.append(
current_num_rows * current_num_columns * current_num_channels
)
current_num_channels = num_filters
# For propagating across multiple conv layers
if self.cnn_params[i]["padding"] == "SAME":
current_num_rows = int(
current_num_rows / self.cnn_params[i]["stride"]
)
current_num_columns = int(
current_num_columns / self.cnn_params[i]["stride"]
)
self.output_shapes.append(
[1, current_num_rows, current_num_columns, current_num_channels]
)
# For conv networks, unraveling the bias terms
small_bias = tf.convert_to_tensor(net_biases[i], dtype=tf.float32)
large_bias = tf.tile(
tf.reshape(small_bias, [-1, 1]),
[current_num_rows * current_num_columns, 1],
)
self.biases.append(large_bias)
# Last layer shape: always ff
if self.has_conv:
final_dim = int(np.shape(net_weights[self.num_hidden_layers])[1])
self.input_shapes.append([final_dim, 1])
else:
final_dim = int(np.shape(net_weights[self.num_hidden_layers - 1])[0])
self.sizes.append(final_dim)
self.final_weights = tf.convert_to_tensor(
net_weights[self.num_hidden_layers], dtype=tf.float32
)
self.final_bias = tf.convert_to_tensor(
net_biases[self.num_hidden_layers], dtype=tf.float32
)
def forward_pass(self, vector, layer_index, is_transpose=False, is_abs=False):
"""Performs forward pass through the layer weights at layer_index.
Args:
vector: vector that has to be passed through in forward pass
layer_index: index of the layer
is_transpose: whether the weights of the layer have to be transposed
is_abs: whether to take the absolute value of the weights
Returns:
tensor that corresponds to the forward pass through the layer
Raises:
ValueError: if the layer_index is negative or more than num hidden layers
"""
if layer_index < 0 or layer_index > self.num_hidden_layers:
raise ValueError("Invalid layer index")
layer_type = self.layer_types[layer_index]
weight = self.weights[layer_index]
if is_abs:
weight = tf.abs(weight)
if is_transpose:
vector = tf.reshape(vector, self.output_shapes[layer_index])
else:
vector = tf.reshape(vector, self.input_shapes[layer_index])
if layer_type in {"ff", "ff_relu"}:
if is_transpose:
weight = tf.transpose(weight)
return_vector = tf.matmul(weight, vector)
elif layer_type in {"conv", "conv_relu"}:
if is_transpose:
return_vector = tf.nn.conv2d_transpose(
vector,
weight,
output_shape=self.input_shapes[layer_index],
strides=[
1,
self.cnn_params[layer_index]["stride"],
self.cnn_params[layer_index]["stride"],
1,
],
padding=self.cnn_params[layer_index]["padding"],
)
else:
return_vector = tf.nn.conv2d(
vector,
weight,
strides=[
1,
self.cnn_params[layer_index]["stride"],
self.cnn_params[layer_index]["stride"],
1,
],
padding=self.cnn_params[layer_index]["padding"],
)
else:
raise NotImplementedError("Unsupported layer type: {0}".format(layer_type))
if is_transpose:
return tf.reshape(return_vector, (self.sizes[layer_index], 1))
return tf.reshape(return_vector, (self.sizes[layer_index + 1], 1))
def load_network_from_checkpoint(checkpoint, model_json, input_shape=None):
"""Function to read the weights from checkpoint based on json description.
Args:
checkpoint: tensorflow checkpoint with trained model to
verify
model_json: path of json file with model description of
the network list of dictionary items for each layer
containing 'type', 'weight_var', 'bias_var' and
'is_transpose' 'type'is one of {'ff', 'ff_relu' or
'conv'}; 'weight_var' is the name of tf variable for
weights of layer i; 'bias_var' is the name of tf
variable for bias of layer i; 'is_transpose' is set to
True if the weights have to be transposed as per
convention Note that last layer is always feedforward
net_weights: list of numpy matrices of weights of each layer
convention: x[i+1] = W[i] x[i]
net_biases: list of numpy arrays of biases of each layer
net_layer_types: type of each layer ['ff' or 'ff_relu' or 'ff_conv'
or 'ff_conv_relu']
'ff': Simple feedforward layer with no activations
'ff_relu': Simple feedforward layer with ReLU activations
'ff_conv': Convolution layer with no activation
'ff_conv_relu': Convolution layer with ReLU activation
Raises:
ValueError: If layer_types are invalid or variable names
not found in checkpoint
"""
# Load checkpoint
reader = tf.train.load_checkpoint(checkpoint)
variable_map = reader.get_variable_to_shape_map()
checkpoint_variable_names = variable_map.keys()
# Parse JSON file for names
with tf.gfile.Open(model_json) as f:
list_model_var = json.load(f)
net_layer_types = []
net_weights = []
net_biases = []
cnn_params = []
# Checking validity of the input and adding to list
for layer_model_var in list_model_var:
if layer_model_var["type"] not in {"ff", "ff_relu", "conv"}:
raise ValueError("Invalid layer type in description")
if (
layer_model_var["weight_var"] not in checkpoint_variable_names
or layer_model_var["bias_var"] not in checkpoint_variable_names
):
raise ValueError("Variable names not found in checkpoint")
net_layer_types.append(layer_model_var["type"])
layer_weight = reader.get_tensor(layer_model_var["weight_var"])
layer_bias = reader.get_tensor(layer_model_var["bias_var"])
# TODO(aditirag): is there a way to automatically check when to transpose
# We want weights W such that x^{i+1} = W^i x^i + b^i
# Can think of a hack involving matching shapes but if shapes are equal
# it can be ambiguous
if layer_model_var["type"] in {"ff", "ff_relu"}:
layer_weight = np.transpose(layer_weight)
cnn_params.append(None)
if layer_model_var["type"] in {"conv"}:
if "stride" not in layer_model_var or "padding" not in layer_model_var:
raise ValueError("Please define stride and padding for conv layers.")
cnn_params.append(
{
"stride": layer_model_var["stride"],
"padding": layer_model_var["padding"],
}
)
net_weights.append(layer_weight)
net_biases.append(np.reshape(layer_bias, (np.size(layer_bias), 1)))
return NeuralNetwork(
net_weights, net_biases, net_layer_types, input_shape, cnn_params
)
================================================
FILE: cleverhans/experimental/certification/optimization.py
================================================
"""Code for setting up the optimization problem for certification."""
# pylint: disable=missing-docstring
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import json
import os
import numpy as np
from scipy.sparse.linalg import eigs, LinearOperator
import tensorflow as tf
from tensorflow.contrib import autograph
from cleverhans.experimental.certification import utils
UPDATE_PARAM_CONSTANT = -0.1
# Tolerance value for eigenvalue computation
TOL = 1e-5
class Optimization(object):
"""Class that sets up and runs the optimization of dual_formulation"""
def __init__(self, dual_formulation_object, sess, optimization_params):
"""Initialize the class variables.
Args:
dual_formulation_object: Instance of DualFormulation that contains the
dual variables and objective
sess: tf session to be used to run
optimization_params: Dictionary with the following
eig_num_iter - Number of iterations to run for computing minimum eigen
value
eig_learning_rate - Learning rate for minimum eigen value iterations
init_smooth - Starting value of the smoothness parameter (typically
around 0.001)
smooth_decay - The factor by which to decay after every outer loop epoch
optimizer - one of gd, adam, momentum or adagrad
eig_type - The method to compute eigenvalues (TF or SCIPY)
"""
self.sess = sess
self.dual_object = dual_formulation_object
self.params = optimization_params
self.penalty_placeholder = tf.placeholder(tf.float32, shape=[])
# The dimensionality of matrix M is the sum of sizes of all layers + 1
# The + 1 comes due to a row and column of M representing the linear terms
self.eig_init_vec_placeholder = tf.placeholder(
tf.float32, shape=[1 + self.dual_object.dual_index[-1], 1]
)
self.smooth_placeholder = tf.placeholder(tf.float32, shape=[])
self.eig_num_iter_placeholder = tf.placeholder(tf.int32, shape=[])
self.current_eig_val_estimate = None
# Create graph for optimization
self.prepare_for_optimization()
def tf_min_eig_vec(self):
"""Function for min eigen vector using tf's full eigen decomposition."""
# Full eigen decomposition requires the explicit psd matrix M
_, matrix_m = self.dual_object.get_full_psd_matrix()
[eig_vals, eig_vectors] = tf.self_adjoint_eig(matrix_m)
index = tf.argmin(eig_vals)
return tf.reshape(eig_vectors[:, index], shape=[eig_vectors.shape[0].value, 1])
def tf_smooth_eig_vec(self):
"""Function that returns smoothed version of min eigen vector."""
_, matrix_m = self.dual_object.get_full_psd_matrix()
# Easier to think in terms of max so negating the matrix
[eig_vals, eig_vectors] = tf.self_adjoint_eig(-matrix_m)
exp_eig_vals = tf.exp(tf.divide(eig_vals, self.smooth_placeholder))
scaling_factor = tf.reduce_sum(exp_eig_vals)
# Multiplying each eig vector by exponential of corresponding eig value
# Scaling factor normalizes the vector to be unit norm
eig_vec_smooth = tf.divide(
tf.matmul(eig_vectors, tf.diag(tf.sqrt(exp_eig_vals))),
tf.sqrt(scaling_factor),
)
return tf.reshape(
tf.reduce_sum(eig_vec_smooth, axis=1),
shape=[eig_vec_smooth.shape[0].value, 1],
)
def get_min_eig_vec_proxy(self, use_tf_eig=False):
"""Computes the min eigen value and corresponding vector of matrix M.
Args:
use_tf_eig: Whether to use tf's default full eigen decomposition
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector
"""
if use_tf_eig:
# If smoothness parameter is too small, essentially no smoothing
# Just output the eigen vector corresponding to min
return tf.cond(
self.smooth_placeholder < 1e-8,
self.tf_min_eig_vec,
self.tf_smooth_eig_vec,
)
# Using autograph to automatically handle
# the control flow of minimum_eigen_vector
min_eigen_tf = autograph.to_graph(utils.minimum_eigen_vector)
def _vector_prod_fn(x):
return self.dual_object.get_psd_product(x)
estimated_eigen_vector = min_eigen_tf(
x=self.eig_init_vec_placeholder,
num_steps=self.eig_num_iter_placeholder,
learning_rate=self.params["eig_learning_rate"],
vector_prod_fn=_vector_prod_fn,
)
return estimated_eigen_vector
def get_scipy_eig_vec(self):
"""Computes scipy estimate of min eigenvalue for matrix M.
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector
"""
if not self.params["has_conv"]:
matrix_m = self.sess.run(self.dual_object.matrix_m)
min_eig_vec_val, estimated_eigen_vector = eigs(
matrix_m, k=1, which="SR", tol=1e-4
)
min_eig_vec_val = np.reshape(np.real(min_eig_vec_val), [1, 1])
return np.reshape(estimated_eigen_vector, [-1, 1]), min_eig_vec_val
else:
dim = self.dual_object.matrix_m_dimension
input_vector = tf.placeholder(tf.float32, shape=(dim, 1))
output_vector = self.dual_object.get_psd_product(input_vector)
def np_vector_prod_fn(np_vector):
np_vector = np.reshape(np_vector, [-1, 1])
output_np_vector = self.sess.run(
output_vector, feed_dict={input_vector: np_vector}
)
return output_np_vector
linear_operator = LinearOperator((dim, dim), matvec=np_vector_prod_fn)
# Performing shift invert scipy operation when eig val estimate is available
min_eig_vec_val, estimated_eigen_vector = eigs(
linear_operator, k=1, which="SR", tol=1e-4
)
min_eig_vec_val = np.reshape(np.real(min_eig_vec_val), [1, 1])
return np.reshape(estimated_eigen_vector, [-1, 1]), min_eig_vec_val
def prepare_for_optimization(self):
"""Create tensorflow op for running one step of descent."""
if self.params["eig_type"] == "TF":
self.eig_vec_estimate = self.get_min_eig_vec_proxy()
elif self.params["eig_type"] == "LZS":
self.eig_vec_estimate = self.dual_object.m_min_vec
else:
self.eig_vec_estimate = tf.placeholder(
tf.float32, shape=(self.dual_object.matrix_m_dimension, 1)
)
self.stopped_eig_vec_estimate = tf.stop_gradient(self.eig_vec_estimate)
# Eig value is v^\top M v, where v is eigen vector
self.eig_val_estimate = tf.matmul(
tf.transpose(self.stopped_eig_vec_estimate),
self.dual_object.get_psd_product(self.stopped_eig_vec_estimate),
)
# Penalizing negative of min eigen value because we want min eig value
# to be positive
self.total_objective = (
self.dual_object.unconstrained_objective
+ 0.5
* tf.square(
tf.maximum(-self.penalty_placeholder * self.eig_val_estimate, 0)
)
)
global_step = tf.Variable(0, trainable=False)
# Set up learning rate as a placeholder
self.learning_rate = tf.placeholder(tf.float32, shape=[])
# Set up the optimizer
if self.params["optimizer"] == "adam":
self.optimizer = tf.train.AdamOptimizer(learning_rate=self.learning_rate)
elif self.params["optimizer"] == "adagrad":
self.optimizer = tf.train.AdagradOptimizer(learning_rate=self.learning_rate)
elif self.params["optimizer"] == "momentum":
self.optimizer = tf.train.MomentumOptimizer(
learning_rate=self.learning_rate,
momentum=self.params["momentum_parameter"],
use_nesterov=True,
)
else:
self.optimizer = tf.train.GradientDescentOptimizer(
learning_rate=self.learning_rate
)
# Write out the projection step
self.train_step = self.optimizer.minimize(
self.total_objective, global_step=global_step
)
self.sess.run(tf.global_variables_initializer())
# Projecting the dual variables
proj_ops = []
for i in range(self.dual_object.nn_params.num_hidden_layers + 1):
# Lambda_pos is non negative for switch indices,
# Unconstrained for positive indices
# Zero for negative indices
proj_ops.append(
self.dual_object.lambda_pos[i].assign(
tf.multiply(
self.dual_object.positive_indices[i],
self.dual_object.lambda_pos[i],
)
+ tf.multiply(
self.dual_object.switch_indices[i],
tf.nn.relu(self.dual_object.lambda_pos[i]),
)
)
)
proj_ops.append(
self.dual_object.lambda_neg[i].assign(
tf.multiply(
self.dual_object.negative_indices[i],
self.dual_object.lambda_neg[i],
)
+ tf.multiply(
self.dual_object.switch_indices[i],
tf.nn.relu(self.dual_object.lambda_neg[i]),
)
)
)
# Lambda_quad is only non zero and positive for switch
proj_ops.append(
self.dual_object.lambda_quad[i].assign(
tf.multiply(
self.dual_object.switch_indices[i],
tf.nn.relu(self.dual_object.lambda_quad[i]),
)
)
)
# Lambda_lu is always non negative
proj_ops.append(
self.dual_object.lambda_lu[i].assign(
tf.nn.relu(self.dual_object.lambda_lu[i])
)
)
self.proj_step = tf.group(proj_ops)
# Create folder for saving stats if the folder is not None
if self.params.get("stats_folder") and not tf.gfile.IsDirectory(
self.params["stats_folder"]
):
tf.gfile.MkDir(self.params["stats_folder"])
def run_one_step(
self,
eig_init_vec_val,
eig_num_iter_val,
smooth_val,
penalty_val,
learning_rate_val,
):
"""Run one step of gradient descent for optimization.
Args:
eig_init_vec_val: Start value for eigen value computations
eig_num_iter_val: Number of iterations to run for eigen computations
smooth_val: Value of smoothness parameter
penalty_val: Value of penalty for the current step
learning_rate_val: Value of learning rate
Returns:
found_cert: True is negative certificate is found, False otherwise
"""
# Running step
step_feed_dict = {
self.eig_init_vec_placeholder: eig_init_vec_val,
self.eig_num_iter_placeholder: eig_num_iter_val,
self.smooth_placeholder: smooth_val,
self.penalty_placeholder: penalty_val,
self.learning_rate: learning_rate_val,
}
if self.params["eig_type"] == "SCIPY":
current_eig_vector, self.current_eig_val_estimate = self.get_scipy_eig_vec()
step_feed_dict.update({self.eig_vec_estimate: current_eig_vector})
elif self.params["eig_type"] == "LZS":
step_feed_dict.update(
{self.dual_object.m_min_vec_ph: self.dual_object.m_min_vec_estimate}
)
self.sess.run(self.train_step, feed_dict=step_feed_dict)
[
_,
self.dual_object.m_min_vec_estimate,
self.current_eig_val_estimate,
] = self.sess.run(
[self.proj_step, self.eig_vec_estimate, self.eig_val_estimate],
feed_dict=step_feed_dict,
)
if self.current_step % self.params["print_stats_steps"] == 0:
[
self.current_total_objective,
self.current_unconstrained_objective,
self.dual_object.m_min_vec_estimate,
self.current_eig_val_estimate,
self.current_nu,
] = self.sess.run(
[
self.total_objective,
self.dual_object.unconstrained_objective,
self.eig_vec_estimate,
self.eig_val_estimate,
self.dual_object.nu,
],
feed_dict=step_feed_dict,
)
stats = {
"total_objective": float(self.current_total_objective),
"unconstrained_objective": float(self.current_unconstrained_objective),
"min_eig_val_estimate": float(self.current_eig_val_estimate),
}
tf.logging.info(
"Current inner step: %d, optimization stats: %s",
self.current_step,
stats,
)
if self.params["stats_folder"] is not None:
stats = json.dumps(stats)
filename = os.path.join(
self.params["stats_folder"], str(self.current_step) + ".json"
)
with tf.gfile.Open(filename) as file_f:
file_f.write(stats)
# Project onto feasible set of dual variables
if (
self.current_step % self.params["projection_steps"] == 0
and self.current_unconstrained_objective < 0
):
nu = self.sess.run(self.dual_object.nu)
dual_feed_dict = {
self.dual_object.h_min_vec_ph: self.dual_object.h_min_vec_estimate
}
_, min_eig_val_h_lz = self.dual_object.get_lanczos_eig(
compute_m=False, feed_dict=dual_feed_dict
)
projected_dual_feed_dict = {
self.dual_object.projected_dual.nu: nu,
self.dual_object.projected_dual.min_eig_val_h: min_eig_val_h_lz,
}
if self.dual_object.projected_dual.compute_certificate(
self.current_step, projected_dual_feed_dict
):
return True
return False
def run_optimization(self):
"""Run the optimization, call run_one_step with suitable placeholders.
Returns:
True if certificate is found
False otherwise
"""
penalty_val = self.params["init_penalty"]
# Don't use smoothing initially - very inaccurate for large dimension
self.smooth_on = False
smooth_val = 0
learning_rate_val = self.params["init_learning_rate"]
self.current_outer_step = 1
while self.current_outer_step <= self.params["outer_num_steps"]:
tf.logging.info(
"Running outer step %d with penalty %f",
self.current_outer_step,
penalty_val,
)
# Running inner loop of optimization with current_smooth_val,
# current_penalty as smoothness parameters and penalty respectively
self.current_step = 0
# Run first step with random eig initialization and large number of steps
found_cert = self.run_one_step(
self.dual_object.m_min_vec_estimate,
self.params["large_eig_num_steps"],
smooth_val,
penalty_val,
learning_rate_val,
)
if found_cert:
return True
while self.current_step < self.params["inner_num_steps"]:
self.current_step = self.current_step + 1
found_cert = self.run_one_step(
self.dual_object.m_min_vec_estimate,
self.params["small_eig_num_steps"],
smooth_val,
penalty_val,
learning_rate_val,
)
if found_cert:
return True
# Update penalty only if it looks like current objective is optimizes
if self.current_total_objective < UPDATE_PARAM_CONSTANT:
penalty_val = penalty_val * self.params["beta"]
learning_rate_val = (
learning_rate_val * self.params["learning_rate_decay"]
)
else:
# To get more accurate gradient estimate
self.params["small_eig_num_steps"] = (
1.5 * self.params["small_eig_num_steps"]
)
# If eigen values seem small enough, turn on smoothing
# useful only when performing full eigen decomposition
if np.abs(self.current_eig_val_estimate) < 0.01:
smooth_val = self.params["smoothness_parameter"]
self.current_outer_step = self.current_outer_step + 1
return False
================================================
FILE: cleverhans/experimental/certification/tests/dual_formulation_test.py
================================================
"""Tests for cleverhans.experimental.certification.dual_formulation."""
# pylint: disable=missing-docstring
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
import numpy as np
import tensorflow as tf
from cleverhans.experimental.certification import dual_formulation
from cleverhans.experimental.certification import nn
class DualFormulationTest(unittest.TestCase):
def test_init(self):
# Function to test initialization of dual formulation class.
net_weights = [[[2, 2], [3, 3], [4, 4]], [[1, 1, 1], [-1, -1, -1]]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params1 = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
test_input = np.transpose(np.matrix([0, 0]))
true_class = 0
adv_class = 1
input_minval = 0
input_maxval = 0
epsilon = 0.1
three_dim_tensor = tf.random_uniform(shape=(3, 1), dtype=tf.float32)
two_dim_tensor = tf.random_uniform(shape=(2, 1), dtype=tf.float32)
scalar = tf.random_uniform(shape=(1, 1), dtype=tf.float32)
lambda_pos = [two_dim_tensor, three_dim_tensor]
lambda_neg = lambda_pos
lambda_quad = lambda_pos
lambda_lu = lambda_pos
nu = scalar
dual_var = {
"lambda_pos": lambda_pos,
"lambda_neg": lambda_neg,
"lambda_quad": lambda_quad,
"lambda_lu": lambda_lu,
"nu": nu,
}
with tf.Session() as sess:
dual_formulation_object = dual_formulation.DualFormulation(
sess,
dual_var,
nn_params1,
test_input,
true_class,
adv_class,
input_minval,
input_maxval,
epsilon,
)
self.assertIsNotNone(dual_formulation_object)
def test_set_differentiable_objective(self):
# Function to test the function that sets the differentiable objective.
net_weights = [[[2, 2], [3, 3], [4, 4]], [[1, 1, 1], [-1, -1, -1]]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params1 = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
test_input = np.transpose(np.matrix([0, 0]))
true_class = 0
adv_class = 1
input_minval = 0
input_maxval = 0
epsilon = 0.1
three_dim_tensor = tf.random_uniform(shape=(3, 1), dtype=tf.float32)
two_dim_tensor = tf.random_uniform(shape=(2, 1), dtype=tf.float32)
scalar = tf.random_uniform(shape=(1, 1), dtype=tf.float32)
lambda_pos = [two_dim_tensor, three_dim_tensor]
lambda_neg = lambda_pos
lambda_quad = lambda_pos
lambda_lu = lambda_pos
nu = scalar
dual_var = {
"lambda_pos": lambda_pos,
"lambda_neg": lambda_neg,
"lambda_quad": lambda_quad,
"lambda_lu": lambda_lu,
"nu": nu,
}
with tf.Session() as sess:
dual_formulation_object = dual_formulation.DualFormulation(
sess,
dual_var,
nn_params1,
test_input,
true_class,
adv_class,
input_minval,
input_maxval,
epsilon,
)
dual_formulation_object.set_differentiable_objective()
self.assertEqual(dual_formulation_object.scalar_f.shape.as_list(), [1])
self.assertEqual(
dual_formulation_object.unconstrained_objective.shape.as_list(), [1, 1]
)
self.assertEqual(dual_formulation_object.vector_g.shape.as_list(), [5, 1])
def test_get_full_psd_matrix(self):
# Function to test product with PSD matrix.
net_weights = [[[2, 2], [3, 3], [4, 4]], [[1, 1, 1], [-1, -1, -1]]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params1 = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
test_input = np.transpose(np.matrix([0, 0]))
true_class = 0
adv_class = 1
input_minval = 0
input_maxval = 0
epsilon = 0.1
three_dim_tensor = tf.random_uniform(shape=(3, 1), dtype=tf.float32)
two_dim_tensor = tf.random_uniform(shape=(2, 1), dtype=tf.float32)
scalar = tf.random_uniform(shape=(1, 1), dtype=tf.float32)
lambda_pos = [two_dim_tensor, three_dim_tensor]
lambda_neg = lambda_pos
lambda_quad = lambda_pos
lambda_lu = lambda_pos
nu = scalar
dual_var = {
"lambda_pos": lambda_pos,
"lambda_neg": lambda_neg,
"lambda_quad": lambda_quad,
"lambda_lu": lambda_lu,
"nu": nu,
}
with tf.Session() as sess:
dual_formulation_object = dual_formulation.DualFormulation(
sess,
dual_var,
nn_params1,
test_input,
true_class,
adv_class,
input_minval,
input_maxval,
epsilon,
)
matrix_h, matrix_m = dual_formulation_object.get_full_psd_matrix()
self.assertEqual(matrix_h.shape.as_list(), [5, 5])
self.assertEqual(matrix_m.shape.as_list(), [6, 6])
def test_get_psd_product(self):
# Function to test implicit product with PSD matrix.
net_weights = [[[2, 2], [3, 3], [4, 4]], [[1, 1, 1], [-1, -1, -1]]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params1 = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
test_input = np.transpose(np.matrix([0, 0]))
true_class = 0
adv_class = 1
input_minval = 0
input_maxval = 0
epsilon = 0.1
three_dim_tensor = tf.random_uniform(shape=(3, 1), dtype=tf.float32)
two_dim_tensor = tf.random_uniform(shape=(2, 1), dtype=tf.float32)
scalar = tf.random_uniform(shape=(1, 1), dtype=tf.float32)
lambda_pos = [two_dim_tensor, three_dim_tensor]
lambda_neg = lambda_pos
lambda_quad = lambda_pos
lambda_lu = lambda_pos
nu = scalar
dual_var = {
"lambda_pos": lambda_pos,
"lambda_neg": lambda_neg,
"lambda_quad": lambda_quad,
"lambda_lu": lambda_lu,
"nu": nu,
}
with tf.Session() as sess:
dual_formulation_object = dual_formulation.DualFormulation(
sess,
dual_var,
nn_params1,
test_input,
true_class,
adv_class,
input_minval,
input_maxval,
epsilon,
)
_, matrix_m = dual_formulation_object.get_full_psd_matrix()
# Testing if the values match
six_dim_tensor = tf.random_uniform(shape=(6, 1), dtype=tf.float32)
implicit_product = dual_formulation_object.get_psd_product(six_dim_tensor)
explicit_product = tf.matmul(matrix_m, six_dim_tensor)
[implicit_product_value, explicit_product_value] = sess.run(
[implicit_product, explicit_product]
)
self.assertEqual(
np.shape(implicit_product_value), np.shape(explicit_product_value)
)
self.assertLess(
np.max(np.abs(implicit_product_value - explicit_product_value)), 1e-5
)
if __name__ == "__main__":
unittest.main()
================================================
FILE: cleverhans/experimental/certification/tests/nn_test.py
================================================
"""Tests for cleverhans.experimental.certification.nn."""
# pylint: disable=missing-docstring
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
import numpy as np
import tensorflow as tf
from cleverhans.experimental.certification import nn
class NeuralNetworkTest(unittest.TestCase):
def test_init(self):
# Function to test initialization of NeuralNetParams object.
# Valid params
net_weights = [[[2, 2], [3, 3], [4, 4]], [1, 1, 1]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params1 = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
self.assertIsNotNone(nn_params1)
# Invalid params : list length
net_biases = [0]
with self.assertRaises(ValueError):
nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
# Invalid params: layer types
with self.assertRaises(ValueError):
net_layer_types = ["ff_relu", "ff_relu"]
nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
def test_forward_pass(self):
# Function to test forward pass of nn_params.
net_weights = [[[2, 2], [3, 3], [4, 4]], [1, 1, 1]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
input_vector = tf.random_uniform(shape=(2, 1), dtype=tf.float32)
output_vector = nn_params.forward_pass(input_vector, 0)
self.assertEqual(output_vector.shape.as_list(), [3, 1])
output_vector_2 = nn_params.forward_pass(input_vector, 0, is_abs=True)
self.assertEqual(output_vector_2.shape.as_list(), [3, 1])
input_vector_trans = tf.random_uniform(shape=(3, 1), dtype=tf.float32)
output_vector_3 = nn_params.forward_pass(
input_vector_trans, 0, is_transpose=True
)
self.assertEqual(output_vector_3.shape.as_list(), [2, 1])
if __name__ == "__main__":
unittest.main()
================================================
FILE: cleverhans/experimental/certification/tests/optimization_test.py
================================================
"""Tests for cleverhans.experimental.certification.optimization."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
from cleverhans.experimental.certification import dual_formulation
from cleverhans.experimental.certification import nn
from cleverhans.experimental.certification import optimization
class OptimizationTest(tf.test.TestCase):
# pylint: disable=missing-docstring
def prepare_dual_object(self):
# Function to prepare dual object to be used for testing optimization.
net_weights = [[[2, 2], [3, 3], [4, 4]], [[1, 1, 1], [-1, -1, -1]]]
net_biases = [
np.transpose(np.matrix([0, 0, 0])),
np.transpose(np.matrix([0, 0])),
]
net_layer_types = ["ff_relu", "ff"]
nn_params1 = nn.NeuralNetwork(net_weights, net_biases, net_layer_types)
test_input = np.transpose(np.matrix([0, 0]))
true_class = 0
adv_class = 1
input_minval = 0
input_maxval = 0
epsilon = 0.1
# Creating dual variables to use for optimization
lambda_pos = [
tf.get_variable(
"lambda_pos0",
initializer=np.random.uniform(0, 0.1, size=(2, 1)).astype(np.float32),
),
tf.get_variable(
"lambda_pos1",
initializer=np.random.uniform(0, 0.1, size=(3, 1)).astype(np.float32),
),
]
lambda_neg = [
tf.get_variable(
"lambda_neg0",
initializer=np.random.uniform(0, 0.1, size=(2, 1)).astype(np.float32),
),
tf.get_variable(
"lambda_neg1",
initializer=np.random.uniform(0, 0.1, size=(3, 1)).astype(np.float32),
),
]
lambda_quad = [
tf.get_variable(
"lambda_quad0",
initializer=np.random.uniform(0, 0.1, size=(2, 1)).astype(np.float32),
),
tf.get_variable(
"lambda_quad1",
initializer=np.random.uniform(0, 0.1, size=(3, 1)).astype(np.float32),
),
]
lambda_lu = [
tf.get_variable(
"lambda_lu0",
initializer=np.random.uniform(0, 0.1, size=(2, 1)).astype(np.float32),
),
tf.get_variable(
"lambda_lu1",
initializer=np.random.uniform(0, 0.1, size=(3, 1)).astype(np.float32),
),
]
nu = tf.reshape(
tf.get_variable("nu", initializer=200.0, dtype=tf.float32), shape=(1, 1)
)
dual_var = {
"lambda_pos": lambda_pos,
"lambda_neg": lambda_neg,
"lambda_quad": lambda_quad,
"lambda_lu": lambda_lu,
"nu": nu,
}
sess = tf.Session()
dual_formulation_object = dual_formulation.DualFormulation(
sess,
dual_var,
nn_params1,
test_input,
true_class,
adv_class,
input_minval,
input_maxval,
epsilon,
)
return sess, dual_formulation_object
def test_init(self):
""" Function to test initialization of OptimizationTest. """
sess, dual_formulation_object = self.prepare_dual_object()
dual_formulation_object.set_differentiable_objective()
sess.run(tf.global_variables_initializer())
optimization_params = {
"init_learning_rate": 0.1,
"learning_rate_decay": 0.9,
"eig_num_iter": 10,
"eig_learning_rate": 0.01,
"init_smooth": 0.5,
"smooth_decay": 0.9,
"inner_num_steps": 10,
"optimizer": "adam",
"momentum_parameter": 0.9,
"eig_type": "TF",
}
optimization_object = optimization.Optimization(
dual_formulation_object, sess, optimization_params
)
self.assertIsNotNone(optimization_object)
def test_get_min_eig_vec_proxy(self):
""" Function test computing min eigen value using matrix vector products."""
sess, dual_formulation_object = self.prepare_dual_object()
_, matrix_m = dual_formulation_object.get_full_psd_matrix()
optimization_params = {
"init_learning_rate": 0.1,
"learning_rate_decay": 0.9,
"eig_num_iter": 2000,
"eig_learning_rate": 0.01,
"init_smooth": 0.0,
"smooth_decay": 0.9,
"inner_num_steps": 10,
"optimizer": "adam",
"momentum_parameter": 0.9,
"eig_type": "TF",
}
sess.run(tf.global_variables_initializer())
optimization_object = optimization.Optimization(
dual_formulation_object, sess, optimization_params
)
eig_vec = optimization_object.get_min_eig_vec_proxy()
tf_eig_vec = optimization_object.get_min_eig_vec_proxy(use_tf_eig=True)
self.assertIsNotNone(eig_vec)
# Running the graphs and checking that minimum eigen value is correct
# ** No smoothing
tf_eig_vec_val, eig_vec_val, matrix_m_val = sess.run(
[tf_eig_vec, eig_vec, matrix_m],
feed_dict={
optimization_object.eig_init_vec_placeholder: np.random.rand(6, 1),
optimization_object.eig_num_iter_placeholder: 2000,
optimization_object.smooth_placeholder: 0.0,
},
)
# Eigen value corresponding to v is v^\top M v
eig_val = np.matmul(
np.transpose(eig_vec_val), np.matmul(matrix_m_val, eig_vec_val)
)
tf_eig_val = np.matmul(
np.transpose(tf_eig_vec_val), np.matmul(matrix_m_val, tf_eig_vec_val)
)
[np_eig_values, _] = np.linalg.eig(matrix_m_val)
self.assertLess(np.abs(np.min(np_eig_values) - eig_val), 1e-5)
self.assertLess(np.abs(np.min(np_eig_values) - tf_eig_val), 1e-5)
# Running the graphs and checking that minimum eigen value is correct
# **Smoothing
optimization_params["init_smooth"] = 0.0001
optimization_object = optimization.Optimization(
dual_formulation_object, sess, optimization_params
)
eig_vec = optimization_object.get_min_eig_vec_proxy()
tf_eig_vec = optimization_object.get_min_eig_vec_proxy(use_tf_eig=True)
tf_eig_vec_val, eig_vec_val, matrix_m_val = sess.run(
[tf_eig_vec, eig_vec, matrix_m],
feed_dict={
optimization_object.eig_init_vec_placeholder: np.random.rand(6, 1),
optimization_object.smooth_placeholder: 0.1,
optimization_object.eig_num_iter_placeholder: 2000,
},
)
# Eigen value corresponding to v is v^\top M v
eig_val = np.matmul(
np.transpose(eig_vec_val), np.matmul(matrix_m_val, eig_vec_val)
)
tf_eig_val = np.matmul(
np.transpose(tf_eig_vec_val), np.matmul(matrix_m_val, tf_eig_vec_val)
)
[np_eig_values, _] = np.linalg.eig(matrix_m_val)
self.assertLess(np.abs(np.min(np_eig_values) - eig_val), 1e-5)
# In general, smoothed version can be far off
self.assertLess(np.abs(np.min(np_eig_values) - tf_eig_val), 1e-1)
def test_optimization(self):
"""Function to test optimization."""
sess, dual_formulation_object = self.prepare_dual_object()
optimization_params = {
"init_penalty": 10000,
"large_eig_num_steps": 1000,
"small_eig_num_steps": 500,
"inner_num_steps": 10,
"outer_num_steps": 2,
"beta": 2,
"smoothness_parameter": 0.001,
"eig_learning_rate": 0.01,
"optimizer": "adam",
"init_learning_rate": 0.1,
"learning_rate_decay": 0.9,
"momentum_parameter": 0.9,
"print_stats_steps": 1,
"stats_folder": None,
"projection_steps": 200,
"eig_type": "TF",
}
sess.run(tf.global_variables_initializer())
optimization_object = optimization.Optimization(
dual_formulation_object, sess, optimization_params
)
is_cert_found = optimization_object.run_optimization()
self.assertFalse(is_cert_found)
if __name__ == "__main__":
tf.test.main()
================================================
FILE: cleverhans/experimental/certification/tests/utils_test.py
================================================
"""Tests for cleverhans.experimental.certification.utils."""
# pylint: disable=missing-docstring
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from scipy.sparse.linalg import eigs
import tensorflow as tf
from tensorflow.contrib import autograph
from cleverhans.experimental.certification import utils
MATRIX_DIMENTION = 100
NUM_LZS_ITERATIONS = 100
NUM_RANDOM_MATRICES = 10
class UtilsTest(tf.test.TestCase):
def test_minimum_eigen_vector(self):
matrix = np.array([[1.0, 2.0], [2.0, 5.0]], dtype=np.float32)
initial_vec = np.array([[1.0], [-1.0]], dtype=np.float32)
def _vector_prod_fn(x):
return tf.matmul(matrix, x)
min_eigen_fn = autograph.to_graph(utils.minimum_eigen_vector)
x = tf.placeholder(tf.float32, shape=(2, 1))
min_eig_vec = min_eigen_fn(x, 10, 0.1, _vector_prod_fn)
with self.test_session() as sess:
v = sess.run(min_eig_vec, feed_dict={x: initial_vec})
if v.flatten()[0] < 0:
v = -v
np.testing.assert_almost_equal(v, [[0.9239], [-0.3827]], decimal=4)
def test_tf_lanczos_smallest_eigval(self):
tf_num_iter = tf.placeholder(dtype=tf.int32, shape=())
tf_matrix = tf.placeholder(dtype=tf.float32)
def _vector_prod_fn(x):
return tf.matmul(tf_matrix, tf.reshape(x, [-1, 1]))
min_eigen_fn = autograph.to_graph(utils.tf_lanczos_smallest_eigval)
init_vec_ph = tf.placeholder(shape=(MATRIX_DIMENTION, 1), dtype=tf.float32)
tf_eigval, tf_eigvec = min_eigen_fn(
_vector_prod_fn,
MATRIX_DIMENTION,
init_vec_ph,
tf_num_iter,
dtype=tf.float32,
)
eigvec = np.zeros((MATRIX_DIMENTION, 1), dtype=np.float32)
with self.test_session() as sess:
# run this test for a few random matrices
for _ in range(NUM_RANDOM_MATRICES):
matrix = np.random.random((MATRIX_DIMENTION, MATRIX_DIMENTION))
matrix = matrix + matrix.T # symmetrizing matrix
eigval, eigvec = sess.run(
[tf_eigval, tf_eigvec],
feed_dict={
tf_num_iter: NUM_LZS_ITERATIONS,
tf_matrix: matrix,
init_vec_ph: eigvec,
},
)
scipy_min_eigval, scipy_min_eigvec = eigs(matrix, k=1, which="SR")
scipy_min_eigval = np.real(scipy_min_eigval)
scipy_min_eigvec = np.real(scipy_min_eigvec)
scipy_min_eigvec = scipy_min_eigvec / np.linalg.norm(scipy_min_eigvec)
np.testing.assert_almost_equal(eigval, scipy_min_eigval, decimal=3)
np.testing.assert_almost_equal(np.linalg.norm(eigvec), 1.0, decimal=3)
abs_dot_prod = abs(np.dot(eigvec.flatten(), scipy_min_eigvec.flatten()))
np.testing.assert_almost_equal(abs_dot_prod, 1.0, decimal=3)
if __name__ == "__main__":
tf.test.main()
================================================
FILE: cleverhans/experimental/certification/utils.py
================================================
"""File containing some simple helper functions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
def diag(diag_elements):
"""Function to create tensorflow diagonal matrix with input diagonal entries.
Args:
diag_elements: tensor with diagonal elements
Returns:
tf matrix with diagonal entries as diag_elements
"""
return tf.diag(tf.reshape(diag_elements, [-1]))
def initialize_dual(
neural_net_params_object,
init_dual_file=None,
random_init_variance=0.01,
init_nu=200.0,
):
"""Function to initialize the dual variables of the class.
Args:
neural_net_params_object: Object with the neural net weights, biases
and types
init_dual_file: Path to file containing dual variables, if the path
is empty, perform random initialization
Expects numpy dictionary with
lambda_pos_0, lambda_pos_1, ..
lambda_neg_0, lambda_neg_1, ..
lambda_quad_0, lambda_quad_1, ..
lambda_lu_0, lambda_lu_1, ..
random_init_variance: variance for random initialization
init_nu: Value to initialize nu variable with
Returns:
dual_var: dual variables initialized appropriately.
"""
lambda_pos = []
lambda_neg = []
lambda_quad = []
lambda_lu = []
if init_dual_file is None:
for i in range(0, neural_net_params_object.num_hidden_layers + 1):
initializer = (
np.random.uniform(
0, random_init_variance, size=(neural_net_params_object.sizes[i], 1)
)
).astype(np.float32)
lambda_pos.append(
tf.get_variable(
"lambda_pos_" + str(i), initializer=initializer, dtype=tf.float32
)
)
initializer = (
np.random.uniform(
0, random_init_variance, size=(neural_net_params_object.sizes[i], 1)
)
).astype(np.float32)
lambda_neg.append(
tf.get_variable(
"lambda_neg_" + str(i), initializer=initializer, dtype=tf.float32
)
)
initializer = (
np.random.uniform(
0, random_init_variance, size=(neural_net_params_object.sizes[i], 1)
)
).astype(np.float32)
lambda_quad.append(
tf.get_variable(
"lambda_quad_" + str(i), initializer=initializer, dtype=tf.float32
)
)
initializer = (
np.random.uniform(
0, random_init_variance, size=(neural_net_params_object.sizes[i], 1)
)
).astype(np.float32)
lambda_lu.append(
tf.get_variable(
"lambda_lu_" + str(i), initializer=initializer, dtype=tf.float32
)
)
nu = tf.get_variable("nu", initializer=init_nu)
else:
# Loading from file
dual_var_init_val = np.load(init_dual_file).item()
for i in range(0, neural_net_params_object.num_hidden_layers + 1):
lambda_pos.append(
tf.get_variable(
"lambda_pos_" + str(i),
initializer=dual_var_init_val["lambda_pos"][i],
dtype=tf.float32,
)
)
lambda_neg.append(
tf.get_variable(
"lambda_neg_" + str(i),
initializer=dual_var_init_val["lambda_neg"][i],
dtype=tf.float32,
)
)
lambda_quad.append(
tf.get_variable(
"lambda_quad_" + str(i),
initializer=dual_var_init_val["lambda_quad"][i],
dtype=tf.float32,
)
)
lambda_lu.append(
tf.get_variable(
"lambda_lu_" + str(i),
initializer=dual_var_init_val["lambda_lu"][i],
dtype=tf.float32,
)
)
nu = tf.get_variable("nu", initializer=1.0 * dual_var_init_val["nu"])
dual_var = {
"lambda_pos": lambda_pos,
"lambda_neg": lambda_neg,
"lambda_quad": lambda_quad,
"lambda_lu": lambda_lu,
"nu": nu,
}
return dual_var
def eig_one_step(current_vector, learning_rate, vector_prod_fn):
"""Function that performs one step of gd (variant) for min eigen value.
Args:
current_vector: current estimate of the eigen vector with minimum eigen
value.
learning_rate: learning rate.
vector_prod_fn: function which returns product H*x, where H is a matrix for
which we computing eigenvector.
Returns:
updated vector after one step
"""
grad = 2 * vector_prod_fn(current_vector)
# Current objective = (1/2)*v^T (2*M*v); v = current_vector
# grad = 2*M*v
current_objective = tf.reshape(
tf.matmul(tf.transpose(current_vector), grad) / 2.0, shape=()
)
# Project the gradient into the tangent space of the constraint region.
# This way we do not waste time taking steps that try to change the
# norm of current_vector
grad = grad - current_vector * tf.matmul(tf.transpose(current_vector), grad)
grad_norm = tf.norm(grad)
grad_norm_sq = tf.square(grad_norm)
# Computing normalized gradient of unit norm
norm_grad = grad / grad_norm
# Computing directional second derivative (dsd)
# dsd = 2*g^T M g, where g is normalized gradient
directional_second_derivative = tf.reshape(
2 * tf.matmul(tf.transpose(norm_grad), vector_prod_fn(norm_grad)), shape=()
)
# Computing grad^\top M grad [useful to compute step size later]
# Just a rescaling of the directional_second_derivative (which uses
# normalized gradient
grad_m_grad = directional_second_derivative * grad_norm_sq / 2
# Directional_second_derivative/2 = objective when vector is norm_grad
# If this is smaller than current objective, simply return that
if directional_second_derivative / 2.0 < current_objective:
return norm_grad
# If curvature is positive, jump to the bottom of the bowl
if directional_second_derivative > 0.0:
step = -1.0 * grad_norm / directional_second_derivative
else:
# If the gradient is very small, do not move
if grad_norm_sq <= 1e-16:
step = 0.0
else:
# Make a heuristic guess of the step size
step = -2.0 * tf.reduce_sum(current_vector * grad) / grad_norm_sq
# Computing gain using the gradient and second derivative
gain = -(
2 * tf.reduce_sum(current_vector * grad) + (step * step) * grad_m_grad
)
# Fall back to pre-determined learning rate if no gain
if gain < 0.0:
step = -learning_rate * grad_norm
current_vector = current_vector + step * norm_grad
return tf.nn.l2_normalize(current_vector)
def minimum_eigen_vector(x, num_steps, learning_rate, vector_prod_fn):
"""Computes eigenvector which corresponds to minimum eigenvalue.
Args:
x: initial value of eigenvector.
num_steps: number of optimization steps.
learning_rate: learning rate.
vector_prod_fn: function which takes x and returns product H*x.
Returns:
approximate value of eigenvector.
This function finds approximate value of eigenvector of matrix H which
corresponds to smallest (by absolute value) eigenvalue of H.
It works by solving optimization problem x^{T}*H*x -> min.
"""
x = tf.nn.l2_normalize(x)
for _ in range(num_steps):
x = eig_one_step(x, learning_rate, vector_prod_fn)
return x
def tf_lanczos_smallest_eigval(
vector_prod_fn,
matrix_dim,
initial_vector,
num_iter=1000,
max_iter=1000,
collapse_tol=1e-9,
dtype=tf.float32,
):
"""Computes smallest eigenvector and eigenvalue using Lanczos in pure TF.
This function computes smallest eigenvector and eigenvalue of the matrix
which is implicitly specified by `vector_prod_fn`.
`vector_prod_fn` is a function which takes `x` and returns a product of matrix
in consideration and `x`.
Computation is done using Lanczos algorithm, see
https://en.wikipedia.org/wiki/Lanczos_algorithm#The_algorithm
Args:
vector_prod_fn: function which takes a vector as an input and returns
matrix vector product.
matrix_dim: dimentionality of the matrix.
initial_vector: guess vector to start the algorithm with
num_iter: user-defined number of iterations for the algorithm
max_iter: maximum number of iterations.
collapse_tol: tolerance to determine collapse of the Krylov subspace
dtype: type of data
Returns:
tuple of (eigenvalue, eigenvector) of smallest eigenvalue and corresponding
eigenvector.
"""
# alpha will store diagonal elements
alpha = tf.TensorArray(dtype, size=1, dynamic_size=True, element_shape=())
# beta will store off diagonal elements
beta = tf.TensorArray(dtype, size=0, dynamic_size=True, element_shape=())
# q will store Krylov space basis
q_vectors = tf.TensorArray(
dtype, size=1, dynamic_size=True, element_shape=(matrix_dim, 1)
)
# If start vector is all zeros, make it a random normal vector and run for max_iter
if tf.norm(initial_vector) < collapse_tol:
initial_vector = tf.random_normal(shape=(matrix_dim, 1), dtype=dtype)
num_iter = max_iter
w = initial_vector / tf.norm(initial_vector)
# Iteration 0 of Lanczos
q_vectors = q_vectors.write(0, w)
w_ = vector_prod_fn(w)
cur_alpha = tf.reduce_sum(w_ * w)
alpha = alpha.write(0, cur_alpha)
w_ = w_ - tf.scalar_mul(cur_alpha, w)
w_prev = w
w = w_
# Subsequent iterations of Lanczos
for i in tf.range(1, num_iter):
cur_beta = tf.norm(w)
if cur_beta < collapse_tol:
# return early if Krylov subspace collapsed
break
# cur_beta is larger than collapse_tol,
# so division will return finite result.
w = w / cur_beta
w_ = vector_prod_fn(w)
cur_alpha = tf.reduce_sum(w_ * w)
q_vectors = q_vectors.write(i, w)
alpha = alpha.write(i, cur_alpha)
beta = beta.write(i - 1, cur_beta)
w_ = w_ - tf.scalar_mul(cur_alpha, w) - tf.scalar_mul(cur_beta, w_prev)
w_prev = w
w = w_
alpha = alpha.stack()
beta = beta.stack()
q_vectors = tf.reshape(q_vectors.stack(), (-1, matrix_dim))
offdiag_submatrix = tf.linalg.diag(beta)
tridiag_matrix = (
tf.linalg.diag(alpha)
+ tf.pad(offdiag_submatrix, [[0, 1], [1, 0]])
+ tf.pad(offdiag_submatrix, [[1, 0], [0, 1]])
)
eigvals, eigvecs = tf.linalg.eigh(tridiag_matrix)
smallest_eigval = eigvals[0]
smallest_eigvec = tf.matmul(tf.reshape(eigvecs[:, 0], (1, -1)), q_vectors)
smallest_eigvec = smallest_eigvec / tf.norm(smallest_eigvec)
smallest_eigvec = tf.reshape(smallest_eigvec, (matrix_dim, 1))
return smallest_eigval, smallest_eigvec
================================================
FILE: cleverhans/generic/README.md
================================================
# Generic Code (framework independent)
This folder contains code that is framework independent (for example, it uses
the numpy library only or can handle support for all major deep learning
libraries).
================================================
FILE: cleverhans/generic/__init__.py
================================================
================================================
FILE: cleverhans/jax/__init__.py
================================================
================================================
FILE: cleverhans/jax/attacks/__init__.py
================================================
from cleverhans.jax.attacks.projected_gradient_descent import projected_gradient_descent
================================================
FILE: cleverhans/jax/attacks/fast_gradient_method.py
================================================
import jax.numpy as np
from jax import grad, vmap
from jax.nn import log_softmax as logsoftmax
from cleverhans.jax.utils import one_hot
def fast_gradient_method(
model_fn, x, eps, norm, clip_min=None, clip_max=None, y=None, targeted=False
):
"""
JAX implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param norm: Order of the norm (mimics NumPy). Possible values: np.inf or 2.
:param clip_min: (optional) float. Minimum float value for adversarial example components.
:param clip_max: (optional) float. Maximum float value for adversarial example components.
:param y: (optional) Tensor with one-hot true labels. If targeted is true, then provide the
target one-hot label. Otherwise, only provide this parameter if you'd like to use true
labels when crafting adversarial samples. Otherwise, model predictions are used
as labels to avoid the "label leaking" effect (explained in this paper:
https://arxiv.org/abs/1611.01236). Default is None. This argument does not have
to be a binary one-hot label (e.g., [0, 1, 0, 0]), it can be floating points values
that sum up to 1 (e.g., [0.05, 0.85, 0.05, 0.05]).
:param targeted: (optional) bool. Is the attack targeted or untargeted?
Untargeted, the default, will try to make the label incorrect.
Targeted will instead try to move in the direction of being more like y.
:return: a tensor for the adversarial example
"""
if norm not in [np.inf, 2]:
raise ValueError("Norm order must be either np.inf or 2.")
if y is None:
# Using model predictions as ground truth to avoid label leaking
x_labels = np.argmax(model_fn(x), 1)
y = one_hot(x_labels, 10)
def loss_adv(image, label):
pred = model_fn(image[None])
loss = -np.sum(logsoftmax(pred) * label)
if targeted:
loss = -loss
return loss
grads_fn = vmap(grad(loss_adv), in_axes=(0, 0), out_axes=0)
grads = grads_fn(x, y)
axis = list(range(1, len(grads.shape)))
avoid_zero_div = 1e-12
if norm == np.inf:
perturbation = eps * np.sign(grads)
elif norm == 1:
raise NotImplementedError("L_1 norm has not been implemented yet.")
elif norm == 2:
square = np.maximum(
avoid_zero_div, np.sum(np.square(grads), axis=axis, keepdims=True)
)
perturbation = grads / np.sqrt(square)
adv_x = x + perturbation
# If clipping is needed, reset all values outside of [clip_min, clip_max]
if (clip_min is not None) or (clip_max is not None):
# We don't currently support one-sided clipping
assert clip_min is not None and clip_max is not None
adv_x = np.clip(adv_x, a_min=clip_min, a_max=clip_max)
return adv_x
================================================
FILE: cleverhans/jax/attacks/projected_gradient_descent.py
================================================
import jax.numpy as np
from cleverhans.jax.attacks.fast_gradient_method import fast_gradient_method
from cleverhans.jax.utils import clip_eta, one_hot
def projected_gradient_descent(
model_fn,
x,
eps,
eps_iter,
nb_iter,
norm,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
rand_init=None,
rand_minmax=0.3,
):
"""
This class implements either the Basic Iterative Method
(Kurakin et al. 2016) when rand_init is set to 0. or the
Madry et al. (2017) method when rand_minmax is larger than 0.
Paper link (Kurakin et al. 2016): https://arxiv.org/pdf/1607.02533.pdf
Paper link (Madry et al. 2017): https://arxiv.org/pdf/1706.06083.pdf
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param eps_iter: step size for each attack iteration
:param nb_iter: Number of attack iterations.
:param norm: Order of the norm (mimics NumPy). Possible values: np.inf or 2.
:param clip_min: (optional) float. Minimum float value for adversarial example components.
:param clip_max: (optional) float. Maximum float value for adversarial example components.
:param y: (optional) Tensor with true labels. If targeted is true, then provide the
target label. Otherwise, only provide this parameter if you'd like to use true
labels when crafting adversarial samples. Otherwise, model predictions are used
as labels to avoid the "label leaking" effect (explained in this paper:
https://arxiv.org/abs/1611.01236). Default is None.
:param targeted: (optional) bool. Is the attack targeted or untargeted?
Untargeted, the default, will try to make the label incorrect.
Targeted will instead try to move in the direction of being more like y.
:return: a tensor for the adversarial example
"""
assert eps_iter <= eps, (eps_iter, eps)
if norm == 1:
raise NotImplementedError(
"It's not clear that FGM is a good inner loop"
" step for PGD when norm=1, because norm=1 FGM "
" changes only one pixel at a time. We need "
" to rigorously test a strong norm=1 PGD "
"before enabling this feature."
)
if norm not in [np.inf, 2]:
raise ValueError("Norm order must be either np.inf or 2.")
# Initialize loop variables
if rand_init:
rand_minmax = eps
eta = np.random.uniform(x.shape, -rand_minmax, rand_minmax)
else:
eta = np.zeros_like(x)
# Clip eta
eta = clip_eta(eta, norm, eps)
adv_x = x + eta
if clip_min is not None or clip_max is not None:
adv_x = np.clip(adv_x, a_min=clip_min, a_max=clip_max)
if y is None:
# Using model predictions as ground truth to avoid label leaking
x_labels = np.argmax(model_fn(x), 1)
y = one_hot(x_labels, 10)
for _ in range(nb_iter):
adv_x = fast_gradient_method(
model_fn,
adv_x,
eps_iter,
norm,
clip_min=clip_min,
clip_max=clip_max,
y=y,
targeted=targeted,
)
# Clipping perturbation eta to norm norm ball
eta = adv_x - x
eta = clip_eta(eta, norm, eps)
adv_x = x + eta
# Redo the clipping.
# FGM already did it, but subtracting and re-adding eta can add some
# small numerical error.
if clip_min is not None or clip_max is not None:
adv_x = np.clip(adv_x, a_min=clip_min, a_max=clip_max)
return adv_x
================================================
FILE: cleverhans/jax/utils.py
================================================
import jax.numpy as np
def one_hot(x, k, dtype=np.float32):
"""Create a one-hot encoding of x of size k."""
return np.array(x[:, None] == np.arange(k), dtype)
def partial_flatten(x):
"""Flatten all but the first dimension of an ndarray."""
return np.reshape(x, (x.shape[0], -1))
def clip_eta(eta, norm, eps):
"""
Helper function to clip the perturbation to epsilon norm ball.
:param eta: A tensor with the current perturbation.
:param norm: Order of the norm (mimics Numpy).
Possible values: np.inf or 2.
:param eps: Epsilon, bound of the perturbation.
"""
# Clipping perturbation eta to self.norm norm ball
if norm not in [np.inf, 2]:
raise ValueError("norm must be np.inf or 2.")
axis = list(range(1, len(eta.shape)))
avoid_zero_div = 1e-12
if norm == np.inf:
eta = np.clip(eta, a_min=-eps, a_max=eps)
elif norm == 2:
# avoid_zero_div must go inside sqrt to avoid a divide by zero in the gradient through this operation
norm = np.sqrt(
np.maximum(avoid_zero_div, np.sum(np.square(eta), axis=axis, keepdims=True))
)
# We must *clip* to within the norm ball, not *normalize* onto the surface of the ball
factor = np.minimum(1.0, np.divide(eps, norm))
eta = eta * factor
return eta
================================================
FILE: cleverhans/plot/__init__.py
================================================
"""
Plotting and visualization
"""
================================================
FILE: cleverhans/plot/image.py
================================================
"""
Functionality for displaying or saving images.
"""
from tempfile import mkstemp
import os
import platform
import numpy as np
from PIL import Image
from cleverhans.utils import shell_call
def show(ndarray, min_val=None, max_val=None):
"""
Display an image.
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of the common ranges:
[0, 1], [-1, 1], [0, 255]
This can be ambiguous, so it is better to specify if known.
"""
# Create a temporary file with the suffix '.png'.
fd, path = mkstemp(suffix=".png")
os.close(fd)
save(path, ndarray, min_val, max_val)
shell_call(VIEWER_COMMAND + [path])
def save(path, ndarray, min_val=None, max_val=None):
"""
Save an image, represented as an ndarray, to the filesystem
:param path: string, filepath
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of the common ranges:
[0, 1], [-1, 1], [0, 255]
This can be ambiguous, so it is better to specify if known.
"""
as_pil(ndarray, min_val, max_val).save(path)
def as_pil(ndarray, min_val=None, max_val=None):
"""
Converts an ndarray to a PIL image.
:param ndarray: The numpy ndarray to convert
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of the common ranges:
[0, 1], [-1, 1], [0, 255]
This can be ambiguous, so it is better to specify if known.
"""
assert isinstance(ndarray, np.ndarray)
# rows x cols for grayscale image
# rows x cols x channels for color
assert ndarray.ndim in [2, 3]
if ndarray.ndim == 3:
channels = ndarray.shape[2]
# grayscale or RGB
assert channels in [1, 3]
actual_min = ndarray.min()
actual_max = ndarray.max()
if min_val is not None:
assert actual_min >= min_val
assert actual_max <= max_val
if np.issubdtype(ndarray.dtype, np.floating):
if min_val is None:
if actual_min < -1.0:
raise ValueError("Unrecognized range")
if actual_min < 0:
min_val = -1.0
else:
min_val = 0.0
if max_val is None:
if actual_max > 255.0:
raise ValueError("Unrecognized range")
if actual_max > 1.0:
max_val = 255.0
else:
max_val = 1.0
ndarray = ndarray - min_val
value_range = max_val - min_val
ndarray *= 255.0 / value_range
ndarray = np.cast["uint8"](ndarray)
elif "int" in str(ndarray.dtype):
if min_val is not None:
assert min_val == 0
else:
assert actual_min >= 0.0
if max_val is not None:
assert max_val == 255
else:
assert actual_max <= 255.0
else:
raise ValueError("Unrecognized dtype")
out = Image.fromarray(ndarray)
return out
def make_grid(image_batch):
"""
Turns a batch of images into one big image.
:param image_batch: ndarray, shape (batch_size, rows, cols, channels)
:returns : a big image containing all `batch_size` images in a grid
"""
m, ir, ic, ch = image_batch.shape
pad = 3
padded = np.zeros((m, ir + pad * 2, ic + pad * 2, ch))
padded[:, pad:-pad, pad:-pad, :] = image_batch
m, ir, ic, ch = padded.shape
pr = int(np.sqrt(m))
pc = int(np.ceil(float(m) / pr))
extra_m = pr * pc
assert extra_m > m
padded = np.concatenate((padded, np.zeros((extra_m - m, ir, ic, ch))), axis=0)
row_content = np.split(padded, pr)
row_content = [np.split(content, pc) for content in row_content]
rows = [np.concatenate(content, axis=2) for content in row_content]
grid = np.concatenate(rows, axis=1)
assert grid.shape[0] == 1, grid.shape
grid = grid[0]
return grid
if platform.system() == "Darwin":
VIEWER_COMMAND = ["open", "-a", "Preview"]
else:
VIEWER_COMMAND = ["eog", "--new-instance"]
================================================
FILE: cleverhans/plot/pyplot_defaults.py
================================================
"""Defaults for pyplot
Import this file to set some default parameters for pyplot.
These are designed to make the plot look good in the context of a LaTeX
document.
If you have installed the Computer Modern fonts
( ftp://canopus.iacp.dvo.ru/pub/Font/cm_unicode/cm-unicode-0.6.3a-otf.tar.gz )
these defaults will use them, so that text in your pyplot figures will
match text in the rest of your document.
If you do not have those fonts installed, pyplot commands will still work.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import matplotlib
from matplotlib import pyplot
matplotlib.rcParams["text.latex.preamble"] = r"\usepackage{bm}"
matplotlib.rcParams["text.usetex"] = True
pyplot.rcParams["pdf.fonttype"] = 42
pyplot.rcParams["font.family"] = "serif"
pyplot.rcParams["font.serif"] = "CMU Serif"
pyplot.rcParams["font.size"] = 8
# Note: if you get an error, delete fontList.cache
================================================
FILE: cleverhans/plot/pyplot_image.py
================================================
"""
Functionality for showing images in pyplot.
See also cleverhans.plot.image for loading/saving image files, showing
images in 3rd party viewers, etc.
"""
import numpy as np
from six.moves import range
def pair_visual(original, adversarial, figure=None):
"""
This function displays two images: the original and the adversarial sample
:param original: the original input
:param adversarial: the input after perturbations have been applied
:param figure: if we've already displayed images, use the same plot
:return: the matplot figure to reuse for future samples
"""
import matplotlib.pyplot as plt
# Squeeze the image to remove single-dimensional entries from array shape
original = np.squeeze(original)
adversarial = np.squeeze(adversarial)
# Ensure our inputs are of proper shape
assert len(original.shape) == 2 or len(original.shape) == 3
# To avoid creating figures per input sample, reuse the sample plot
if figure is None:
plt.ion()
figure = plt.figure()
figure.canvas.set_window_title("Cleverhans: Pair Visualization")
# Add the images to the plot
perturbations = adversarial - original
for index, image in enumerate((original, perturbations, adversarial)):
figure.add_subplot(1, 3, index + 1)
plt.axis("off")
# If the image is 2D, then we have 1 color channel
if len(image.shape) == 2:
plt.imshow(image, cmap="gray")
else:
plt.imshow(image)
# Give the plot some time to update
plt.pause(0.01)
# Draw the plot and return
plt.show()
return figure
def grid_visual(data):
"""
This function displays a grid of images to show full misclassification
:param data: grid data of the form;
[nb_classes : nb_classes : img_rows : img_cols : nb_channels]
:return: if necessary, the matplot figure to reuse
"""
import matplotlib.pyplot as plt
# Ensure interactive mode is disabled and initialize our graph
plt.ioff()
figure = plt.figure()
figure.canvas.set_window_title("Cleverhans: Grid Visualization")
# Add the images to the plot
num_cols = data.shape[0]
num_rows = data.shape[1]
num_channels = data.shape[4]
for y in range(num_rows):
for x in range(num_cols):
figure.add_subplot(num_rows, num_cols, (x + 1) + (y * num_cols))
plt.axis("off")
if num_channels == 1:
plt.imshow(data[x, y, :, :, 0], cmap="gray")
else:
plt.imshow(data[x, y, :, :, :])
# Draw the plot and return
plt.show()
return figure
def get_logits_over_interval(
sess, model, x_data, fgsm_params, min_epsilon=-10.0, max_epsilon=10.0, num_points=21
):
"""Get logits when the input is perturbed in an interval in adv direction.
Args:
sess: Tf session
model: Model for which we wish to get logits.
x_data: Numpy array corresponding to single data.
point of shape [height, width, channels].
fgsm_params: Parameters for generating adversarial examples.
min_epsilon: Minimum value of epsilon over the interval.
max_epsilon: Maximum value of epsilon over the interval.
num_points: Number of points used to interpolate.
Returns:
Numpy array containing logits.
Raises:
ValueError if min_epsilon is larger than max_epsilon.
"""
# Get the height, width and number of channels
height = x_data.shape[0]
width = x_data.shape[1]
channels = x_data.shape[2]
x_data = np.expand_dims(x_data, axis=0)
import tensorflow as tf
from cleverhans.attacks import FastGradientMethod
# Define the data placeholder
x = tf.placeholder(dtype=tf.float32, shape=[1, height, width, channels], name="x")
# Define adv_x
fgsm = FastGradientMethod(model, sess=sess)
adv_x = fgsm.generate(x, **fgsm_params)
if min_epsilon > max_epsilon:
raise ValueError("Minimum epsilon is less than maximum epsilon")
eta = tf.nn.l2_normalize(adv_x - x, dim=0)
epsilon = tf.reshape(
tf.lin_space(float(min_epsilon), float(max_epsilon), num_points),
(num_points, 1, 1, 1),
)
lin_batch = x + epsilon * eta
logits = model.get_logits(lin_batch)
with sess.as_default():
log_prob_adv_array = sess.run(logits, feed_dict={x: x_data})
return log_prob_adv_array
def linear_extrapolation_plot(
log_prob_adv_array, y, file_name, min_epsilon=-10, max_epsilon=10, num_points=21
):
"""Generate linear extrapolation plot.
Args:
log_prob_adv_array: Numpy array containing log probabilities
y: Tf placeholder for the labels
file_name: Plot filename
min_epsilon: Minimum value of epsilon over the interval
max_epsilon: Maximum value of epsilon over the interval
num_points: Number of points used to interpolate
"""
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
figure = plt.figure()
figure.canvas.set_window_title("Cleverhans: Linear Extrapolation Plot")
correct_idx = np.argmax(y, axis=0)
fig = plt.figure()
plt.xlabel("Epsilon")
plt.ylabel("Logits")
x_axis = np.linspace(min_epsilon, max_epsilon, num_points)
plt.xlim(min_epsilon - 1, max_epsilon + 1)
for i in range(y.shape[0]):
if i == correct_idx:
ls = "-"
linewidth = 5
else:
ls = "--"
linewidth = 2
plt.plot(
x_axis,
log_prob_adv_array[:, i],
ls=ls,
linewidth=linewidth,
label="{}".format(i),
)
plt.legend(loc="best", fontsize=14)
plt.show()
fig.savefig(file_name)
plt.clf()
return figure
================================================
FILE: cleverhans/plot/save_pdf.py
================================================
"""
The save_pdf function.
"""
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib import pyplot
def save_pdf(path):
"""
Saves a pdf of the current matplotlib figure.
:param path: str, filepath to save to
"""
pp = PdfPages(path)
pp.savefig(pyplot.gcf())
pp.close()
================================================
FILE: cleverhans/plot/success_fail.py
================================================
"""Functions for plotting succes-failure curves
Reference: https://openreview.net/forum?id=H1g0piA9tQ
"""
import warnings
import numpy as np
from matplotlib import pyplot
from cleverhans.serial import load
from cleverhans.utils import safe_zip
LINEWIDTH = 2
DEFAULT_SUCCESS_NAME = "clean"
# This must be a tuple or it is not safe to use as a param default
DEFAULT_FAIL_NAMES = ("mc", "bundled")
def plot_report_from_path(
path,
success_name=DEFAULT_SUCCESS_NAME,
fail_names=DEFAULT_FAIL_NAMES,
label=None,
is_max_confidence=True,
linewidth=LINEWIDTH,
plot_upper_bound=True,
):
"""
Plots a success-fail curve from a confidence report stored on disk,
:param path: string filepath for the stored report.
(Should be the output of make_confidence_report*.py)
:param success_name: The name (confidence report key) of the data that
should be used to measure success rate
:param fail_names: A list of names (confidence report keys) of the data
that should be used to measure failure rate.
*Only one of these keys will be plotted*. Each key will be tried in
order until one is found in the report. This is to support both the
output of `make_confidence_report` and `make_confidence_report_bundled`.
:param label: Optional string. Name to use for this curve in the legend.
:param is_max_confidence: bool.
If True, when measuring the failure rate, treat the data as the output
of a maximum confidence attack procedure.
This means that the attack is optimal (assuming the underlying optimizer
is good enough, *which is probably false*, so interpret the plot
accordingly) for thresholds >= .5 but for lower thresholds the observed
failure rate is a lower bound on the true worst failure rate and the
observed coverage is an upper bound (assuming good enough optimization)
on the true failure rate.
The plot thus draws the threshold >= .5 portion of the curve with a solid
line and the upper and lower bounds with a dashed line.
See https://openreview.net/forum?id=H1g0piA9tQ for details.
If False, the attack procedure is regarded as an ad hoc way of obtaining
a loose lower bound, and thus the whole curve is drawn with dashed lines.
:param linewidth: thickness of the line to draw
:param plot_upper_bound: include upper bound on error rate in plot
"""
report = load(path)
plot_report(
report,
success_name,
fail_names,
label,
is_max_confidence,
linewidth,
plot_upper_bound,
)
def plot_report(
report,
success_name,
fail_names,
label=None,
is_max_confidence=True,
linewidth=LINEWIDTH,
plot_upper_bound=True,
):
"""
Plot a success fail curve from a confidence report
:param report: A confidence report
(the type of object saved by make_confidence_report.py)
:param success_name: see plot_report_from_path
:param fail_names: see plot_report_from_path
:param label: see plot_report_from_path
:param is_max_confidence: see plot_report_from_path
:param linewidth: see plot_report_from_path
"""
(
fail_optimal,
success_optimal,
fail_lower_bound,
fail_upper_bound,
success_bounded,
) = make_curve(report, success_name, fail_names)
assert len(fail_lower_bound) == len(fail_upper_bound)
fail_optimal = np.array(fail_optimal)
fail_lower_bound = np.array(fail_lower_bound)
fail_upper_bound = np.array(fail_upper_bound)
if is_max_confidence:
(p,) = pyplot.plot(
fail_optimal, success_optimal, label=label, linewidth=linewidth
)
color = p.get_color()
pyplot.plot(fail_lower_bound, success_bounded, "--", color=color)
if plot_upper_bound:
pyplot.plot(fail_upper_bound, success_bounded, "--", color=color)
else:
# If the attack was not MaxConfidence, then this whole curve is just
# a loose lower bound
all_fail = np.concatenate((fail_optimal, fail_lower_bound), axis=0)
pyplot.plot(
all_fail,
success_optimal + success_bounded,
"--",
label=label,
linewidth=linewidth,
)
pyplot.xlabel("Failure rate on adversarial examples")
pyplot.ylabel("Success rate on clean examples")
gap = fail_upper_bound - fail_lower_bound
if gap.size > 0:
assert gap.min() >= 0.0
print("Max gap: ", gap.max())
def make_curve(report, success_name, fail_names):
"""
Make a success-failure curve.
:param report: A confidence report
(the type of object saved by make_confidence_report.py)
:param success_name: see plot_report_from_path
:param fail_names: see plot_report_from_path
:returns:
fail_optimal: list of failure rates on adversarial data for the optimal
(t >= .5) part of the curve. Each entry corresponds to a different
threshold. Thresholds are chosen to make the smoothest possible curve
from the available data, e.g. one threshold between each unique
confidence value observed in the data. To make sure that linear
interpolation between points in the curve never overestimates the
failure rate for a specific success rate, the curve also includes
extra points that increment the failure rate prior to any point
that increments the success rate, so the curve moves up and to the
right in a series of backwards "L" shapes rather than moving up
and to the right along diagonal lines. For large datasets these
maximally pessimistic points will usually not be visible and the
curve will appear smooth.
success_optimal: list of success rates on clean data on the optimal
part of the curve. Matches up with `fail_optimal`.
fail_lower_bound: list of observed failure rates on the t < .5 portion
of the curve where MaxConfidence is not optimal.
fail_upper_bound: list of upper bounds (assuming good enough optimization,
so not a true upper bound) on the failure rates on the t < .5 portion
of the curve where MaxConfidence is not optimal. Matches up with
`fail_lower_bound`.
success_bounded: success rates on the non-optimal part of the curve.
Matches up with `fail_lower_bound` and `fail_upper_bound`.
"""
success_results = report[success_name]
fail_name = None # pacify pylint
found = False
for fail_name in fail_names:
if fail_name in report:
found = True
break
if not found:
raise ValueError(
fail_name + " not in report." "Available keys: " + str(report.keys())
)
fail_results = report[fail_name]
# "good" means drawn from the distribution where we measure success rate.
# "bad" means drawn from the distribution where we measure failure rate.
# From here on out we use those terms, to avoid confusion between examples
# that actually failed and examples that were drawn from the distribution
# where we measured failure rate.
old_all_probs_version = False
if isinstance(success_results, dict):
# This dictionary key lookup will trigger a deprecation warning if `success_results` is not the old dictionary
# style of report, so we don't want to do a dictionary lookup unless we really are using the old version.
old_all_probs_version = "all_probs" in success_results
if old_all_probs_version:
warnings.warn(
"The 'all_probs' key is included only to support "
" old files from a private development codebase. "
"Support for this key can be dropped at any time "
" without warning."
)
good_probs = success_results["all_probs"]
bad_probs = fail_results["all_probs"]
bad_corrects = fail_results["correctness_mask"]
good_corrects = success_results["correctness_mask"]
else:
if isinstance(success_results, dict):
# Still using dict, but using newer key names
warnings.warn(
"Support for dictionary confidence reports is deprecated. Switch to using the classes in "
"cleverhans.confidence_report. Support for old dictionary-style reports may be removed "
"on or after 2019-07-19."
)
good_probs = success_results["confidence"]
bad_probs = fail_results["confidence"]
good_corrects = success_results["correctness"]
bad_corrects = fail_results["correctness"]
else:
# current version
good_probs = success_results.confidence
bad_probs = fail_results.confidence
good_corrects = success_results.correctness
bad_corrects = fail_results.correctness
good_triplets = [
(prob, correct, True) for prob, correct in safe_zip(good_probs, good_corrects)
]
bad_triplets = [
(prob, correct, False) for prob, correct in safe_zip(bad_probs, bad_corrects)
]
total_good = len(good_triplets)
total_bad = len(bad_triplets)
if total_good != 10000:
warnings.warn(
"Not using full test set? Found "
+ str(total_good)
+ " examples for measuring success rate"
)
if total_bad != 10000:
warnings.warn("Not using full test set for adversarial examples?")
all_triplets = good_triplets + bad_triplets
all_triplets = sorted(all_triplets, key=lambda x: -x[0])
# Start with the case for threshold t = 1.
# Examples are covered only if prob > t (strict inequality)
# So initially nothing is covered
good_covered_and_correct = 0
bad_covered_and_incorrect = 0
# Number of examples that are bad, incorrect, and covered by
# a t >= 0.5, or that were merely covered by a t < 0.5
failure_opportunities = 0
next_idx = 0
fail_optimal = []
success_optimal = []
fail_upper_bound = []
fail_lower_bound = []
success_bounded = []
bounded = False
# NOTE: the loop always exits via an internal break statement.
# Copied the termination condition to the while statement for ease
# of reading.
while next_idx < len(all_triplets):
gs = float(good_covered_and_correct) / total_good
bf = float(bad_covered_and_incorrect) / total_bad
# Add results for current threshold to the list
if not bounded:
# Sometimes when there are big jumps the failure rate it makes
# artifacts in the plot, where there's a long linear track.
# This implies the real success-fail curve is linear when
# actually it just isn't sampled by the data.
# To avoid implying that the model reaches a higher success
# rate than it actually does, we avoid these plotting artifacts
# by introducing extra points that make the graph move horizontally
# to the right first, then vertically.
if len(fail_optimal) > 0:
prev_bf = fail_optimal[-1]
prev_gs = success_optimal[-1]
if gs > prev_gs and bf > prev_bf:
fail_optimal.append(bf)
success_optimal.append(prev_gs)
success_optimal.append(gs)
fail_optimal.append(bf)
else:
success_bounded.append(gs)
fail_lower_bound.append(bf)
fail_upper_bound.append(float(failure_opportunities) / total_bad)
if next_idx == len(all_triplets):
break
# next_prob_to_include is not quite the same thing as the threshold.
# The threshold is infinitesimally smaller than this value.
next_prob_to_include = all_triplets[next_idx][0]
# Process all ties
while next_prob_to_include == all_triplets[next_idx][0]:
_prob, correct, is_good = all_triplets[next_idx]
if is_good:
good_covered_and_correct += correct
else:
if next_prob_to_include <= 0.5:
failure_opportunities += 1
else:
failure_opportunities += 1 - correct
bad_covered_and_incorrect += 1 - correct
next_idx += 1
if next_idx == len(all_triplets):
break
if next_prob_to_include <= 0.5:
bounded = True
out = (
fail_optimal,
success_optimal,
fail_lower_bound,
fail_upper_bound,
success_bounded,
)
return out
================================================
FILE: cleverhans/tf2/__init__.py
================================================
================================================
FILE: cleverhans/tf2/attacks/__init__.py
================================================
================================================
FILE: cleverhans/tf2/attacks/basic_iterative_method.py
================================================
"""
The BasicIterativeMethod attack.
"""
from cleverhans.tf2.attacks.projected_gradient_descent import projected_gradient_descent
def basic_iterative_method(
model_fn,
x,
eps,
eps_iter,
nb_iter,
norm,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
rand_init=None,
rand_minmax=0.3,
sanity_checks=True,
):
"""
The BasicIterativeMethod attack.
"""
return projected_gradient_descent(
model_fn,
x,
eps,
eps_iter,
nb_iter,
norm,
clip_min=clip_min,
clip_max=clip_max,
y=y,
targeted=targeted,
rand_init=False,
rand_minmax=rand_minmax,
sanity_checks=sanity_checks,
)
================================================
FILE: cleverhans/tf2/attacks/carlini_wagner_l2.py
================================================
"""The CarliniWagnerL2 attack.
"""
import numpy as np
import tensorflow as tf
from cleverhans.tf2.utils import get_or_guess_labels, set_with_mask
def carlini_wagner_l2(model_fn, x, **kwargs):
"""
This is the function interface for the Carlini-Wagner-L2 attack.
For more details on the attack and the parameters see the corresponding class.
"""
return CarliniWagnerL2(model_fn, **kwargs).attack(x)
class CarliniWagnerL2Exception(Exception):
pass
class CarliniWagnerL2(object):
def __init__(
self,
model_fn,
y=None,
targeted=False,
batch_size=128,
clip_min=0.0,
clip_max=1.0,
binary_search_steps=5,
max_iterations=1_000,
abort_early=True,
confidence=0.0,
initial_const=1e-2,
learning_rate=5e-3,
):
"""
This attack was originally proposed by Carlini and Wagner. It is an
iterative attack that finds adversarial examples on many defenses that
are robust to other attacks.
Paper link: https://arxiv.org/abs/1608.04644
At a high level, this attack is an iterative attack using Adam and
a specially-chosen loss function to find adversarial examples with
lower distortion than other attacks. This comes at the cost of speed,
as this attack is often much slower than others.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param y: (optional) Tensor with target labels.
:param targeted: (optional) Targeted attack?
:param batch_size (optional): Number of attacks to run simultaneously.
:param clip_min: (optional) float. Minimum float values for adversarial example components.
:param clip_max: (optional) float. Maximum float value for adversarial example components.
:param binary_search_steps (optional): The number of times we perform binary
search to find the optimal tradeoff-
constant between norm of the purturbation
and confidence of the classification.
:param max_iterations (optional): The maximum number of iterations. Setting this
to a larger value will produce lower distortion
results. Using only a few iterations requires
a larger learning rate, and will produce larger
distortion results.
:param abort_early (optional): If true, allows early aborts if gradient descent
is unable to make progress (i.e., gets stuck in
a local minimum).
:param confidence (optional): Confidence of adversarial examples: higher produces
examples with larger l2 distortion, but more
strongly classified as adversarial.
:param initial_const (optional): The initial tradeoff-constant used to tune the
relative importance of the size of the perturbation
and confidence of classification.
If binary_search_steps is large, the initial
constant is not important. A smaller value of
this constant gives lower distortion results.
:param learning_rate (optional): The learning rate for the attack algorithm.
Smaller values produce better results but are
slower to converge.
"""
self.model_fn = model_fn
self.batch_size = batch_size
self.y = y
self.targeted = y is not None
self.clip_min = clip_min
self.clip_max = clip_max
self.binary_search_steps = binary_search_steps
self.max_iterations = max_iterations
self.abort_early = abort_early
self.learning_rate = learning_rate
self.confidence = confidence
self.initial_const = initial_const
# the optimizer
self.optimizer = tf.keras.optimizers.Adam(self.learning_rate)
super(CarliniWagnerL2, self).__init__()
def attack(self, x):
"""
Returns adversarial examples for the tensor.
:param x: input tensor.
:return: a numpy tensor with the adversarial example.
"""
adv_ex = np.zeros_like(x)
for i in range(0, len(x), self.batch_size):
adv_ex[i : i + self.batch_size] = self._attack(
x[i : i + self.batch_size]
).numpy()
return adv_ex
def _attack(self, x):
if self.clip_min is not None:
if not np.all(tf.math.greater_equal(x, self.clip_min)):
raise CarliniWagnerL2Exception(
f"The input is smaller than the minimum value of {self.clip_min}r"
)
if self.clip_max is not None:
if not np.all(tf.math.less_equal(x, self.clip_max)):
raise CarliniWagnerL2Exception(
f"The input is greater than the maximum value of {self.clip_max}!"
)
# cast to tensor if provided as numpy array
original_x = tf.cast(x, tf.float32)
shape = original_x.shape
y, _ = get_or_guess_labels(
self.model_fn, original_x, y=self.y, targeted=self.targeted
)
if not y.shape.as_list()[0] == original_x.shape.as_list()[0]:
raise CarliniWagnerL2Exception("x and y do not have the same shape!")
# re-scale x to [0, 1]
x = original_x
x = (x - self.clip_min) / (self.clip_max - self.clip_min)
x = tf.clip_by_value(x, 0.0, 1.0)
# scale to [-1, 1]
x = (x * 2.0) - 1.0
# convert tonh-space
x = tf.atanh(x * 0.999999)
# parameters for the binary search
lower_bound = tf.zeros(shape[:1])
upper_bound = tf.ones(shape[:1]) * 1e10
const = tf.ones(shape) * self.initial_const
# placeholder variables for best values
best_l2 = tf.fill(shape[:1], 1e10)
best_score = tf.fill(shape[:1], -1)
best_score = tf.cast(best_score, tf.int32)
best_attack = original_x
# convience function for comparing
compare_fn = tf.equal if self.targeted else tf.not_equal
# the perturbation
modifier = tf.Variable(tf.zeros(shape, dtype=x.dtype), trainable=True)
for outer_step in range(self.binary_search_steps):
# at each iteration reset variable state
modifier.assign(tf.zeros(shape, dtype=x.dtype))
for var in self.optimizer.variables():
var.assign(tf.zeros(var.shape, dtype=var.dtype))
# variables to keep track in the inner loop
current_best_l2 = tf.fill(shape[:1], 1e10)
current_best_score = tf.fill(shape[:1], -1)
current_best_score = tf.cast(current_best_score, tf.int32)
# The last iteration (if we run many steps) repeat the search once.
if (
self.binary_search_steps >= 10
and outer_step == self.binary_search_steps - 1
):
const = upper_bound
# early stopping criteria
prev = None
for iteration in range(self.max_iterations):
x_new, loss, preds, l2_dist = self.attack_step(x, y, modifier, const)
# check if we made progress, abort otherwise
if (
self.abort_early
and iteration % ((self.max_iterations // 10) or 1) == 0
):
if prev is not None and loss > prev * 0.9999:
break
prev = loss
lab = tf.argmax(y, axis=1)
pred_with_conf = (
preds - self.confidence
if self.targeted
else preds + self.confidence
)
pred_with_conf = tf.argmax(pred_with_conf, axis=1)
pred = tf.argmax(preds, axis=1)
pred = tf.cast(pred, tf.int32)
# compute a binary mask of the tensors we want to assign
mask = tf.math.logical_and(
tf.less(l2_dist, current_best_l2), compare_fn(pred_with_conf, lab)
)
# all entries which evaluate to True get reassigned
current_best_l2 = set_with_mask(current_best_l2, l2_dist, mask)
current_best_score = set_with_mask(current_best_score, pred, mask)
# if the l2 distance is better than the one found before
# and if the example is a correct example (with regards to the labels)
mask = tf.math.logical_and(
tf.less(l2_dist, best_l2), compare_fn(pred_with_conf, lab)
)
best_l2 = set_with_mask(best_l2, l2_dist, mask)
best_score = set_with_mask(best_score, pred, mask)
# mask is of shape [batch_size]; best_attack is [batch_size, image_size]
# need to expand
mask = tf.reshape(mask, [-1, 1, 1, 1])
mask = tf.tile(mask, [1, *best_attack.shape[1:]])
best_attack = set_with_mask(best_attack, x_new, mask)
# adjust binary search parameters
lab = tf.argmax(y, axis=1)
lab = tf.cast(lab, tf.int32)
# we first compute the mask for the upper bound
upper_mask = tf.math.logical_and(
compare_fn(best_score, lab),
tf.not_equal(best_score, -1),
)
upper_bound = set_with_mask(
upper_bound, tf.math.minimum(upper_bound, const), upper_mask
)
# based on this mask compute const mask
const_mask = tf.math.logical_and(
upper_mask,
tf.less(upper_bound, 1e9),
)
const = set_with_mask(const, (lower_bound + upper_bound) / 2.0, const_mask)
# else case is the negation of the inital mask
lower_mask = tf.math.logical_not(upper_mask)
lower_bound = set_with_mask(
lower_bound, tf.math.maximum(lower_bound, const), lower_mask
)
const_mask = tf.math.logical_and(
lower_mask,
tf.less(upper_bound, 1e9),
)
const = set_with_mask(const, (lower_bound + upper_bound) / 2, const_mask)
const_mask = tf.math.logical_not(const_mask)
const = set_with_mask(const, const * 10, const_mask)
return best_attack
def attack_step(self, x, y, modifier, const):
x_new, grads, loss, preds, l2_dist = self.gradient(x, y, modifier, const)
self.optimizer.apply_gradients([(grads, modifier)])
return x_new, loss, preds, l2_dist
@tf.function
def gradient(self, x, y, modifier, const):
# compute the actual attack
with tf.GradientTape() as tape:
adv_image = modifier + x
x_new = clip_tanh(adv_image, clip_min=self.clip_min, clip_max=self.clip_max)
preds = self.model_fn(x_new)
loss, l2_dist = loss_fn(
x=x,
x_new=x_new,
y_true=y,
y_pred=preds,
confidence=self.confidence,
const=const,
targeted=self.targeted,
clip_min=self.clip_min,
clip_max=self.clip_max,
)
grads = tape.gradient(loss, adv_image)
return x_new, grads, loss, preds, l2_dist
def l2(x, y):
# technically squarred l2
return tf.reduce_sum(tf.square(x - y), list(range(1, len(x.shape))))
def loss_fn(
x,
x_new,
y_true,
y_pred,
confidence,
const=0,
targeted=False,
clip_min=0,
clip_max=1,
):
other = clip_tanh(x, clip_min=clip_min, clip_max=clip_max)
l2_dist = l2(x_new, other)
real = tf.reduce_sum(y_true * y_pred, 1)
other = tf.reduce_max((1.0 - y_true) * y_pred - y_true * 10_000, 1)
if targeted:
# if targeted, optimize for making the other class most likely
loss_1 = tf.maximum(0.0, other - real + confidence)
else:
# if untargeted, optimize for making this class least likely.
loss_1 = tf.maximum(0.0, real - other + confidence)
# sum up losses
loss_2 = tf.reduce_sum(l2_dist)
loss_1 = tf.reduce_sum(const * loss_1)
loss = loss_1 + loss_2
return loss, l2_dist
def clip_tanh(x, clip_min, clip_max):
return ((tf.tanh(x) + 1) / 2) * (clip_max - clip_min) + clip_min
================================================
FILE: cleverhans/tf2/attacks/fast_gradient_method.py
================================================
"""The Fast Gradient Method attack."""
import numpy as np
import tensorflow as tf
from cleverhans.tf2.utils import optimize_linear, compute_gradient
def fast_gradient_method(
model_fn,
x,
eps,
norm,
loss_fn=None,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
sanity_checks=False,
):
"""
Tensorflow 2.0 implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param norm: Order of the norm (mimics NumPy). Possible values: np.inf, 1 or 2.
:param loss_fn: (optional) callable. Loss function that takes (labels, logits) as arguments and returns loss.
default function is 'tf.nn.sparse_softmax_cross_entropy_with_logits'
:param clip_min: (optional) float. Minimum float value for adversarial example components.
:param clip_max: (optional) float. Maximum float value for adversarial example components.
:param y: (optional) Tensor with true labels. If targeted is true, then provide the
target label. Otherwise, only provide this parameter if you'd like to use true
labels when crafting adversarial samples. Otherwise, model predictions are used
as labels to avoid the "label leaking" effect (explained in this paper:
https://arxiv.org/abs/1611.01236). Default is None.
:param targeted: (optional) bool. Is the attack targeted or untargeted?
Untargeted, the default, will try to make the label incorrect.
Targeted will instead try to move in the direction of being more like y.
:param sanity_checks: bool, if True, include asserts (Turn them off to use less runtime /
memory or for unit tests that intentionally pass strange input)
:return: a tensor for the adversarial example
"""
if norm not in [np.inf, 1, 2]:
raise ValueError("Norm order must be either np.inf, 1, or 2.")
if loss_fn is None:
loss_fn = tf.nn.sparse_softmax_cross_entropy_with_logits
asserts = []
# If a data range was specified, check that the input was in that range
if clip_min is not None:
asserts.append(tf.math.greater_equal(x, clip_min))
if clip_max is not None:
asserts.append(tf.math.less_equal(x, clip_max))
# cast to tensor if provided as numpy array
x = tf.cast(x, tf.float32)
if y is None:
# Using model predictions as ground truth to avoid label leaking
y = tf.argmax(model_fn(x), 1)
grad = compute_gradient(model_fn, loss_fn, x, y, targeted)
optimal_perturbation = optimize_linear(grad, eps, norm)
# Add perturbation to original example to obtain adversarial example
adv_x = x + optimal_perturbation
# If clipping is needed, reset all values outside of [clip_min, clip_max]
if (clip_min is not None) or (clip_max is not None):
# We don't currently support one-sided clipping
assert clip_min is not None and clip_max is not None
adv_x = tf.clip_by_value(adv_x, clip_min, clip_max)
if sanity_checks:
assert np.all(asserts)
return adv_x
================================================
FILE: cleverhans/tf2/attacks/madry_et_al.py
================================================
"""
The MadryEtAl attack
"""
from cleverhans.tf2.attacks.projected_gradient_descent import projected_gradient_descent
def madry_et_al(
model_fn,
x,
eps,
eps_iter,
nb_iter,
norm,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
rand_minmax=0.3,
sanity_checks=True,
):
"""
The attack from Madry et al 2017
"""
return projected_gradient_descent(
model_fn,
x,
eps,
eps_iter,
nb_iter,
norm,
clip_min=clip_min,
clip_max=clip_max,
y=y,
targeted=targeted,
rand_init=True,
rand_minmax=rand_minmax,
sanity_checks=sanity_checks,
)
================================================
FILE: cleverhans/tf2/attacks/momentum_iterative_method.py
================================================
"""The MomentumIterativeMethod attack."""
import numpy as np
import tensorflow as tf
from cleverhans.tf2.utils import optimize_linear, compute_gradient
from cleverhans.tf2.utils import clip_eta
def momentum_iterative_method(
model_fn,
x,
eps=0.3,
eps_iter=0.06,
nb_iter=10,
norm=np.inf,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
decay_factor=1.0,
sanity_checks=True,
):
"""
Tensorflow 2.0 implementation of Momentum Iterative Method (Dong et al. 2017).
This method won the first places in NIPS 2017 Non-targeted Adversarial Attacks
and Targeted Adversarial Attacks. The original paper used hard labels
for this attack; no label smoothing.
Paper link: https://arxiv.org/pdf/1710.06081.pdf
:param model_fn: a callable that takes an input tensor and returns the m
gitextract_jw024m5z/
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ └── feature_request.md
│ ├── cml_gpu_test.yaml
│ └── workflows/
│ ├── style_type_check.yml
│ ├── tests-pytorch.yml
│ ├── tutorials-jax.yml
│ ├── tutorials-pytorch.yml
│ └── tutorials-tf2.yml
├── .gitignore
├── .pre-commit-config.yaml
├── .pylintrc
├── .setup_vm_and_run_tests.sh
├── CODE_OF_CONDUCT.rst
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── README.md
├── assets/
│ └── logo.psd
├── cleverhans/
│ ├── __init__.py
│ ├── devtools/
│ │ ├── LICENSE.txt
│ │ ├── __init__.py
│ │ ├── autopep8_all.py
│ │ ├── checks.py
│ │ ├── list_files.py
│ │ ├── mocks.py
│ │ ├── tests/
│ │ │ ├── __init__.py
│ │ │ └── test_format.py
│ │ └── version.py
│ ├── experimental/
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── certification/
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── certify.py
│ │ ├── dual_formulation.py
│ │ ├── nn.py
│ │ ├── optimization.py
│ │ ├── tests/
│ │ │ ├── dual_formulation_test.py
│ │ │ ├── nn_test.py
│ │ │ ├── optimization_test.py
│ │ │ └── utils_test.py
│ │ └── utils.py
│ ├── generic/
│ │ ├── README.md
│ │ └── __init__.py
│ ├── jax/
│ │ ├── __init__.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── fast_gradient_method.py
│ │ │ └── projected_gradient_descent.py
│ │ └── utils.py
│ ├── plot/
│ │ ├── __init__.py
│ │ ├── image.py
│ │ ├── pyplot_defaults.py
│ │ ├── pyplot_image.py
│ │ ├── save_pdf.py
│ │ └── success_fail.py
│ ├── tf2/
│ │ ├── __init__.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── basic_iterative_method.py
│ │ │ ├── carlini_wagner_l2.py
│ │ │ ├── fast_gradient_method.py
│ │ │ ├── madry_et_al.py
│ │ │ ├── momentum_iterative_method.py
│ │ │ ├── projected_gradient_descent.py
│ │ │ └── spsa.py
│ │ └── utils.py
│ ├── torch/
│ │ ├── __init__.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── carlini_wagner_l2.py
│ │ │ ├── fast_gradient_method.py
│ │ │ ├── hop_skip_jump_attack.py
│ │ │ ├── noise.py
│ │ │ ├── projected_gradient_descent.py
│ │ │ ├── semantic.py
│ │ │ ├── sparse_l1_descent.py
│ │ │ └── spsa.py
│ │ ├── tests/
│ │ │ ├── __init__.py
│ │ │ ├── test_attacks.py
│ │ │ └── test_utils.py
│ │ └── utils.py
│ └── utils.py
├── cleverhans_v3.1.0/
│ ├── CODE_OF_CONDUCT.rst
│ ├── CONTRIBUTING.md
│ ├── Dockerfile
│ ├── LICENSE
│ ├── README.md
│ ├── assets/
│ │ └── logo.psd
│ ├── cleverhans/
│ │ ├── __init__.py
│ │ ├── attack_bundling.py
│ │ ├── attacks/
│ │ │ ├── __init__.py
│ │ │ ├── attack.py
│ │ │ ├── basic_iterative_method.py
│ │ │ ├── carlini_wagner_l2.py
│ │ │ ├── deep_fool.py
│ │ │ ├── elastic_net_method.py
│ │ │ ├── fast_feature_adversaries.py
│ │ │ ├── fast_gradient_method.py
│ │ │ ├── hop_skip_jump_attack.py
│ │ │ ├── lbfgs.py
│ │ │ ├── madry_et_al.py
│ │ │ ├── max_confidence.py
│ │ │ ├── momentum_iterative_method.py
│ │ │ ├── noise.py
│ │ │ ├── projected_gradient_descent.py
│ │ │ ├── saliency_map_method.py
│ │ │ ├── semantic.py
│ │ │ ├── sparse_l1_descent.py
│ │ │ ├── spatial_transformation_method.py
│ │ │ ├── spsa.py
│ │ │ └── virtual_adversarial_method.py
│ │ ├── attacks_tf.py
│ │ ├── attacks_tfe.py
│ │ ├── augmentation.py
│ │ ├── canary.py
│ │ ├── compat.py
│ │ ├── confidence_report.py
│ │ ├── dataset.py
│ │ ├── devtools/
│ │ │ ├── LICENSE.txt
│ │ │ ├── __init__.py
│ │ │ ├── autopep8_all.py
│ │ │ ├── checks.py
│ │ │ ├── list_files.py
│ │ │ ├── mocks.py
│ │ │ ├── tests/
│ │ │ │ ├── __init__.py
│ │ │ │ └── test_format.py
│ │ │ └── version.py
│ │ ├── evaluation.py
│ │ ├── experimental/
│ │ │ ├── README.md
│ │ │ ├── __init__.py
│ │ │ └── certification/
│ │ │ ├── README.md
│ │ │ ├── __init__.py
│ │ │ ├── certify.py
│ │ │ ├── dual_formulation.py
│ │ │ ├── nn.py
│ │ │ ├── optimization.py
│ │ │ ├── tests/
│ │ │ │ ├── dual_formulation_test.py
│ │ │ │ ├── nn_test.py
│ │ │ │ ├── optimization_test.py
│ │ │ │ └── utils_test.py
│ │ │ └── utils.py
│ │ ├── initializers.py
│ │ ├── loss.py
│ │ ├── model.py
│ │ ├── model_zoo/
│ │ │ ├── __init__.py
│ │ │ ├── all_convolutional.py
│ │ │ ├── basic_cnn.py
│ │ │ ├── deep_k_nearest_neighbors/
│ │ │ │ ├── README.md
│ │ │ │ ├── __init__.py
│ │ │ │ └── dknn.py
│ │ │ ├── madry_lab_challenges/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── cifar10_model.py
│ │ │ │ └── make_cifar10_joblib.py
│ │ │ └── soft_nearest_neighbor_loss/
│ │ │ ├── SNNL_regularized_model.py
│ │ │ ├── SNNL_regularized_train.py
│ │ │ └── __init__.py
│ │ ├── picklable_model.py
│ │ ├── plot/
│ │ │ ├── __init__.py
│ │ │ ├── image.py
│ │ │ ├── pyplot_defaults.py
│ │ │ ├── pyplot_image.py
│ │ │ ├── save_pdf.py
│ │ │ └── success_fail.py
│ │ ├── serial.py
│ │ ├── train.py
│ │ ├── utils.py
│ │ ├── utils_keras.py
│ │ ├── utils_mnist.py
│ │ ├── utils_pytorch.py
│ │ ├── utils_tf.py
│ │ └── utils_tfe.py
│ ├── cleverhans_tutorials/
│ │ ├── __init__.py
│ │ ├── cifar10_tutorial_tf.py
│ │ ├── evaluate_pickled_model.py
│ │ ├── mnist_blackbox.py
│ │ ├── mnist_tutorial_cw.py
│ │ ├── mnist_tutorial_jsma.py
│ │ ├── mnist_tutorial_keras.py
│ │ ├── mnist_tutorial_keras_tf.py
│ │ ├── mnist_tutorial_picklable.py
│ │ ├── mnist_tutorial_pytorch.py
│ │ ├── mnist_tutorial_tf.py
│ │ ├── mnist_tutorial_tfe.py
│ │ ├── tutorial_models.py
│ │ └── tutorial_models_tfe.py
│ ├── docs/
│ │ ├── .nojekyll
│ │ ├── README.html
│ │ ├── _modules/
│ │ │ ├── abc.html
│ │ │ ├── cleverhans/
│ │ │ │ ├── attacks/
│ │ │ │ │ ├── attack.html
│ │ │ │ │ ├── basic_iterative_method.html
│ │ │ │ │ ├── carlini_wagner_l2.html
│ │ │ │ │ ├── deep_fool.html
│ │ │ │ │ ├── elastic_net_method.html
│ │ │ │ │ ├── fast_feature_adversaries.html
│ │ │ │ │ ├── fast_gradient_method.html
│ │ │ │ │ ├── hop_skip_jump_attack.html
│ │ │ │ │ ├── lbfgs.html
│ │ │ │ │ ├── madry_et_al.html
│ │ │ │ │ ├── max_confidence.html
│ │ │ │ │ ├── momentum_iterative_method.html
│ │ │ │ │ ├── noise.html
│ │ │ │ │ ├── projected_gradient_descent.html
│ │ │ │ │ ├── saliency_map_method.html
│ │ │ │ │ ├── semantic.html
│ │ │ │ │ ├── sparse_l1_descent.html
│ │ │ │ │ ├── spatial_transformation_method.html
│ │ │ │ │ ├── spsa.html
│ │ │ │ │ └── virtual_adversarial_method.html
│ │ │ │ ├── compat.html
│ │ │ │ ├── model.html
│ │ │ │ └── utils_tf.html
│ │ │ └── index.html
│ │ ├── _sources/
│ │ │ ├── README.md.txt
│ │ │ ├── index.md.txt
│ │ │ └── source/
│ │ │ ├── attacks.md.txt
│ │ │ ├── devtools.md.txt
│ │ │ ├── future.md.txt
│ │ │ └── model.md.txt
│ │ ├── _static/
│ │ │ ├── alabaster.css
│ │ │ ├── basic.css
│ │ │ ├── custom.css
│ │ │ ├── doctools.js
│ │ │ ├── documentation_options.js
│ │ │ ├── jquery-3.5.1.js
│ │ │ ├── jquery.js
│ │ │ ├── language_data.js
│ │ │ ├── pygments.css
│ │ │ ├── searchtools.js
│ │ │ ├── underscore-1.3.1.js
│ │ │ └── underscore.js
│ │ ├── genindex.html
│ │ ├── index.html
│ │ ├── objects.inv
│ │ ├── py-modindex.html
│ │ ├── search.html
│ │ ├── searchindex.js
│ │ └── source/
│ │ ├── attacks.html
│ │ ├── devtools.html
│ │ ├── future.html
│ │ └── model.html
│ ├── docsource/
│ │ ├── Makefile
│ │ ├── README.md
│ │ ├── _templates/
│ │ │ └── layout.html
│ │ ├── conf.py
│ │ ├── docs_requirements.txt
│ │ ├── index.md
│ │ └── source/
│ │ ├── attacks.md
│ │ ├── devtools.md
│ │ ├── future.md
│ │ └── model.md
│ ├── examples/
│ │ ├── README.md
│ │ ├── RL-attack/
│ │ │ ├── README.md
│ │ │ ├── enjoy-adv.py
│ │ │ ├── model.py
│ │ │ └── train.py
│ │ ├── adversarial_asr/
│ │ │ ├── LibriSpeech/
│ │ │ │ └── LICENSE.TXT
│ │ │ ├── README.md
│ │ │ ├── generate_imperceptible_adv.py
│ │ │ ├── generate_masking_threshold.py
│ │ │ ├── generate_robust_adv.py
│ │ │ ├── model/
│ │ │ │ ├── checkpoint
│ │ │ │ ├── ckpt-00908156.index
│ │ │ │ ├── ckpt-00908156.meta
│ │ │ │ └── events.out.tfevents.1543301105.e33cfcb49883
│ │ │ ├── read_data.txt
│ │ │ ├── room_simulator.py
│ │ │ ├── test_imperceptible_adv.py
│ │ │ ├── test_robust_adv.py
│ │ │ ├── tool.py
│ │ │ └── util/
│ │ │ ├── convert_name_format.sh
│ │ │ └── read_data_full.txt
│ │ ├── adversarial_patch/
│ │ │ ├── AdversarialPatch.ipynb
│ │ │ └── README.md
│ │ ├── facenet_adversarial_faces/
│ │ │ ├── README.md
│ │ │ ├── facenet_fgsm.py
│ │ │ └── set_loader.py
│ │ ├── imagenet_featadvs/
│ │ │ └── model.py
│ │ ├── madry_lab_challenges/
│ │ │ ├── LICENSE
│ │ │ ├── README
│ │ │ ├── cifar10/
│ │ │ │ └── attack_model.py
│ │ │ └── mnist/
│ │ │ ├── attack_model.py
│ │ │ └── madry_mnist_model.py
│ │ ├── multigpu_advtrain/
│ │ │ ├── README.md
│ │ │ ├── attacks_multigpu.py
│ │ │ ├── evaluator.py
│ │ │ ├── make_model.py
│ │ │ ├── model.py
│ │ │ ├── resnet_tf.py
│ │ │ ├── run_multigpu.py
│ │ │ ├── runner.py
│ │ │ ├── test_attack_multigpu.py
│ │ │ ├── test_run_multigpu.py
│ │ │ ├── test_runner.py
│ │ │ ├── trainer.py
│ │ │ ├── utils.py
│ │ │ ├── utils_cifar.py
│ │ │ └── utils_svhn.py
│ │ ├── nips17_adversarial_competition/
│ │ │ ├── .gitignore
│ │ │ ├── README.md
│ │ │ ├── dataset/
│ │ │ │ ├── README.md
│ │ │ │ ├── dev_dataset.csv
│ │ │ │ ├── download_images.py
│ │ │ │ └── final_dataset.csv
│ │ │ ├── dev_toolkit/
│ │ │ │ ├── .gitignore
│ │ │ │ ├── README.md
│ │ │ │ ├── download_data.sh
│ │ │ │ ├── run_attacks_and_defenses.py
│ │ │ │ ├── run_attacks_and_defenses.sh
│ │ │ │ ├── sample_attacks/
│ │ │ │ │ ├── download_checkpoints.sh
│ │ │ │ │ ├── fgsm/
│ │ │ │ │ │ ├── attack_fgsm.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_attack.sh
│ │ │ │ │ ├── noop/
│ │ │ │ │ │ ├── attack_noop.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_attack.sh
│ │ │ │ │ └── random_noise/
│ │ │ │ │ ├── attack_random_noise.py
│ │ │ │ │ ├── metadata.json
│ │ │ │ │ └── run_attack.sh
│ │ │ │ ├── sample_defenses/
│ │ │ │ │ ├── adv_inception_v3/
│ │ │ │ │ │ ├── defense.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_defense.sh
│ │ │ │ │ ├── base_inception_model/
│ │ │ │ │ │ ├── defense.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_defense.sh
│ │ │ │ │ ├── download_checkpoints.sh
│ │ │ │ │ └── ens_adv_inception_resnet_v2/
│ │ │ │ │ ├── defense.py
│ │ │ │ │ ├── inception_resnet_v2.py
│ │ │ │ │ ├── metadata.json
│ │ │ │ │ └── run_defense.sh
│ │ │ │ ├── sample_targeted_attacks/
│ │ │ │ │ ├── download_checkpoints.sh
│ │ │ │ │ ├── iter_target_class/
│ │ │ │ │ │ ├── attack_iter_target_class.py
│ │ │ │ │ │ ├── metadata.json
│ │ │ │ │ │ └── run_attack.sh
│ │ │ │ │ └── step_target_class/
│ │ │ │ │ ├── attack_step_target_class.py
│ │ │ │ │ ├── metadata.json
│ │ │ │ │ └── run_attack.sh
│ │ │ │ └── validation_tool/
│ │ │ │ ├── README.md
│ │ │ │ ├── submission_validator_lib.py
│ │ │ │ └── validate_submission.py
│ │ │ └── eval_infra/
│ │ │ ├── README.md
│ │ │ ├── code/
│ │ │ │ ├── eval_lib/
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── classification_results.py
│ │ │ │ │ ├── cloud_client.py
│ │ │ │ │ ├── dataset_helper.py
│ │ │ │ │ ├── image_batches.py
│ │ │ │ │ ├── submissions.py
│ │ │ │ │ ├── tests/
│ │ │ │ │ │ ├── __init__.py
│ │ │ │ │ │ ├── classification_results_test.py
│ │ │ │ │ │ ├── fake_cloud_client.py
│ │ │ │ │ │ ├── fake_cloud_client_test.py
│ │ │ │ │ │ ├── image_batches_test.py
│ │ │ │ │ │ ├── submissions_test.py
│ │ │ │ │ │ └── work_data_test.py
│ │ │ │ │ └── work_data.py
│ │ │ │ ├── master.py
│ │ │ │ ├── run_worker_locally.sh
│ │ │ │ ├── start_worker_in_tmux.sh
│ │ │ │ └── worker.py
│ │ │ ├── run_master.sh
│ │ │ ├── scripts/
│ │ │ │ ├── config.sh
│ │ │ │ ├── copy_baselines.sh
│ │ │ │ ├── copy_dataset_to_vm.sh
│ │ │ │ ├── copy_eval_infra_to_vm.sh
│ │ │ │ ├── create_workers.sh
│ │ │ │ ├── prepare_virtualenv.sh
│ │ │ │ ├── scp_cloud_vm.sh
│ │ │ │ └── start_workers.sh
│ │ │ └── validation_tool/
│ │ │ ├── validate_and_copy_submissions.py
│ │ │ └── validate_submission_lib.py
│ │ ├── robust_vision_benchmark/
│ │ │ ├── README.md
│ │ │ └── cleverhans_attack_example/
│ │ │ ├── Dockerfile
│ │ │ ├── main.py
│ │ │ ├── requirements.txt
│ │ │ └── utils.py
│ │ └── test_imagenet_attacks.py
│ ├── scripts/
│ │ ├── compute_accuracy.py
│ │ ├── make_confidence_report.py
│ │ ├── make_confidence_report_bundle_examples.py
│ │ ├── make_confidence_report_bundled.py
│ │ ├── make_confidence_report_spsa.py
│ │ ├── plot_success_fail_curve.py
│ │ ├── print_report.py
│ │ └── show_images.py
│ ├── setup.py
│ └── tests_tf/
│ ├── test_attack_bundling.py
│ ├── test_attacks.py
│ ├── test_attacks_tf.py
│ ├── test_confidence_report.py
│ ├── test_dataset.py
│ ├── test_defenses.py
│ ├── test_evaluation.py
│ ├── test_mnist_blackbox.py
│ ├── test_mnist_tutorial_cw.py
│ ├── test_mnist_tutorial_jsma.py
│ ├── test_mnist_tutorial_keras.py
│ ├── test_mnist_tutorial_keras_tf.py
│ ├── test_mnist_tutorial_tf.py
│ ├── test_model.py
│ ├── test_picklable_model.py
│ ├── test_projected_gradient_descent.py
│ ├── test_serial.py
│ ├── test_utils.py
│ ├── test_utils_keras.py
│ └── test_utils_tf.py
├── defenses/
│ ├── README.md
│ ├── generic/
│ │ ├── README.md
│ │ └── __init__.py
│ ├── jax/
│ │ └── README.md
│ ├── tf2/
│ │ └── README.md
│ └── torch/
│ ├── README.md
│ └── audio/
│ └── input_tranformation/
│ └── resampling.py
├── docs/
│ ├── .nojekyll
│ ├── README.html
│ ├── _modules/
│ │ ├── abc.html
│ │ ├── cleverhans/
│ │ │ ├── attacks/
│ │ │ │ ├── attack.html
│ │ │ │ ├── basic_iterative_method.html
│ │ │ │ ├── carlini_wagner_l2.html
│ │ │ │ ├── deep_fool.html
│ │ │ │ ├── elastic_net_method.html
│ │ │ │ ├── fast_feature_adversaries.html
│ │ │ │ ├── fast_gradient_method.html
│ │ │ │ ├── hop_skip_jump_attack.html
│ │ │ │ ├── lbfgs.html
│ │ │ │ ├── madry_et_al.html
│ │ │ │ ├── max_confidence.html
│ │ │ │ ├── momentum_iterative_method.html
│ │ │ │ ├── noise.html
│ │ │ │ ├── projected_gradient_descent.html
│ │ │ │ ├── saliency_map_method.html
│ │ │ │ ├── semantic.html
│ │ │ │ ├── sparse_l1_descent.html
│ │ │ │ ├── spatial_transformation_method.html
│ │ │ │ ├── spsa.html
│ │ │ │ └── virtual_adversarial_method.html
│ │ │ ├── compat.html
│ │ │ ├── model.html
│ │ │ └── utils_tf.html
│ │ └── index.html
│ ├── _sources/
│ │ ├── README.md.txt
│ │ ├── index.md.txt
│ │ └── source/
│ │ ├── attacks.md.txt
│ │ ├── devtools.md.txt
│ │ ├── future.md.txt
│ │ └── model.md.txt
│ ├── _static/
│ │ ├── alabaster.css
│ │ ├── basic.css
│ │ ├── custom.css
│ │ ├── doctools.js
│ │ ├── documentation_options.js
│ │ ├── jquery-3.5.1.js
│ │ ├── jquery.js
│ │ ├── language_data.js
│ │ ├── pygments.css
│ │ ├── searchtools.js
│ │ ├── underscore-1.3.1.js
│ │ └── underscore.js
│ ├── genindex.html
│ ├── index.html
│ ├── objects.inv
│ ├── py-modindex.html
│ ├── search.html
│ ├── searchindex.js
│ └── source/
│ ├── attacks.html
│ ├── devtools.html
│ ├── future.html
│ └── model.html
├── docsource/
│ ├── Makefile
│ ├── README.md
│ ├── _templates/
│ │ └── layout.html
│ ├── conf.py
│ ├── docs_requirements.txt
│ ├── index.md
│ └── source/
│ ├── attacks.md
│ ├── devtools.md
│ ├── future.md
│ └── model.md
├── examples/
│ └── README.md
├── requirements/
│ ├── requirements-dev.txt
│ ├── requirements-gpu.txt
│ ├── requirements-jax.txt
│ ├── requirements-pytorch.txt
│ ├── requirements-tf2.txt
│ └── requirements.txt
├── setup.py
└── tutorials/
├── README.md
├── generic/
│ ├── README.md
│ └── __init__.py
├── jax/
│ ├── __init__.py
│ ├── datasets.py
│ └── mnist_tutorial.py
├── tf2/
│ ├── __init__.py
│ ├── cifar10_tutorial.py
│ └── mnist_tutorial.py
└── torch/
├── __init__.py
├── cifar10_tutorial.py
├── datasets.py
└── mnist_tutorial.py
SYMBOL INDEX (2257 symbols across 231 files)
FILE: cleverhans/devtools/checks.py
class CleverHansTest (line 17) | class CleverHansTest(unittest.TestCase):
method setUp (line 20) | def setUp(self):
method tearDown (line 25) | def tearDown(self):
method assertClose (line 28) | def assertClose(self, x, y, *args, **kwargs):
FILE: cleverhans/devtools/list_files.py
function list_files (line 6) | def list_files(suffix=""):
function _list_files (line 47) | def _list_files(path, suffix=""):
FILE: cleverhans/devtools/mocks.py
function random_feed_dict (line 16) | def random_feed_dict(rng, placeholders):
class SimpleDataset (line 35) | class SimpleDataset(Dataset):
method __init__ (line 41) | def __init__(
FILE: cleverhans/devtools/tests/test_format.py
function update_whitelist (line 24) | def update_whitelist():
function test_format_pep8 (line 84) | def test_format_pep8():
FILE: cleverhans/devtools/version.py
function dev_version (line 11) | def dev_version():
function append_dev_version (line 27) | def append_dev_version(release_version):
FILE: cleverhans/experimental/certification/certify.py
function main (line 82) | def main(_):
FILE: cleverhans/experimental/certification/dual_formulation.py
class DualFormulation (line 29) | class DualFormulation(object):
method __init__ (line 35) | def __init__(
method create_projected_dual (line 184) | def create_projected_dual(self):
method construct_lanczos_params (line 238) | def construct_lanczos_params(self):
method set_differentiable_objective (line 291) | def set_differentiable_objective(self):
method get_h_product (line 354) | def get_h_product(self, vector, dtype=None):
method get_psd_product (line 416) | def get_psd_product(self, vector, dtype=None):
method get_full_psd_matrix (line 445) | def get_full_psd_matrix(self):
method make_m_psd (line 499) | def make_m_psd(self, original_nu, feed_dictionary):
method get_lanczos_eig (line 538) | def get_lanczos_eig(self, compute_m=True, feed_dict=None):
method compute_certificate (line 561) | def compute_certificate(self, current_step, feed_dictionary):
FILE: cleverhans/experimental/certification/nn.py
class NeuralNetwork (line 15) | class NeuralNetwork(object):
method __init__ (line 20) | def __init__(
method forward_pass (line 132) | def forward_pass(self, vector, layer_index, is_transpose=False, is_abs...
function load_network_from_checkpoint (line 195) | def load_network_from_checkpoint(checkpoint, model_json, input_shape=None):
FILE: cleverhans/experimental/certification/optimization.py
class Optimization (line 21) | class Optimization(object):
method __init__ (line 24) | def __init__(self, dual_formulation_object, sess, optimization_params):
method tf_min_eig_vec (line 58) | def tf_min_eig_vec(self):
method tf_smooth_eig_vec (line 66) | def tf_smooth_eig_vec(self):
method get_min_eig_vec_proxy (line 84) | def get_min_eig_vec_proxy(self, use_tf_eig=False):
method get_scipy_eig_vec (line 117) | def get_scipy_eig_vec(self):
method prepare_for_optimization (line 151) | def prepare_for_optimization(self):
method run_one_step (line 257) | def run_one_step(
method run_optimization (line 363) | def run_optimization(self):
FILE: cleverhans/experimental/certification/tests/dual_formulation_test.py
class DualFormulationTest (line 16) | class DualFormulationTest(unittest.TestCase):
method test_init (line 17) | def test_init(self):
method test_set_differentiable_objective (line 62) | def test_set_differentiable_objective(self):
method test_get_full_psd_matrix (line 112) | def test_get_full_psd_matrix(self):
method test_get_psd_product (line 159) | def test_get_psd_product(self):
FILE: cleverhans/experimental/certification/tests/nn_test.py
class NeuralNetworkTest (line 15) | class NeuralNetworkTest(unittest.TestCase):
method test_init (line 16) | def test_init(self):
method test_forward_pass (line 38) | def test_forward_pass(self):
FILE: cleverhans/experimental/certification/tests/optimization_test.py
class OptimizationTest (line 15) | class OptimizationTest(tf.test.TestCase):
method prepare_dual_object (line 18) | def prepare_dual_object(self):
method test_init (line 100) | def test_init(self):
method test_get_min_eig_vec_proxy (line 122) | def test_get_min_eig_vec_proxy(self):
method test_optimization (line 198) | def test_optimization(self):
FILE: cleverhans/experimental/certification/tests/utils_test.py
class UtilsTest (line 20) | class UtilsTest(tf.test.TestCase):
method test_minimum_eigen_vector (line 21) | def test_minimum_eigen_vector(self):
method test_tf_lanczos_smallest_eigval (line 37) | def test_tf_lanczos_smallest_eigval(self):
FILE: cleverhans/experimental/certification/utils.py
function diag (line 11) | def diag(diag_elements):
function initialize_dual (line 23) | def initialize_dual(
function eig_one_step (line 138) | def eig_one_step(current_vector, learning_rate, vector_prod_fn):
function minimum_eigen_vector (line 206) | def minimum_eigen_vector(x, num_steps, learning_rate, vector_prod_fn):
function tf_lanczos_smallest_eigval (line 228) | def tf_lanczos_smallest_eigval(
FILE: cleverhans/jax/attacks/fast_gradient_method.py
function fast_gradient_method (line 8) | def fast_gradient_method(
FILE: cleverhans/jax/attacks/projected_gradient_descent.py
function projected_gradient_descent (line 7) | def projected_gradient_descent(
FILE: cleverhans/jax/utils.py
function one_hot (line 4) | def one_hot(x, k, dtype=np.float32):
function partial_flatten (line 9) | def partial_flatten(x):
function clip_eta (line 14) | def clip_eta(eta, norm, eps):
FILE: cleverhans/plot/image.py
function show (line 14) | def show(ndarray, min_val=None, max_val=None):
function save (line 33) | def save(path, ndarray, min_val=None, max_val=None):
function as_pil (line 48) | def as_pil(ndarray, min_val=None, max_val=None):
function make_grid (line 113) | def make_grid(image_batch):
FILE: cleverhans/plot/pyplot_image.py
function pair_visual (line 10) | def pair_visual(original, adversarial, figure=None):
function grid_visual (line 53) | def grid_visual(data):
function get_logits_over_interval (line 86) | def get_logits_over_interval(
function linear_extrapolation_plot (line 137) | def linear_extrapolation_plot(
FILE: cleverhans/plot/save_pdf.py
function save_pdf (line 8) | def save_pdf(path):
FILE: cleverhans/plot/success_fail.py
function plot_report_from_path (line 19) | def plot_report_from_path(
function plot_report (line 69) | def plot_report(
function make_curve (line 128) | def make_curve(report, success_name, fail_names):
FILE: cleverhans/tf2/attacks/basic_iterative_method.py
function basic_iterative_method (line 8) | def basic_iterative_method(
FILE: cleverhans/tf2/attacks/carlini_wagner_l2.py
function carlini_wagner_l2 (line 8) | def carlini_wagner_l2(model_fn, x, **kwargs):
class CarliniWagnerL2Exception (line 16) | class CarliniWagnerL2Exception(Exception):
class CarliniWagnerL2 (line 20) | class CarliniWagnerL2(object):
method __init__ (line 21) | def __init__(
method attack (line 100) | def attack(self, x):
method _attack (line 114) | def _attack(self, x):
method attack_step (line 275) | def attack_step(self, x, y, modifier, const):
method gradient (line 282) | def gradient(self, x, y, modifier, const):
function l2 (line 304) | def l2(x, y):
function loss_fn (line 309) | def loss_fn(
function clip_tanh (line 340) | def clip_tanh(x, clip_min, clip_max):
FILE: cleverhans/tf2/attacks/fast_gradient_method.py
function fast_gradient_method (line 9) | def fast_gradient_method(
FILE: cleverhans/tf2/attacks/madry_et_al.py
function madry_et_al (line 8) | def madry_et_al(
FILE: cleverhans/tf2/attacks/momentum_iterative_method.py
function momentum_iterative_method (line 10) | def momentum_iterative_method(
function loss_fn (line 112) | def loss_fn(labels, logits):
FILE: cleverhans/tf2/attacks/projected_gradient_descent.py
function projected_gradient_descent (line 10) | def projected_gradient_descent(
FILE: cleverhans/tf2/attacks/spsa.py
function spsa (line 8) | def spsa(
class SPSAAdam (line 83) | class SPSAAdam(tf.optimizers.Adam):
method __init__ (line 90) | def __init__(
method _get_delta (line 105) | def _get_delta(self, x, delta):
method _compute_gradients (line 117) | def _compute_gradients(self, loss_fn, x):
method _apply_gradients (line 166) | def _apply_gradients(self, grads, x, optim_state):
method init_state (line 196) | def init_state(self, x):
method minimize (line 205) | def minimize(self, loss_fn, x, optim_state):
function margin_logit_loss (line 220) | def margin_logit_loss(model_logits, label, nb_classes=10):
function _project_perturbation (line 248) | def _project_perturbation(
function projected_optimization (line 279) | def projected_optimization(
FILE: cleverhans/tf2/utils.py
function clip_eta (line 5) | def clip_eta(eta, norm, eps):
function random_exponential (line 39) | def random_exponential(shape, rate=1.0, dtype=tf.float32, seed=None):
function random_laplace (line 52) | def random_laplace(shape, loc=0.0, scale=1.0, dtype=tf.float32, seed=None):
function random_lp_vector (line 68) | def random_lp_vector(shape, ord, eps, dtype=tf.float32, seed=None):
function get_or_guess_labels (line 120) | def get_or_guess_labels(model_fn, x, y=None, targeted=False):
function set_with_mask (line 158) | def set_with_mask(x, x_other, mask):
function compute_gradient (line 171) | def compute_gradient(model_fn, loss_fn, x, y, targeted):
function optimize_linear (line 198) | def optimize_linear(grad, eps, norm=np.inf):
FILE: cleverhans/torch/attacks/carlini_wagner_l2.py
function carlini_wagner_l2 (line 8) | def carlini_wagner_l2(
FILE: cleverhans/torch/attacks/fast_gradient_method.py
function fast_gradient_method (line 8) | def fast_gradient_method(
FILE: cleverhans/torch/attacks/hop_skip_jump_attack.py
function hop_skip_jump_attack (line 8) | def hop_skip_jump_attack(
function compute_distance (line 216) | def compute_distance(x_ori, x_pert, constraint=2):
function approximate_gradient (line 225) | def approximate_gradient(
function project (line 262) | def project(original_image, perturbed_images, alphas, shape, constraint):
function binary_search_batch (line 274) | def binary_search_batch(
function initialize (line 325) | def initialize(decision_function, sample, shape, clip_min, clip_max):
function geometric_progression_for_stepsize (line 362) | def geometric_progression_for_stepsize(
function select_delta (line 381) | def select_delta(
FILE: cleverhans/torch/attacks/noise.py
function noise (line 9) | def noise(x, eps=0.3, order=np.inf, clip_min=None, clip_max=None):
FILE: cleverhans/torch/attacks/projected_gradient_descent.py
function projected_gradient_descent (line 9) | def projected_gradient_descent(
FILE: cleverhans/torch/attacks/semantic.py
function semantic (line 6) | def semantic(x, center=True, max_val=1.0):
FILE: cleverhans/torch/attacks/sparse_l1_descent.py
function sparse_l1_descent (line 8) | def sparse_l1_descent(
FILE: cleverhans/torch/attacks/spsa.py
function spsa (line 8) | def spsa(
function _project_perturbation (line 171) | def _project_perturbation(
function _compute_spsa_gradient (line 186) | def _compute_spsa_gradient(loss_fn, x, delta, samples, iters):
function _margin_logit_loss (line 214) | def _margin_logit_loss(logits, labels):
FILE: cleverhans/torch/tests/test_attacks.py
class TrivialModel (line 22) | class TrivialModel(torch.nn.Module):
method __init__ (line 23) | def __init__(self):
method forward (line 27) | def forward(self, x, **kwargs):
class SimpleModel (line 31) | class SimpleModel(torch.nn.Module):
method __init__ (line 32) | def __init__(self):
method forward (line 37) | def forward(self, x):
class DummyModel (line 44) | class DummyModel(torch.nn.Module):
method __init__ (line 45) | def __init__(self, n_features):
method forward (line 53) | def forward(self, x):
class CommonAttackProperties (line 58) | class CommonAttackProperties(CleverHansTest):
method setUp (line 59) | def setUp(self):
method help_adv_examples_success_rate (line 70) | def help_adv_examples_success_rate(self, model, x, rate=0.5, **kwargs):
method help_targeted_adv_examples_success_rate (line 77) | def help_targeted_adv_examples_success_rate(self, model, x, rate=0.7, ...
class TestFastGradientMethod (line 87) | class TestFastGradientMethod(CommonAttackProperties):
method setUp (line 88) | def setUp(self):
method test_invalid_input (line 94) | def test_invalid_input(self):
method test_invalid_eps (line 109) | def test_invalid_eps(self):
method test_eps_equals_zero (line 120) | def test_eps_equals_zero(self):
method test_eps (line 126) | def test_eps(self):
method test_clips (line 134) | def test_clips(self):
method test_invalid_clips (line 149) | def test_invalid_clips(self):
method test_adv_example_success_rate_linf (line 164) | def test_adv_example_success_rate_linf(self):
method test_targeted_adv_example_success_rate_linf (line 171) | def test_targeted_adv_example_success_rate_linf(self):
method test_adv_example_success_rate_l1 (line 176) | def test_adv_example_success_rate_l1(self):
method test_targeted_adv_example_success_rate_l1 (line 181) | def test_targeted_adv_example_success_rate_l1(self):
method test_adv_example_success_rate_l2 (line 186) | def test_adv_example_success_rate_l2(self):
method test_targeted_adv_example_success_rate_l2 (line 191) | def test_targeted_adv_example_success_rate_l2(self):
class TestProjectedGradientMethod (line 197) | class TestProjectedGradientMethod(CommonAttackProperties):
method setUp (line 198) | def setUp(self):
method test_invalid_input (line 209) | def test_invalid_input(self):
method test_invalid_eps (line 241) | def test_invalid_eps(self):
method test_invalid_eps_iter (line 266) | def test_invalid_eps_iter(self):
method test_eps_equals_zero (line 291) | def test_eps_equals_zero(self):
method test_eps_iter_equals_zero (line 317) | def test_eps_iter_equals_zero(self):
method test_invalid_clips (line 343) | def test_invalid_clips(self):
method test_adv_example_success_rate_linf (line 374) | def test_adv_example_success_rate_linf(self):
method test_targeted_adv_example_success_rate_linf (line 381) | def test_targeted_adv_example_success_rate_linf(self):
method test_adv_example_success_rate_l1 (line 386) | def test_adv_example_success_rate_l1(self):
method test_targeted_adv_example_success_rate_l1 (line 399) | def test_targeted_adv_example_success_rate_l1(self):
method test_adv_example_success_rate_l2 (line 412) | def test_adv_example_success_rate_l2(self):
method test_targeted_adv_example_success_rate_l2 (line 417) | def test_targeted_adv_example_success_rate_l2(self):
method test_do_not_reach_lp_boundary (line 422) | def test_do_not_reach_lp_boundary(self):
method test_attack_strength (line 455) | def test_attack_strength(self):
method test_eps (line 474) | def test_eps(self):
method test_clip_eta (line 481) | def test_clip_eta(self):
method test_clips (line 485) | def test_clips(self):
method test_attack_does_not_cache_graph_computation_for_nb_iter (line 516) | def test_attack_does_not_cache_graph_computation_for_nb_iter(self):
method test_multiple_initial_random_step (line 520) | def test_multiple_initial_random_step(self):
class TestCarliniWagnerL2 (line 548) | class TestCarliniWagnerL2(CommonAttackProperties):
method setUp (line 549) | def setUp(self):
method test_adv_example_success_rate (line 559) | def test_adv_example_success_rate(self):
method test_targeted_adv_example_success_rate (line 569) | def test_targeted_adv_example_success_rate(self):
method test_adv_examples_clipped_successfully (line 579) | def test_adv_examples_clipped_successfully(self):
method test_high_confidence_adv_example (line 590) | def test_high_confidence_adv_example(self):
method test_high_confidence_targeted_adv_example (line 617) | def test_high_confidence_targeted_adv_example(self):
class TestSPSA (line 646) | class TestSPSA(CommonAttackProperties):
method setUp (line 647) | def setUp(self):
method test_invalid_input (line 659) | def test_invalid_input(self):
method test_invalid_eps (line 673) | def test_invalid_eps(self):
method test_eps_equals_zero (line 678) | def test_eps_equals_zero(self):
method test_invalid_clips (line 683) | def test_invalid_clips(self):
method test_adv_example_success_rate_linf (line 695) | def test_adv_example_success_rate_linf(self):
method test_targeted_adv_example_success_rate_linf (line 700) | def test_targeted_adv_example_success_rate_linf(self):
method test_adv_example_success_rate_l1 (line 703) | def test_adv_example_success_rate_l1(self):
method test_targeted_adv_example_success_rate_l1 (line 714) | def test_targeted_adv_example_success_rate_l1(self):
method test_adv_example_success_rate_l2 (line 725) | def test_adv_example_success_rate_l2(self):
method test_targeted_adv_example_success_rate_l2 (line 728) | def test_targeted_adv_example_success_rate_l2(self):
method test_attack_strength (line 731) | def test_attack_strength(self):
method test_eps (line 748) | def test_eps(self):
method test_clips (line 755) | def test_clips(self):
class TestHopSkipJumpAttack (line 770) | class TestHopSkipJumpAttack(CommonAttackProperties):
method setUp (line 771) | def setUp(self):
method test_generate_np_untargeted_l2 (line 775) | def test_generate_np_untargeted_l2(self):
method test_generate_untargeted_linf (line 791) | def test_generate_untargeted_linf(self):
method test_generate_np_targeted_linf (line 807) | def test_generate_np_targeted_linf(self):
method test_generate_targeted_l2 (line 836) | def test_generate_targeted_l2(self):
class TestSparseL1Descent (line 868) | class TestSparseL1Descent(CommonAttackProperties):
method setUp (line 869) | def setUp(self):
method generate_adversarial_examples (line 873) | def generate_adversarial_examples(self, **kwargs):
method generate_targeted_adversarial_examples (line 884) | def generate_targeted_adversarial_examples(self, **kwargs):
method test_invalid_input (line 902) | def test_invalid_input(self):
method test_gives_adversarial_example (line 907) | def test_gives_adversarial_example(self):
method test_targeted_gives_adversarial_example (line 914) | def test_targeted_gives_adversarial_example(self):
method test_can_be_called_with_different_eps (line 921) | def test_can_be_called_with_different_eps(self):
method test_clip_works_as_expected (line 928) | def test_clip_works_as_expected(self):
method test_do_not_reach_lp_boundary (line 941) | def test_do_not_reach_lp_boundary(self):
method test_generate_np_gives_clipped_adversarial_examples (line 952) | def test_generate_np_gives_clipped_adversarial_examples(self):
method test_clip_eta (line 965) | def test_clip_eta(self):
method test_attack_strength (line 973) | def test_attack_strength(self):
method test_grad_clip (line 987) | def test_grad_clip(self):
method test_sparsity (line 1006) | def test_sparsity(self):
method test_grad_sparsity_checks (line 1024) | def test_grad_sparsity_checks(self):
FILE: cleverhans/torch/tests/test_utils.py
class TestOptimizeLinear (line 9) | class TestOptimizeLinear(CleverHansTest):
method setUp (line 14) | def setUp(self):
method test_optimize_linear_linf (line 23) | def test_optimize_linear_linf(self):
method test_optimize_linear_l2 (line 32) | def test_optimize_linear_l2(self):
method test_optimize_linear_l1 (line 41) | def test_optimize_linear_l1(self):
method test_optimize_linear_l1_ties (line 50) | def test_optimize_linear_l1_ties(self):
method test_optimize_linear_linf_satisfies_norm_constraint (line 59) | def test_optimize_linear_linf_satisfies_norm_constraint(self):
method test_optimize_linear_l1_satisfies_norm_constraint (line 64) | def test_optimize_linear_l1_satisfies_norm_constraint(self):
method test_optimize_linear_l2_satisfies_norm_constraint (line 70) | def test_optimize_linear_l2_satisfies_norm_constraint(self):
method test_clip_eta_linf (line 93) | def test_clip_eta_linf(self):
method test_clip_eta_l1 (line 98) | def test_clip_eta_l1(self):
method test_clip_eta_l2 (line 108) | def test_clip_eta_l2(self):
FILE: cleverhans/torch/utils.py
function clip_eta (line 8) | def clip_eta(eta, norm, eps):
function get_or_guess_labels (line 42) | def get_or_guess_labels(model, x, **kwargs):
function optimize_linear (line 69) | def optimize_linear(grad, eps, norm=np.inf):
function zero_out_clipped_grads (line 127) | def zero_out_clipped_grads(grad, x, clip_min, clip_max):
FILE: cleverhans/utils.py
class _ArgsWrapper (line 40) | class _ArgsWrapper(object):
method __init__ (line 46) | def __init__(self, args):
method __getattr__ (line 51) | def __getattr__(self, name):
class AccuracyReport (line 55) | class AccuracyReport(object):
method __init__ (line 63) | def __init__(self):
function batch_indices (line 76) | def batch_indices(batch_nb, data_length, batch_size):
function other_classes (line 98) | def other_classes(nb_classes, class_ind):
function to_categorical (line 115) | def to_categorical(y, nb_classes, num_classes=None):
function random_targets (line 144) | def random_targets(gt, nb_classes):
function pair_visual (line 184) | def pair_visual(*args, **kwargs):
function grid_visual (line 196) | def grid_visual(*args, **kwargs):
function get_logits_over_interval (line 208) | def get_logits_over_interval(*args, **kwargs):
function linear_extrapolation_plot (line 224) | def linear_extrapolation_plot(*args, **kwargs):
function set_log_level (line 240) | def set_log_level(level, name="cleverhans"):
function get_log_level (line 250) | def get_log_level(name="cleverhans"):
class TemporaryLogLevel (line 258) | class TemporaryLogLevel(object):
method __init__ (line 267) | def __init__(self, level, name):
method __enter__ (line 271) | def __enter__(self):
method __exit__ (line 275) | def __exit__(self, type, value, traceback):
function create_logger (line 280) | def create_logger(name):
function deterministic_dict (line 299) | def deterministic_dict(normal_dict):
function ordered_union (line 309) | def ordered_union(l1, l2):
function safe_zip (line 325) | def safe_zip(*args):
function shell_call (line 339) | def shell_call(command, **kwargs):
function deep_copy (line 377) | def deep_copy(numpy_dict):
FILE: cleverhans_v3.1.0/cleverhans/attack_bundling.py
function single_run_max_confidence_recipe (line 43) | def single_run_max_confidence_recipe(
function basic_max_confidence_recipe (line 130) | def basic_max_confidence_recipe(
function fixed_max_confidence_recipe (line 215) | def fixed_max_confidence_recipe(
function random_search_max_confidence_recipe (line 302) | def random_search_max_confidence_recipe(
class AttackConfig (line 346) | class AttackConfig(object):
method __init__ (line 355) | def __init__(self, attack, params=None, name=None, pass_y=False):
method __str__ (line 365) | def __str__(self):
method __repr__ (line 370) | def __repr__(self):
function bundle_attacks (line 374) | def bundle_attacks(
function bundle_attacks_with_goal (line 461) | def bundle_attacks_with_goal(
function run_batch_with_goal (line 524) | def run_batch_with_goal(
function save (line 606) | def save(criteria, report, report_path, adv_x_val):
class AttackGoal (line 624) | class AttackGoal(object):
method start (line 640) | def start(self, run_counts):
method get_criteria (line 648) | def get_criteria(self, sess, model, advx, y, batch_size=BATCH_SIZE):
method extra_criteria (line 673) | def extra_criteria(self):
method request_examples (line 680) | def request_examples(self, attack_config, criteria, run_counts, batch_...
method is_satisfied (line 688) | def is_satisfied(self, criteria, run_counts):
method print_progress (line 694) | def print_progress(self, criteria, run_counts):
method get_attack_config (line 703) | def get_attack_config(self, attack_configs, run_counts, criteria):
method new_wins (line 711) | def new_wins(self, orig_criteria, orig_idx, new_criteria, new_idx):
class Misclassify (line 727) | class Misclassify(AttackGoal):
method __init__ (line 749) | def __init__(self, new_work_goal=None, break_ties="wrong_confidence"):
method start (line 757) | def start(self, run_counts):
method is_satisfied (line 764) | def is_satisfied(self, criteria, run_counts):
method print_progress (line 786) | def print_progress(self, criteria, run_counts):
method filter (line 815) | def filter(self, run_counts, criteria):
method get_attack_config (line 826) | def get_attack_config(self, attack_configs, run_counts, criteria):
method extra_criteria (line 836) | def extra_criteria(self):
method request_examples (line 842) | def request_examples(self, attack_config, criteria, run_counts, batch_...
method new_wins (line 873) | def new_wins(self, orig_criteria, orig_idx, new_criteria, new_idx):
class MaxConfidence (line 889) | class MaxConfidence(AttackGoal):
method __init__ (line 915) | def __init__(self, t=1.0, new_work_goal=None):
method filter (line 925) | def filter(self, run_counts, criteria):
method extra_criteria (line 936) | def extra_criteria(self):
method is_satisfied (line 939) | def is_satisfied(self, criteria, run_counts):
method print_progress (line 959) | def print_progress(self, criteria, run_counts):
method get_attack_config (line 991) | def get_attack_config(self, attack_configs, run_counts, criteria):
method start (line 1002) | def start(self, run_counts):
method request_examples (line 1018) | def request_examples(self, attack_config, criteria, run_counts, batch_...
method new_wins (line 1047) | def new_wins(self, orig_criteria, orig_idx, new_criteria, new_idx):
function unfinished_attack_configs (line 1053) | def unfinished_attack_configs(new_work_goal, work_before, run_counts, lo...
class _CriteriaFactory (line 1101) | class _CriteriaFactory(object):
method __init__ (line 1106) | def __init__(self, model, extra_criteria_factory=None):
method __hash__ (line 1116) | def __hash__(self):
method __eq__ (line 1121) | def __eq__(self, other):
method __call__ (line 1130) | def __call__(self):
class _ExtraCriteriaFactory (line 1148) | class _ExtraCriteriaFactory(object):
method __init__ (line 1153) | def __init__(self, properties_to_hash=None):
method __hash__ (line 1156) | def __hash__(self):
method __eq__ (line 1161) | def __eq__(self, other):
method __call__ (line 1168) | def __call__(self, x_batch, y_batch, predictions, correct, max_probs):
class _WrongConfidenceFactory (line 1172) | class _WrongConfidenceFactory(_ExtraCriteriaFactory):
method __call__ (line 1173) | def __call__(self, x_batch, y_batch, predictions, correct, max_probs):
function bundle_examples_with_goal (line 1178) | def bundle_examples_with_goal(
function spsa_max_confidence_recipe (line 1252) | def spsa_max_confidence_recipe(
FILE: cleverhans_v3.1.0/cleverhans/attacks/attack.py
class Attack (line 19) | class Attack(object):
method __init__ (line 26) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 87) | def generate(self, x, **kwargs):
method construct_graph (line 121) | def construct_graph(self, fixed, feedable, x_val, hash_key):
method generate_np (line 178) | def generate_np(self, x_val, **kwargs):
method construct_variables (line 212) | def construct_variables(self, kwargs):
method get_or_guess_labels (line 275) | def get_or_guess_labels(self, x, kwargs):
method parse_params (line 304) | def parse_params(self, params=None):
function arg_type (line 320) | def arg_type(arg_names, kwargs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/basic_iterative_method.py
class BasicIterativeMethod (line 8) | class BasicIterativeMethod(ProjectedGradientDescent):
method __init__ (line 13) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/carlini_wagner_l2.py
class CarliniWagnerL2 (line 21) | class CarliniWagnerL2(Attack):
method __init__ (line 39) | def __init__(self, model, sess, dtypestr="float32", **kwargs):
method generate (line 65) | def generate(self, x, **kwargs):
method parse_params (line 105) | def parse_params(
function ZERO (line 166) | def ZERO():
class CWL2 (line 170) | class CWL2(object):
method __init__ (line 171) | def __init__(
method attack (line 308) | def attack(self, imgs, targets):
method attack_batch (line 326) | def attack_batch(self, imgs, labs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/deep_fool.py
class DeepFool (line 22) | class DeepFool(Attack):
method __init__ (line 35) | def __init__(self, model, sess, dtypestr="float32", **kwargs):
method generate (line 53) | def generate(self, x, **kwargs):
method parse_params (line 102) | def parse_params(
function deepfool_batch (line 135) | def deepfool_batch(
function deepfool_attack (line 191) | def deepfool_attack(
FILE: cleverhans_v3.1.0/cleverhans/attacks/elastic_net_method.py
function ZERO (line 21) | def ZERO():
class ElasticNetMethod (line 25) | class ElasticNetMethod(Attack):
method __init__ (line 41) | def __init__(self, model, sess, dtypestr="float32", **kwargs):
method generate (line 69) | def generate(self, x, **kwargs):
method parse_params (line 111) | def parse_params(
class EAD (line 187) | class EAD(object):
method __init__ (line 188) | def __init__(
method attack (line 410) | def attack(self, imgs, targets):
method attack_batch (line 443) | def attack_batch(self, imgs, labs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/fast_feature_adversaries.py
class FastFeatureAdversaries (line 16) | class FastFeatureAdversaries(Attack):
method __init__ (line 33) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method parse_params (line 43) | def parse_params(
method attack_single_step (line 90) | def attack_single_step(self, x, eta, g_feat):
method generate (line 133) | def generate(self, x, g, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/fast_gradient_method.py
class FastGradientMethod (line 15) | class FastGradientMethod(Attack):
method __init__ (line 29) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 40) | def generate(self, x, **kwargs):
method parse_params (line 66) | def parse_params(
function fgm (line 136) | def fgm(
function optimize_linear (line 224) | def optimize_linear(grad, eps, ord=np.inf):
FILE: cleverhans_v3.1.0/cleverhans/attacks/hop_skip_jump_attack.py
class HopSkipJumpAttack (line 18) | class HopSkipJumpAttack(Attack):
method __init__ (line 35) | def __init__(self, model, sess, dtypestr="float32", **kwargs):
method generate (line 61) | def generate(self, x, **kwargs):
method generate_np (line 127) | def generate_np(self, x, **kwargs):
method parse_params (line 165) | def parse_params(
method _hsja (line 221) | def _hsja(self, sample, target_label, target_image):
function BoundaryAttackPlusPlus (line 374) | def BoundaryAttackPlusPlus(model, sess, dtypestr="float32", **kwargs):
function _check_first_dimension (line 384) | def _check_first_dimension(x, tensor_name):
function clip_image (line 394) | def clip_image(image, clip_min, clip_max):
function compute_distance (line 399) | def compute_distance(x_ori, x_pert, constraint="l2"):
function approximate_gradient (line 408) | def approximate_gradient(
function project (line 445) | def project(original_image, perturbed_images, alphas, shape, constraint):
function binary_search_batch (line 458) | def binary_search_batch(
function initialize (line 509) | def initialize(decision_function, sample, shape, clip_min, clip_max):
function geometric_progression_for_stepsize (line 544) | def geometric_progression_for_stepsize(
function select_delta (line 563) | def select_delta(
FILE: cleverhans_v3.1.0/cleverhans/attacks/lbfgs.py
class LBFGS (line 17) | class LBFGS(Attack):
method __init__ (line 28) | def __init__(self, model, sess, dtypestr="float32", **kwargs):
method generate (line 45) | def generate(self, x, **kwargs):
method parse_params (line 90) | def parse_params(
class LBFGS_impl (line 124) | class LBFGS_impl(object):
method __init__ (line 146) | def __init__(
method attack (line 194) | def attack(self, x_val, targets):
FILE: cleverhans_v3.1.0/cleverhans/attacks/madry_et_al.py
class MadryEtAl (line 8) | class MadryEtAl(ProjectedGradientDescent):
method __init__ (line 13) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/max_confidence.py
class MaxConfidence (line 12) | class MaxConfidence(Attack):
method __init__ (line 28) | def __init__(self, model, sess=None, base_attacker=None):
method generate (line 42) | def generate(self, x, **kwargs):
method parse_params (line 56) | def parse_params(self, y=None, nb_classes=10, **kwargs):
method attack (line 66) | def attack(self, x, true_y):
method attack_class (line 114) | def attack_class(self, x, target_y):
FILE: cleverhans_v3.1.0/cleverhans/attacks/momentum_iterative_method.py
class MomentumIterativeMethod (line 15) | class MomentumIterativeMethod(Attack):
method __init__ (line 29) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 53) | def generate(self, x, **kwargs):
method parse_params (line 141) | def parse_params(
FILE: cleverhans_v3.1.0/cleverhans/attacks/noise.py
class Noise (line 12) | class Noise(Attack):
method __init__ (line 31) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 37) | def generate(self, x, **kwargs):
method parse_params (line 57) | def parse_params(self, eps=0.3, ord=np.inf, clip_min=None, clip_max=No...
FILE: cleverhans_v3.1.0/cleverhans/attacks/projected_gradient_descent.py
class ProjectedGradientDescent (line 17) | class ProjectedGradientDescent(Attack):
method __init__ (line 34) | def __init__(
method generate (line 64) | def generate(self, x, **kwargs):
method parse_params (line 202) | def parse_params(
FILE: cleverhans_v3.1.0/cleverhans/attacks/saliency_map_method.py
class SaliencyMapMethod (line 16) | class SaliencyMapMethod(Attack):
method __init__ (line 30) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 48) | def generate(self, x, **kwargs):
method parse_params (line 97) | def parse_params(
function jsma_batch (line 135) | def jsma_batch(*args, **kwargs):
function jsma_symbolic (line 141) | def jsma_symbolic(x, y_target, model, theta, gamma, clip_min, clip_max):
FILE: cleverhans_v3.1.0/cleverhans/attacks/semantic.py
class Semantic (line 7) | class Semantic(Attack):
method __init__ (line 27) | def __init__(
method generate (line 37) | def generate(self, x, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/attacks/sparse_l1_descent.py
class SparseL1Descent (line 16) | class SparseL1Descent(Attack):
method __init__ (line 36) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 57) | def generate(self, x, **kwargs):
method parse_params (line 170) | def parse_params(
function sparse_l1_descent (line 259) | def sparse_l1_descent(
FILE: cleverhans_v3.1.0/cleverhans/attacks/spatial_transformation_method.py
class SpatialTransformationMethod (line 8) | class SpatialTransformationMethod(Attack):
method __init__ (line 13) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 42) | def generate(self, x, **kwargs):
method parse_params (line 72) | def parse_params(
FILE: cleverhans_v3.1.0/cleverhans/attacks/spsa.py
class SPSA (line 19) | class SPSA(Attack):
method __init__ (line 37) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 52) | def generate(
method generate_np (line 196) | def generate_np(self, x_val, **kwargs):
function _project_perturbation (line 227) | def _project_perturbation(
class TensorOptimizer (line 258) | class TensorOptimizer(object):
method _compute_gradients (line 270) | def _compute_gradients(self, loss_fn, x, unused_optim_state):
method _apply_gradients (line 297) | def _apply_gradients(self, grads, x, optim_state):
method minimize (line 311) | def minimize(self, loss_fn, x, optim_state):
method init_state (line 326) | def init_state(self, x):
class TensorGradientDescent (line 338) | class TensorGradientDescent(TensorOptimizer):
method __init__ (line 341) | def __init__(self, lr):
method init_state (line 344) | def init_state(self, x):
method _apply_gradients (line 347) | def _apply_gradients(self, grads, x, optim_state):
class TensorAdam (line 354) | class TensorAdam(TensorOptimizer):
method __init__ (line 357) | def __init__(self, lr=0.001, beta1=0.9, beta2=0.999, epsilon=1e-9):
method init_state (line 363) | def init_state(self, x):
method _apply_gradients (line 373) | def _apply_gradients(self, grads, x, optim_state):
class SPSAAdam (line 394) | class SPSAAdam(TensorAdam):
method __init__ (line 401) | def __init__(
method _get_delta (line 416) | def _get_delta(self, x, delta):
method _compute_gradients (line 428) | def _compute_gradients(self, loss_fn, x, unused_optim_state):
function margin_logit_loss (line 467) | def margin_logit_loss(model_logits, label, nb_classes=10, num_classes=No...
function _apply_black_border (line 503) | def _apply_black_border(x, border_size):
function _apply_transformation (line 517) | def _apply_transformation(inputs):
function spm (line 548) | def spm(
function parallel_apply_transformations (line 619) | def parallel_apply_transformations(x, transforms, black_border_size=0):
function projected_optimization (line 648) | def projected_optimization(
FILE: cleverhans_v3.1.0/cleverhans/attacks/virtual_adversarial_method.py
class VirtualAdversarialMethod (line 17) | class VirtualAdversarialMethod(Attack):
method __init__ (line 29) | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
method generate (line 43) | def generate(self, x, **kwargs):
method parse_params (line 64) | def parse_params(
function vatm (line 113) | def vatm(
FILE: cleverhans_v3.1.0/cleverhans/attacks_tf.py
function fgsm (line 61) | def fgsm(x, predictions, eps=0.3, clip_min=None, clip_max=None):
function fgm (line 77) | def fgm(x, preds, *args, **kwargs):
function apply_perturbations (line 91) | def apply_perturbations(i, j, X, increase, theta, clip_min, clip_max):
function saliency_map (line 119) | def saliency_map(grads_target, grads_other, search_domain, increase):
function jacobian (line 171) | def jacobian(sess, x, grads, target, X, nb_features, nb_classes, feed=No...
class UnrolledOptimizer (line 206) | class UnrolledOptimizer(TensorOptimizer):
method __init__ (line 207) | def __init__(self, *args, **kwargs):
class UnrolledGradientDescent (line 215) | class UnrolledGradientDescent(TensorGradientDescent):
method __init__ (line 216) | def __init__(self, *args, **kwargs):
class UnrolledAdam (line 225) | class UnrolledAdam(TensorAdam):
method __init__ (line 226) | def __init__(self, *args, **kwargs):
function pgd_attack (line 234) | def pgd_attack(*args, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/attacks_tfe.py
class Attack (line 23) | class Attack(attacks.Attack):
method __init__ (line 32) | def __init__(self, model, dtypestr="float32"):
method construct_graph (line 49) | def construct_graph(self, **kwargs):
method generate_np (line 58) | def generate_np(self, x_val, **kwargs):
method construct_variables (line 71) | def construct_variables(self, kwargs):
class FastGradientMethod (line 81) | class FastGradientMethod(Attack, attacks.FastGradientMethod):
method __init__ (line 92) | def __init__(self, model, dtypestr="float32", **kwargs):
method generate (line 105) | def generate(self, x, **kwargs):
method fgm (line 129) | def fgm(self, x, labels, targeted=False):
class BasicIterativeMethod (line 163) | class BasicIterativeMethod(Attack, attacks.BasicIterativeMethod):
method __init__ (line 174) | def __init__(self, model, dtypestr="float32"):
FILE: cleverhans_v3.1.0/cleverhans/augmentation.py
function random_shift (line 19) | def random_shift(x, pad=(4, 4), mode="REFLECT"):
function batch_augment (line 28) | def batch_augment(x, func, device="/CPU:0"):
function random_crop_and_flip (line 40) | def random_crop_and_flip(x, pad_rows=4, pad_cols=4):
FILE: cleverhans_v3.1.0/cleverhans/canary.py
function run_canary (line 13) | def run_canary():
FILE: cleverhans_v3.1.0/cleverhans/compat.py
function _wrap (line 21) | def _wrap(f):
function reduce_function (line 49) | def reduce_function(
function softmax_cross_entropy_with_logits (line 80) | def softmax_cross_entropy_with_logits(sentinel=None, labels=None, logits...
FILE: cleverhans_v3.1.0/cleverhans/confidence_report.py
class ConfidenceReport (line 52) | class ConfidenceReport(OrderedDict):
method __init__ (line 63) | def __init__(self, iterable=None):
method __setitem__ (line 76) | def __setitem__(self, key, value):
class ConfidenceReportEntry (line 88) | class ConfidenceReportEntry(object):
method __init__ (line 99) | def __init__(self, correctness, confidence):
method __getitem__ (line 112) | def __getitem__(self, key):
method __setitem__ (line 123) | def __setitem__(self, key, value):
function make_confidence_report_bundled (line 135) | def make_confidence_report_bundled(
function print_stats (line 279) | def print_stats(correctness, confidence, name):
function make_confidence_report (line 314) | def make_confidence_report(
FILE: cleverhans_v3.1.0/cleverhans/dataset.py
class Dataset (line 42) | class Dataset(object):
method __init__ (line 48) | def __init__(self, kwargs=None):
method get_factory (line 55) | def get_factory(self):
method get_set (line 60) | def get_set(self, which_set):
method to_tensorflow (line 66) | def to_tensorflow(self):
method in_memory_dataset (line 70) | def in_memory_dataset(cls, x, y, shuffle=None, repeat=True):
class MNIST (line 85) | class MNIST(Dataset):
method __init__ (line 90) | def __init__(
method to_tensorflow (line 121) | def to_tensorflow(self, shuffle=4096):
class CIFAR10 (line 128) | class CIFAR10(Dataset):
method __init__ (line 146) | def __init__(
method to_tensorflow (line 179) | def to_tensorflow(self, shuffle=4096):
class Factory (line 187) | class Factory(object):
method __init__ (line 192) | def __init__(self, cls, kwargs):
method __call__ (line 196) | def __call__(self):
function maybe_download_file (line 201) | def maybe_download_file(url, datadir=None, force=False):
function download_and_parse_mnist_file (line 219) | def download_and_parse_mnist_file(file_name, datadir=None, force=False):
function data_mnist (line 261) | def data_mnist(
function data_cifar10 (line 310) | def data_cifar10(train_start=0, train_end=50000, test_start=0, test_end=...
FILE: cleverhans_v3.1.0/cleverhans/devtools/checks.py
class CleverHansTest (line 17) | class CleverHansTest(unittest.TestCase):
method setUp (line 20) | def setUp(self):
method tearDown (line 25) | def tearDown(self):
method assertClose (line 28) | def assertClose(self, x, y, *args, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/devtools/list_files.py
function list_files (line 6) | def list_files(suffix=""):
function _list_files (line 47) | def _list_files(path, suffix=""):
FILE: cleverhans_v3.1.0/cleverhans/devtools/mocks.py
function random_feed_dict (line 16) | def random_feed_dict(rng, placeholders):
class SimpleDataset (line 35) | class SimpleDataset(Dataset):
method __init__ (line 41) | def __init__(
FILE: cleverhans_v3.1.0/cleverhans/devtools/tests/test_format.py
function update_whitelist (line 24) | def update_whitelist():
function test_format_pep8 (line 84) | def test_format_pep8():
FILE: cleverhans_v3.1.0/cleverhans/devtools/version.py
function dev_version (line 11) | def dev_version():
function append_dev_version (line 27) | def append_dev_version(release_version):
FILE: cleverhans_v3.1.0/cleverhans/evaluation.py
function accuracy (line 18) | def accuracy(
function class_and_confidence (line 72) | def class_and_confidence(
function correctness_and_confidence (line 149) | def correctness_and_confidence(
function run_attack (line 222) | def run_attack(
function batch_eval_multi_worker (line 273) | def batch_eval_multi_worker(
function batch_eval (line 468) | def batch_eval(
class _CorrectFactory (line 549) | class _CorrectFactory(object):
method __init__ (line 555) | def __init__(self, model, attack=None, attack_params=None):
method __hash__ (line 566) | def __hash__(self):
method __eq__ (line 571) | def __eq__(self, other):
method __call__ (line 578) | def __call__(self):
class _ClassAndProbFactory (line 599) | class _ClassAndProbFactory(object):
method __init__ (line 607) | def __init__(self, model, attack=None, attack_params=None):
method __hash__ (line 618) | def __hash__(self):
method __eq__ (line 623) | def __eq__(self, other):
method __call__ (line 630) | def __call__(self):
class _CorrectAndProbFactory (line 654) | class _CorrectAndProbFactory(object):
method __init__ (line 662) | def __init__(self, model, attack=None, attack_params=None):
method __hash__ (line 673) | def __hash__(self):
method __eq__ (line 678) | def __eq__(self, other):
method __call__ (line 685) | def __call__(self):
class _AttackFactory (line 707) | class _AttackFactory(object):
method __init__ (line 719) | def __init__(self, model, attack, attack_params=None, pass_y=False):
method __hash__ (line 738) | def __hash__(self):
method __eq__ (line 743) | def __eq__(self, other):
method __call__ (line 750) | def __call__(self):
function _check_x (line 775) | def _check_x(x):
function _check_y (line 786) | def _check_y(y):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/certify.py
function main (line 82) | def main(_):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/dual_formulation.py
class DualFormulation (line 29) | class DualFormulation(object):
method __init__ (line 35) | def __init__(
method create_projected_dual (line 184) | def create_projected_dual(self):
method construct_lanczos_params (line 238) | def construct_lanczos_params(self):
method set_differentiable_objective (line 291) | def set_differentiable_objective(self):
method get_h_product (line 354) | def get_h_product(self, vector, dtype=None):
method get_psd_product (line 416) | def get_psd_product(self, vector, dtype=None):
method get_full_psd_matrix (line 445) | def get_full_psd_matrix(self):
method make_m_psd (line 499) | def make_m_psd(self, original_nu, feed_dictionary):
method get_lanczos_eig (line 538) | def get_lanczos_eig(self, compute_m=True, feed_dict=None):
method compute_certificate (line 561) | def compute_certificate(self, current_step, feed_dictionary):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/nn.py
class NeuralNetwork (line 15) | class NeuralNetwork(object):
method __init__ (line 20) | def __init__(
method forward_pass (line 132) | def forward_pass(self, vector, layer_index, is_transpose=False, is_abs...
function load_network_from_checkpoint (line 195) | def load_network_from_checkpoint(checkpoint, model_json, input_shape=None):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/optimization.py
class Optimization (line 21) | class Optimization(object):
method __init__ (line 24) | def __init__(self, dual_formulation_object, sess, optimization_params):
method tf_min_eig_vec (line 58) | def tf_min_eig_vec(self):
method tf_smooth_eig_vec (line 66) | def tf_smooth_eig_vec(self):
method get_min_eig_vec_proxy (line 84) | def get_min_eig_vec_proxy(self, use_tf_eig=False):
method get_scipy_eig_vec (line 117) | def get_scipy_eig_vec(self):
method prepare_for_optimization (line 151) | def prepare_for_optimization(self):
method run_one_step (line 257) | def run_one_step(
method run_optimization (line 363) | def run_optimization(self):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/tests/dual_formulation_test.py
class DualFormulationTest (line 16) | class DualFormulationTest(unittest.TestCase):
method test_init (line 17) | def test_init(self):
method test_set_differentiable_objective (line 62) | def test_set_differentiable_objective(self):
method test_get_full_psd_matrix (line 112) | def test_get_full_psd_matrix(self):
method test_get_psd_product (line 159) | def test_get_psd_product(self):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/tests/nn_test.py
class NeuralNetworkTest (line 15) | class NeuralNetworkTest(unittest.TestCase):
method test_init (line 16) | def test_init(self):
method test_forward_pass (line 38) | def test_forward_pass(self):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/tests/optimization_test.py
class OptimizationTest (line 15) | class OptimizationTest(tf.test.TestCase):
method prepare_dual_object (line 18) | def prepare_dual_object(self):
method test_init (line 100) | def test_init(self):
method test_get_min_eig_vec_proxy (line 122) | def test_get_min_eig_vec_proxy(self):
method test_optimization (line 198) | def test_optimization(self):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/tests/utils_test.py
class UtilsTest (line 20) | class UtilsTest(tf.test.TestCase):
method test_minimum_eigen_vector (line 21) | def test_minimum_eigen_vector(self):
method test_tf_lanczos_smallest_eigval (line 37) | def test_tf_lanczos_smallest_eigval(self):
FILE: cleverhans_v3.1.0/cleverhans/experimental/certification/utils.py
function diag (line 11) | def diag(diag_elements):
function initialize_dual (line 23) | def initialize_dual(
function eig_one_step (line 138) | def eig_one_step(current_vector, learning_rate, vector_prod_fn):
function minimum_eigen_vector (line 206) | def minimum_eigen_vector(x, num_steps, learning_rate, vector_prod_fn):
function tf_lanczos_smallest_eigval (line 228) | def tf_lanczos_smallest_eigval(
FILE: cleverhans_v3.1.0/cleverhans/initializers.py
class HeReLuNormalInitializer (line 8) | class HeReLuNormalInitializer(tf.initializers.random_normal):
method __init__ (line 13) | def __init__(self, dtype=tf.float32):
method get_config (line 16) | def get_config(self):
method __call__ (line 19) | def __call__(self, shape, dtype=None, partition_info=None):
FILE: cleverhans_v3.1.0/cleverhans/loss.py
class Loss (line 23) | class Loss(object):
method __init__ (line 30) | def __init__(self, model, hparams=None, attack=None):
method save (line 69) | def save(self, path):
method fprop (line 76) | def fprop(self, x, y):
class WeightedSum (line 89) | class WeightedSum(Loss):
method __init__ (line 94) | def __init__(self, model, terms):
method fprop (line 99) | def fprop(self, x, y, **kwargs):
class CrossEntropy (line 122) | class CrossEntropy(Loss):
method __init__ (line 135) | def __init__(
method fprop (line 154) | def fprop(self, x, y, **kwargs):
class MixUp (line 187) | class MixUp(Loss):
method __init__ (line 193) | def __init__(self, model, beta, **kwargs):
method fprop (line 198) | def fprop(self, x, y, **kwargs):
class FeaturePairing (line 214) | class FeaturePairing(Loss):
method __init__ (line 221) | def __init__(self, model, weight, attack, **kwargs):
method fprop (line 226) | def fprop(self, x, y, **kwargs):
class WeightDecay (line 244) | class WeightDecay(Loss):
method fprop (line 247) | def fprop(self, x, y, **kwargs):
class LossCrossEntropy (line 258) | class LossCrossEntropy(Loss):
method __init__ (line 264) | def __init__(self, model, smoothing=0.0, attack=None, **kwargs):
method fprop (line 276) | def fprop(self, x, y, **kwargs):
class LossFeaturePairing (line 301) | class LossFeaturePairing(Loss):
method __init__ (line 305) | def __init__(self, model, weight, attack, **kwargs):
method fprop (line 315) | def fprop(self, x, y, **kwargs):
class LossMixUp (line 334) | class LossMixUp(Loss):
method __init__ (line 338) | def __init__(self, model, beta, **kwargs):
method fprop (line 347) | def fprop(self, x, y, **kwargs):
class SNNLCrossEntropy (line 362) | class SNNLCrossEntropy(CrossEntropy):
method __init__ (line 371) | def __init__(
method pairwise_euclid_distance (line 402) | def pairwise_euclid_distance(A, B):
method pairwise_cos_distance (line 421) | def pairwise_cos_distance(A, B):
method fits (line 434) | def fits(A, B, temp, cos_distance):
method pick_probability (line 452) | def pick_probability(x, temp, cos_distance):
method same_label_mask (line 469) | def same_label_mask(y, y2):
method masked_pick_probability (line 479) | def masked_pick_probability(x, y, temp, cos_distance):
method SNNL (line 494) | def SNNL(x, y, temp, cos_distance):
method optimized_temp_SNNL (line 512) | def optimized_temp_SNNL(x, y, initial_temp, cos_distance):
method fprop (line 536) | def fprop(self, x, y, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/model.py
class Model (line 12) | class Model(object):
method __init__ (line 24) | def __init__(
method __call__ (line 40) | def __call__(self, *args, **kwargs):
method get_logits (line 63) | def get_logits(self, x, **kwargs):
method get_predicted_class (line 77) | def get_predicted_class(self, x, **kwargs):
method get_probs (line 84) | def get_probs(self, x, **kwargs):
method fprop (line 107) | def fprop(self, x, **kwargs):
method get_params (line 116) | def get_params(self):
method make_params (line 160) | def make_params(self):
method get_layer_names (line 174) | def get_layer_names(self):
method get_layer (line 178) | def get_layer(self, x, layer, **kwargs):
method make_input_placeholder (line 187) | def make_input_placeholder(self):
method make_label_placeholder (line 199) | def make_label_placeholder(self):
method __hash__ (line 211) | def __hash__(self):
method __eq__ (line 214) | def __eq__(self, other):
class CallableModelWrapper (line 218) | class CallableModelWrapper(Model):
method __init__ (line 221) | def __init__(self, callable_fn, output_layer):
method fprop (line 235) | def fprop(self, x, **kwargs):
function wrapper_warning (line 256) | def wrapper_warning():
function wrapper_warning_logits (line 282) | def wrapper_warning_logits():
class NoSuchLayerError (line 303) | class NoSuchLayerError(ValueError):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/all_convolutional.py
class ModelAllConvolutional (line 11) | class ModelAllConvolutional(NoRefModel):
method __init__ (line 17) | def __init__(self, scope, nb_classes, nb_filters, input_shape, **kwargs):
method fprop (line 28) | def fprop(self, x, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/basic_cnn.py
class ModelBasicCNN (line 18) | class ModelBasicCNN(Model):
method __init__ (line 19) | def __init__(self, scope, nb_classes, nb_filters, **kwargs):
method fprop (line 30) | def fprop(self, x, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/deep_k_nearest_neighbors/dknn.py
function make_basic_picklable_cnn (line 39) | def make_basic_picklable_cnn(
class NearestNeighbor (line 58) | class NearestNeighbor:
class BACKEND (line 59) | class BACKEND(enum.Enum):
method __init__ (line 63) | def __init__(
method _init_falconn (line 85) | def _init_falconn(
method _init_faiss (line 117) | def _init_faiss(
method _find_knns_falconn (line 130) | def _find_knns_falconn(self, x, output):
method _find_knns_faiss (line 154) | def _find_knns_faiss(self, x, output):
method add (line 167) | def add(self, x):
method find_knns (line 175) | def find_knns(self, x, output):
class DkNNModel (line 184) | class DkNNModel(Model):
method __init__ (line 185) | def __init__(
method init_lsh (line 229) | def init_lsh(self):
method find_train_knns (line 261) | def find_train_knns(self, data_activations):
method nonconformity (line 304) | def nonconformity(self, knns_labels):
method preds_conf_cred (line 329) | def preds_conf_cred(self, knns_not_in_class):
method fprop_np (line 357) | def fprop_np(self, data_np):
method fprop (line 371) | def fprop(self, x):
method calibrate (line 379) | def calibrate(self, cali_data, cali_labels):
function plot_reliability_diagram (line 412) | def plot_reliability_diagram(confidence, labels, filepath):
function get_tensorflow_session (line 482) | def get_tensorflow_session():
function dknn_tutorial (line 490) | def dknn_tutorial():
function main (line 598) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/madry_lab_challenges/cifar10_model.py
class Layer (line 19) | class Layer(object):
method get_output_shape (line 20) | def get_output_shape(self):
class ResNet (line 24) | class ResNet(NoRefModel):
method __init__ (line 27) | def __init__(self, layers, input_shape, scope=None):
method get_vars (line 55) | def get_vars(self):
method build (line 60) | def build(self, layers, input_shape):
method make_input_placeholder (line 80) | def make_input_placeholder(self):
method make_label_placeholder (line 83) | def make_label_placeholder(self):
method fprop (line 86) | def fprop(self, x, set_ref=False):
method _fprop (line 92) | def _fprop(self, x, set_ref=False):
method add_internal_summaries (line 103) | def add_internal_summaries(self):
function _stride_arr (line 107) | def _stride_arr(stride):
class Input (line 112) | class Input(Layer):
method __init__ (line 113) | def __init__(self):
method set_input_shape (line 116) | def set_input_shape(self, input_shape):
method fprop (line 128) | def fprop(self, x):
class Conv2D (line 136) | class Conv2D(Layer):
method __init__ (line 137) | def __init__(self):
method set_input_shape (line 140) | def set_input_shape(self, input_shape):
method fprop (line 155) | def fprop(self, x):
class Linear (line 206) | class Linear(Layer):
method __init__ (line 207) | def __init__(self, num_hid):
method set_input_shape (line 210) | def set_input_shape(self, input_shape):
method make_vars (line 217) | def make_vars(self):
method fprop (line 229) | def fprop(self, x):
function _batch_norm (line 234) | def _batch_norm(name, x):
function _residual (line 248) | def _residual(x, in_filter, out_filter, stride, activate_before_residual...
function _decay (line 287) | def _decay():
function _conv (line 296) | def _conv(name, x, filter_size, in_filters, out_filters, strides):
function _relu (line 309) | def _relu(x, leakiness=0.0):
function _global_avg_pool (line 314) | def _global_avg_pool(x):
class Softmax (line 319) | class Softmax(Layer):
method __init__ (line 320) | def __init__(self):
method set_input_shape (line 323) | def set_input_shape(self, shape):
method fprop (line 327) | def fprop(self, x):
class Flatten (line 331) | class Flatten(Layer):
method __init__ (line 332) | def __init__(self):
method set_input_shape (line 335) | def set_input_shape(self, shape):
method fprop (line 343) | def fprop(self, x):
function make_wresnet (line 347) | def make_wresnet(nb_classes=10, input_shape=(None, 32, 32, 3), scope=None):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/madry_lab_challenges/make_cifar10_joblib.py
function main (line 27) | def main(argv):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/soft_nearest_neighbor_loss/SNNL_regularized_model.py
class ModelBasicCNN (line 18) | class ModelBasicCNN(Model):
method __init__ (line 19) | def __init__(self, scope, nb_classes, nb_filters, **kwargs):
method make_input_placeholder (line 28) | def make_input_placeholder(self):
method get_layer_names (line 31) | def get_layer_names(self):
method fprop (line 34) | def fprop(self, x, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/model_zoo/soft_nearest_neighbor_loss/SNNL_regularized_train.py
function SNNL_example (line 39) | def SNNL_example(
function main (line 175) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans/picklable_model.py
class PicklableModel (line 25) | class PicklableModel(Model):
method __init__ (line 37) | def __init__(self):
method get_params (line 41) | def get_params(self):
class MLP (line 47) | class MLP(PicklableModel):
method __hash__ (line 52) | def __hash__(self):
method __init__ (line 55) | def __init__(self, layers, input_shape):
method get_params (line 89) | def get_params(self):
method fprop (line 95) | def fprop(self, x=None, given=None, **kwargs):
method make_input_placeholder (line 139) | def make_input_placeholder(self):
method make_label_placeholder (line 142) | def make_label_placeholder(self):
class Layer (line 149) | class Layer(PicklableModel):
method __init__ (line 150) | def __init__(self, name=None, parent=None):
method get_output_shape (line 156) | def get_output_shape(self):
class Linear (line 160) | class Linear(Layer):
method __init__ (line 170) | def __init__(
method set_input_shape (line 186) | def set_input_shape(self, input_shape):
method fprop (line 207) | def fprop(self, x, **kwargs):
method get_params (line 213) | def get_params(self):
class Conv2D (line 220) | class Conv2D(Layer):
method __init__ (line 240) | def __init__(
method set_input_shape (line 255) | def set_input_shape(self, input_shape):
method fprop (line 291) | def fprop(self, x, **kwargs):
method get_params (line 300) | def get_params(self):
class ReLU (line 307) | class ReLU(Layer):
method __init__ (line 308) | def __init__(self, leak=0.0, **kwargs):
method set_input_shape (line 312) | def set_input_shape(self, shape):
method get_output_shape (line 316) | def get_output_shape(self):
method fprop (line 319) | def fprop(self, x, **kwargs):
method get_params (line 339) | def get_params(self):
class Sigmoid (line 343) | class Sigmoid(Layer):
method __init__ (line 344) | def __init__(self, **kwargs):
method set_input_shape (line 347) | def set_input_shape(self, shape):
method get_output_shape (line 351) | def get_output_shape(self):
method fprop (line 354) | def fprop(self, x, **kwargs):
method get_params (line 357) | def get_params(self):
class Tanh (line 361) | class Tanh(Layer):
method __init__ (line 362) | def __init__(self, **kwargs):
method set_input_shape (line 365) | def set_input_shape(self, shape):
method get_output_shape (line 369) | def get_output_shape(self):
method fprop (line 372) | def fprop(self, x, **kwargs):
method get_params (line 375) | def get_params(self):
class LeakyReLU (line 379) | class LeakyReLU(ReLU):
method __init__ (line 380) | def __init__(self, leak=0.2, **kwargs):
class ELU (line 384) | class ELU(Layer):
method set_input_shape (line 385) | def set_input_shape(self, shape):
method get_output_shape (line 389) | def get_output_shape(self):
method fprop (line 392) | def fprop(self, x, **kwargs):
method get_params (line 395) | def get_params(self):
class SELU (line 399) | class SELU(Layer):
method set_input_shape (line 400) | def set_input_shape(self, shape):
method get_output_shape (line 404) | def get_output_shape(self):
method fprop (line 407) | def fprop(self, x, **kwargs):
method get_params (line 414) | def get_params(self):
class TanH (line 418) | class TanH(Layer):
method set_input_shape (line 419) | def set_input_shape(self, shape):
method get_output_shape (line 423) | def get_output_shape(self):
method fprop (line 426) | def fprop(self, x, **kwargs):
class Softmax (line 430) | class Softmax(Layer):
method set_input_shape (line 431) | def set_input_shape(self, shape):
method fprop (line 435) | def fprop(self, x, **kwargs):
method get_params (line 439) | def get_params(self):
method make_label_placeholder (line 442) | def make_label_placeholder(self):
class Flatten (line 446) | class Flatten(Layer):
method set_input_shape (line 447) | def set_input_shape(self, shape):
method fprop (line 455) | def fprop(self, x, **kwargs):
method get_params (line 458) | def get_params(self):
class Print (line 462) | class Print(Layer):
method set_input_shape (line 463) | def set_input_shape(self, shape):
method get_params (line 467) | def get_params(self):
method fprop (line 470) | def fprop(self, x, **kwargs):
class Add (line 478) | class Add(Layer):
method __hash__ (line 486) | def __hash__(self):
method set_input_shape (line 489) | def set_input_shape(self, shape):
method __init__ (line 497) | def __init__(self, layers):
method get_params (line 516) | def get_params(self):
method fprop (line 522) | def fprop(self, x, **kwargs):
class PerImageStandardize (line 554) | class PerImageStandardize(Layer):
method set_input_shape (line 555) | def set_input_shape(self, shape):
method get_params (line 559) | def get_params(self):
method fprop (line 562) | def fprop(self, x, **kwargs):
class Dropout (line 580) | class Dropout(Layer):
method __init__ (line 607) | def __init__(self, include_prob=0.5, **kwargs):
method set_input_shape (line 611) | def set_input_shape(self, shape):
method get_params (line 615) | def get_params(self):
method fprop (line 618) | def fprop(self, x, dropout=False, dropout_dict=None, **kwargs):
class ResidualWithGroupNorm (line 644) | class ResidualWithGroupNorm(Layer):
method __init__ (line 652) | def __init__(
method set_input_shape (line 661) | def set_input_shape(self, shape):
method get_params (line 689) | def get_params(self):
method fprop (line 697) | def fprop(self, x, **kwargs):
class GlobalAveragePool (line 729) | class GlobalAveragePool(Layer):
method set_input_shape (line 730) | def set_input_shape(self, shape):
method get_params (line 734) | def get_params(self):
method fprop (line 737) | def fprop(self, x, **kwargs):
class GroupNorm (line 742) | class GroupNorm(Layer):
method __init__ (line 749) | def __init__(self, num_groups=32, eps=1e-3, init_gamma=1.0, **kwargs):
method set_input_shape (line 755) | def set_input_shape(self, shape):
method fprop (line 769) | def fprop(self, x, **kwargs):
method get_params (line 779) | def get_params(self):
class BatchNorm (line 783) | class BatchNorm(Layer):
method __init__ (line 788) | def __init__(self, eps=1e-3, init_gamma=1.0, **kwargs):
method set_input_shape (line 793) | def set_input_shape(self, shape):
method fprop (line 801) | def fprop(self, x, **kwargs):
method get_params (line 807) | def get_params(self):
class ResidualWithBatchNorm (line 811) | class ResidualWithBatchNorm(Layer):
method __init__ (line 819) | def __init__(
method set_input_shape (line 828) | def set_input_shape(self, shape):
method get_params (line 856) | def get_params(self):
method fprop (line 864) | def fprop(self, x, **kwargs):
FILE: cleverhans_v3.1.0/cleverhans/plot/image.py
function show (line 14) | def show(ndarray, min_val=None, max_val=None):
function save (line 33) | def save(path, ndarray, min_val=None, max_val=None):
function as_pil (line 48) | def as_pil(ndarray, min_val=None, max_val=None):
function make_grid (line 113) | def make_grid(image_batch):
FILE: cleverhans_v3.1.0/cleverhans/plot/pyplot_image.py
function pair_visual (line 10) | def pair_visual(original, adversarial, figure=None):
function grid_visual (line 53) | def grid_visual(data):
function get_logits_over_interval (line 86) | def get_logits_over_interval(
function linear_extrapolation_plot (line 137) | def linear_extrapolation_plot(
FILE: cleverhans_v3.1.0/cleverhans/plot/save_pdf.py
function save_pdf (line 8) | def save_pdf(path):
FILE: cleverhans_v3.1.0/cleverhans/plot/success_fail.py
function plot_report_from_path (line 19) | def plot_report_from_path(
function plot_report (line 69) | def plot_report(
function make_curve (line 128) | def make_curve(report, success_name, fail_names):
FILE: cleverhans_v3.1.0/cleverhans/serial.py
class PicklableVariable (line 19) | class PicklableVariable(object):
method __init__ (line 41) | def __init__(self, *args, **kwargs):
method __getstate__ (line 44) | def __getstate__(self):
method __setstate__ (line 52) | def __setstate__(self, d):
class NoRefModel (line 62) | class NoRefModel(Model):
method __getstate__ (line 78) | def __getstate__(self):
method __setstate__ (line 97) | def __setstate__(self, d):
method get_vars (line 153) | def get_vars(self):
function save (line 202) | def save(filepath, obj):
function load (line 215) | def load(filepath):
FILE: cleverhans_v3.1.0/cleverhans/train.py
function train (line 38) | def train(
function avg_grads (line 301) | def avg_grads(tower_grads):
FILE: cleverhans_v3.1.0/cleverhans/utils.py
class _ArgsWrapper (line 40) | class _ArgsWrapper(object):
method __init__ (line 46) | def __init__(self, args):
method __getattr__ (line 51) | def __getattr__(self, name):
class AccuracyReport (line 55) | class AccuracyReport(object):
method __init__ (line 63) | def __init__(self):
function batch_indices (line 76) | def batch_indices(batch_nb, data_length, batch_size):
function other_classes (line 98) | def other_classes(nb_classes, class_ind):
function to_categorical (line 115) | def to_categorical(y, nb_classes, num_classes=None):
function random_targets (line 144) | def random_targets(gt, nb_classes):
function pair_visual (line 184) | def pair_visual(*args, **kwargs):
function grid_visual (line 196) | def grid_visual(*args, **kwargs):
function get_logits_over_interval (line 208) | def get_logits_over_interval(*args, **kwargs):
function linear_extrapolation_plot (line 224) | def linear_extrapolation_plot(*args, **kwargs):
function set_log_level (line 240) | def set_log_level(level, name="cleverhans"):
function get_log_level (line 250) | def get_log_level(name="cleverhans"):
class TemporaryLogLevel (line 258) | class TemporaryLogLevel(object):
method __init__ (line 267) | def __init__(self, level, name):
method __enter__ (line 271) | def __enter__(self):
method __exit__ (line 275) | def __exit__(self, type, value, traceback):
function create_logger (line 280) | def create_logger(name):
function deterministic_dict (line 299) | def deterministic_dict(normal_dict):
function ordered_union (line 309) | def ordered_union(l1, l2):
function safe_zip (line 325) | def safe_zip(*args):
function shell_call (line 339) | def shell_call(command, **kwargs):
function deep_copy (line 377) | def deep_copy(numpy_dict):
FILE: cleverhans_v3.1.0/cleverhans/utils_keras.py
function conv_2d (line 20) | def conv_2d(filters, kernel_shape, strides, padding, input_shape=None):
function cnn_model (line 53) | def cnn_model(
class KerasModelWrapper (line 110) | class KerasModelWrapper(Model):
method __init__ (line 118) | def __init__(self, model):
method _get_softmax_name (line 131) | def _get_softmax_name(self):
method _get_abstract_layer_name (line 143) | def _get_abstract_layer_name(self):
method _get_logits_name (line 156) | def _get_logits_name(self):
method get_logits (line 180) | def get_logits(self, x):
method get_probs (line 198) | def get_probs(self, x):
method get_layer_names (line 207) | def get_layer_names(self):
method fprop (line 214) | def fprop(self, x):
method get_layer (line 258) | def get_layer(self, x, layer):
FILE: cleverhans_v3.1.0/cleverhans/utils_mnist.py
function maybe_download_mnist_file (line 20) | def maybe_download_mnist_file(file_name, datadir=None, force=False):
function download_and_parse_mnist_file (line 26) | def download_and_parse_mnist_file(file_name, datadir=None, force=False):
function data_mnist (line 31) | def data_mnist(
FILE: cleverhans_v3.1.0/cleverhans/utils_pytorch.py
function _py_func_with_gradient (line 14) | def _py_func_with_gradient(func, inp, Tout, stateful=True, name=None, gr...
function convert_pytorch_model_to_tf (line 39) | def convert_pytorch_model_to_tf(model, out_dims=None):
FILE: cleverhans_v3.1.0/cleverhans/utils_tf.py
function model_loss (line 28) | def model_loss(y, model, mean=True):
function initialize_uninitialized_global_variables (line 55) | def initialize_uninitialized_global_variables(sess):
function train (line 79) | def train(
function model_eval (line 220) | def model_eval(sess, x, y, predictions, X_test=None, Y_test=None, feed=N...
function tf_model_load (line 294) | def tf_model_load(sess, file_path=None):
function batch_eval (line 312) | def batch_eval(*args, **kwargs):
function model_argmax (line 327) | def model_argmax(sess, x, predictions, samples, feed=None):
function l2_batch_normalize (line 350) | def l2_batch_normalize(x, epsilon=1e-12, scope=None):
function kl_with_logits (line 367) | def kl_with_logits(
function clip_eta (line 380) | def clip_eta(eta, ord, eps):
function zero_out_clipped_grads (line 443) | def zero_out_clipped_grads(grad, x, clip_min, clip_max):
function random_exponential (line 468) | def random_exponential(shape, rate=1.0, dtype=tf.float32, seed=None):
function random_laplace (line 481) | def random_laplace(shape, loc=0.0, scale=1.0, dtype=tf.float32, seed=None):
function random_lp_vector (line 497) | def random_lp_vector(shape, ord, eps, dtype=tf.float32, seed=None):
function model_train (line 547) | def model_train(
function infer_devices (line 672) | def infer_devices(devices=None):
function get_available_gpus (line 696) | def get_available_gpus():
function silence (line 704) | def silence():
function clip_by_value (line 711) | def clip_by_value(t, clip_value_min, clip_value_max, name=None):
function mul (line 734) | def mul(a, b):
function div (line 747) | def div(a, b):
function op_with_scalar_cast (line 760) | def op_with_scalar_cast(a, b, f):
function assert_less_equal (line 800) | def assert_less_equal(*args, **kwargs):
function assert_greater_equal (line 810) | def assert_greater_equal(*args, **kwargs):
function assert_equal (line 820) | def assert_equal(*args, **kwargs):
function jacobian_graph (line 830) | def jacobian_graph(predictions, x, nb_classes):
function jacobian_augmentation (line 851) | def jacobian_augmentation(
FILE: cleverhans_v3.1.0/cleverhans/utils_tfe.py
function train (line 24) | def train(
function model_eval (line 135) | def model_eval(
function model_argmax (line 207) | def model_argmax(model, samples):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/__init__.py
function check_installation (line 13) | def check_installation(cur_file):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/cifar10_tutorial_tf.py
function cifar10_tutorial (line 37) | def cifar10_tutorial(
function main (line 228) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/evaluate_pickled_model.py
function evaluate_model (line 27) | def evaluate_model(
function main (line 108) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_blackbox.py
function setup_tutorial (line 47) | def setup_tutorial():
function prep_bbox (line 59) | def prep_bbox(
class ModelSubstitute (line 116) | class ModelSubstitute(Model):
method __init__ (line 117) | def __init__(self, scope, nb_classes, nb_filters=200, **kwargs):
method fprop (line 122) | def fprop(self, x, **kwargs):
function train_sub (line 135) | def train_sub(
function mnist_blackbox (line 227) | def mnist_blackbox(
function main (line 367) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_cw.py
function mnist_tutorial_cw (line 41) | def mnist_tutorial_cw(
function main (line 254) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_jsma.py
function mnist_tutorial_jsma (line 37) | def mnist_tutorial_jsma(
function main (line 239) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_keras.py
function mnist_tutorial (line 30) | def mnist_tutorial(
function get_adversarial_acc_metric (line 192) | def get_adversarial_acc_metric(model, fgsm, fgsm_params):
function get_adversarial_loss (line 206) | def get_adversarial_loss(model, fgsm, fgsm_params):
function main (line 225) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_keras_tf.py
function mnist_tutorial (line 41) | def mnist_tutorial(
function main (line 231) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_picklable.py
function mnist_tutorial (line 36) | def mnist_tutorial(
function main (line 254) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_pytorch.py
class PytorchMnistModel (line 44) | class PytorchMnistModel(nn.Module):
method __init__ (line 49) | def __init__(self):
method forward (line 61) | def forward(self, x):
function mnist_tutorial (line 70) | def mnist_tutorial(
function main (line 189) | def main(_=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_tf.py
function mnist_tutorial (line 38) | def mnist_tutorial(
function main (line 214) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_tfe.py
function attack_selection (line 51) | def attack_selection(attack_string):
function mnist_tutorial (line 76) | def mnist_tutorial(
function main (line 268) | def main(argv=None):
FILE: cleverhans_v3.1.0/cleverhans_tutorials/tutorial_models.py
function make_basic_picklable_cnn (line 14) | def make_basic_picklable_cnn(
FILE: cleverhans_v3.1.0/cleverhans_tutorials/tutorial_models_tfe.py
class ModelBasicCNNTFE (line 13) | class ModelBasicCNNTFE(Model):
method __init__ (line 18) | def __init__(
method fprop (line 62) | def fprop(self, x):
method get_layer_params (line 81) | def get_layer_params(self, layer_name):
method get_params (line 104) | def get_params(self):
method get_layer_names (line 119) | def get_layer_names(self):
FILE: cleverhans_v3.1.0/docs/_static/doctools.js
function highlight (line 69) | function highlight(node, addItems) {
FILE: cleverhans_v3.1.0/docs/_static/jquery-3.5.1.js
function DOMEval (line 103) | function DOMEval( code, node, doc ) {
function toType (line 133) | function toType( obj ) {
function isArrayLike (line 503) | function isArrayLike( obj ) {
function Sizzle (line 755) | function Sizzle( selector, context, results, seed ) {
function createCache (line 903) | function createCache() {
function markFunction (line 923) | function markFunction( fn ) {
function assert (line 932) | function assert( fn ) {
function addHandle (line 956) | function addHandle( attrs, handler ) {
function siblingCheck (line 971) | function siblingCheck( a, b ) {
function createInputPseudo (line 997) | function createInputPseudo( type ) {
function createButtonPseudo (line 1008) | function createButtonPseudo( type ) {
function createDisabledPseudo (line 1019) | function createDisabledPseudo( disabled ) {
function createPositionalPseudo (line 1075) | function createPositionalPseudo( fn ) {
function testContext (line 1098) | function testContext( context ) {
function setFilters (line 2309) | function setFilters() {}
function toSelector (line 2383) | function toSelector( tokens ) {
function addCombinator (line 2393) | function addCombinator( matcher, combinator, base ) {
function elementMatcher (line 2460) | function elementMatcher( matchers ) {
function multipleContexts (line 2474) | function multipleContexts( selector, contexts, results ) {
function condense (line 2483) | function condense( unmatched, map, filter, context, xml ) {
function setMatcher (line 2504) | function setMatcher( preFilter, selector, matcher, postFilter, postFinde...
function matcherFromTokens (line 2604) | function matcherFromTokens( tokens ) {
function matcherFromGroupMatchers (line 2667) | function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
function nodeName (line 3025) | function nodeName( elem, name ) {
function winnow (line 3035) | function winnow( elements, qualifier, not ) {
function sibling (line 3330) | function sibling( cur, dir ) {
function createOptions (line 3423) | function createOptions( options ) {
function Identity (line 3648) | function Identity( v ) {
function Thrower (line 3651) | function Thrower( ex ) {
function adoptValue (line 3655) | function adoptValue( value, resolve, reject, noValue ) {
function resolve (line 3748) | function resolve( depth, deferred, handler, special ) {
function completed (line 4113) | function completed() {
function fcamelCase (line 4208) | function fcamelCase( _all, letter ) {
function camelCase (line 4215) | function camelCase( string ) {
function Data (line 4232) | function Data() {
function getData (line 4401) | function getData( data ) {
function dataAttr (line 4426) | function dataAttr( elem, key, data ) {
function adjustCSS (line 4738) | function adjustCSS( elem, prop, valueParts, tween ) {
function getDefaultDisplay (line 4806) | function getDefaultDisplay( elem ) {
function showHide (line 4829) | function showHide( elements, show ) {
function getAll (line 4961) | function getAll( context, tag ) {
function setGlobalEval (line 4986) | function setGlobalEval( elems, refElements ) {
function buildFragment (line 5002) | function buildFragment( elems, context, scripts, selection, ignored ) {
function returnTrue (line 5097) | function returnTrue() {
function returnFalse (line 5101) | function returnFalse() {
function expectSync (line 5111) | function expectSync( elem, type ) {
function safeActiveElement (line 5118) | function safeActiveElement() {
function on (line 5124) | function on( elem, types, selector, data, fn, one ) {
function leverageNative (line 5612) | function leverageNative( el, type, expectSync ) {
function manipulationTarget (line 5976) | function manipulationTarget( elem, content ) {
function disableScript (line 5987) | function disableScript( elem ) {
function restoreScript (line 5991) | function restoreScript( elem ) {
function cloneCopyEvent (line 6001) | function cloneCopyEvent( src, dest ) {
function fixInput (line 6034) | function fixInput( src, dest ) {
function domManip (line 6047) | function domManip( collection, args, callback, ignored ) {
function remove (line 6139) | function remove( elem, selector, keepData ) {
function computeStyleTests (line 6453) | function computeStyleTests() {
function roundPixelMeasures (line 6497) | function roundPixelMeasures( measure ) {
function curCSS (line 6571) | function curCSS( elem, name, computed ) {
function addGetHookIf (line 6624) | function addGetHookIf( conditionFn, hookFn ) {
function vendorPropName (line 6649) | function vendorPropName( name ) {
function finalPropName (line 6664) | function finalPropName( name ) {
function setPositiveNumber (line 6690) | function setPositiveNumber( _elem, value, subtract ) {
function boxModelAdjustment (line 6702) | function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, ...
function getWidthOrHeight (line 6770) | function getWidthOrHeight( elem, dimension, extra ) {
function Tween (line 7146) | function Tween( elem, options, prop, end, easing ) {
function schedule (line 7269) | function schedule() {
function createFxNow (line 7282) | function createFxNow() {
function genFx (line 7290) | function genFx( type, includeWidth ) {
function createTween (line 7310) | function createTween( value, prop, animation ) {
function defaultPrefilter (line 7324) | function defaultPrefilter( elem, props, opts ) {
function propFilter (line 7496) | function propFilter( props, specialEasing ) {
function Animation (line 7533) | function Animation( elem, properties, options ) {
function stripAndCollapse (line 8248) | function stripAndCollapse( value ) {
function getClass (line 8254) | function getClass( elem ) {
function classesToArray (line 8258) | function classesToArray( value ) {
function buildParams (line 8885) | function buildParams( prefix, obj, traditional, add ) {
function addToPrefiltersOrTransports (line 9039) | function addToPrefiltersOrTransports( structure ) {
function inspectPrefiltersOrTransports (line 9073) | function inspectPrefiltersOrTransports( structure, options, originalOpti...
function ajaxExtend (line 9102) | function ajaxExtend( target, src ) {
function ajaxHandleResponses (line 9122) | function ajaxHandleResponses( s, jqXHR, responses ) {
function ajaxConvert (line 9180) | function ajaxConvert( s, response, jqXHR, isSuccess ) {
function done (line 9696) | function done( status, nativeStatusText, responses, headers ) {
FILE: cleverhans_v3.1.0/docs/_static/jquery.js
function b (line 2) | function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e...
function w (line 2) | function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof...
function p (line 2) | function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e...
function se (line 2) | function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeTy...
function ue (line 2) | function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cac...
function le (line 2) | function le(e){return e[S]=!0,e}
function ce (line 2) | function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(...
function fe (line 2) | function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[...
function pe (line 2) | function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourc...
function de (line 2) | function de(t){return function(e){return"input"===e.nodeName.toLowerCase...
function he (line 2) | function he(n){return function(e){var t=e.nodeName.toLowerCase();return(...
function ge (line 2) | function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e....
function ve (line 2) | function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,...
function ye (line 2) | function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}
function me (line 2) | function me(){}
function xe (line 2) | function xe(e){for(var t=0,n=e.length,r="";t<n;t++)r+=e[t].value;return r}
function be (line 2) | function be(s,e,t){var u=e.dir,l=e.next,c=l||u,f=t&&"parentNode"===c,p=r...
function we (line 2) | function we(i){return 1<i.length?function(e,t,n){var r=i.length;while(r-...
function Te (line 2) | function Te(e,t,n,r,i){for(var o,a=[],s=0,u=e.length,l=null!=t;s<u;s++)(...
function Ce (line 2) | function Ce(d,h,g,v,y,e){return v&&!v[S]&&(v=Ce(v)),y&&!y[S]&&(y=Ce(y,e)...
function Ee (line 2) | function Ee(e){for(var i,t,n,r=e.length,o=b.relative[e[0].type],a=o||b.r...
function A (line 2) | function A(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerC...
function D (line 2) | function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,...
function O (line 2) | function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}
function R (line 2) | function R(e){return e}
function M (line 2) | function M(e){throw e}
function I (line 2) | function I(e,t,n,r){var i;try{e&&m(i=e.promise)?i.call(e).done(t).fail(n...
function l (line 2) | function l(i,o,a,s){return function(){var n=this,r=arguments,e=function(...
function B (line 2) | function B(){E.removeEventListener("DOMContentLoaded",B),C.removeEventLi...
function U (line 2) | function U(e,t){return t.toUpperCase()}
function X (line 2) | function X(e){return e.replace(_,"ms-").replace(z,U)}
function G (line 2) | function G(){this.expando=S.expando+G.uid++}
function Z (line 2) | function Z(e,t,n){var r,i;if(void 0===n&&1===e.nodeType)if(r="data-"+t.r...
function se (line 2) | function se(e,t,n,r){var i,o,a=20,s=r?function(){return r.cur()}:functio...
function le (line 2) | function le(e,t){for(var n,r,i,o,a,s,u,l=[],c=0,f=e.length;c<f;c++)(r=e[...
function ve (line 2) | function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagNa...
function ye (line 2) | function ye(e,t){for(var n=0,r=e.length;n<r;n++)Y.set(e[n],"globalEval",...
function xe (line 2) | function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),...
function Ce (line 2) | function Ce(){return!0}
function Ee (line 2) | function Ee(){return!1}
function Se (line 2) | function Se(e,t){return e===function(){try{return E.activeElement}catch(...
function ke (line 2) | function ke(e,t,n,r,i,o){var a,s;if("object"==typeof t){for(s in"string"...
function Ae (line 2) | function Ae(e,i,o){o?(Y.set(e,i,!1),S.event.add(e,i,{namespace:!1,handle...
function qe (line 2) | function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"...
function Le (line 2) | function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}
function He (line 2) | function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.sli...
function Oe (line 2) | function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=...
function Pe (line 2) | function Pe(n,r,i,o){r=g(r);var e,t,a,s,u,l,c=0,f=n.length,p=f-1,d=r[0],...
function Re (line 2) | function Re(e,t,n){for(var r,i=t?S.filter(t,e):e,o=0;null!=(r=i[o]);o++)...
function Be (line 2) | function Be(e,t,n){var r,i,o,a,s=e.style;return(n=n||Ie(e))&&(""!==(a=n....
function $e (line 2) | function $e(e,t){return{get:function(){if(!e())return(this.get=t).apply(...
function e (line 2) | function e(){if(l){u.style.cssText="position:absolute;left:-11111px;widt...
function t (line 2) | function t(e){return Math.round(parseFloat(e))}
function Xe (line 2) | function Xe(e){var t=S.cssProps[e]||Ue[e];return t||(e in ze?e:Ue[e]=fun...
function Je (line 2) | function Je(e,t,n){var r=te.exec(t);return r?Math.max(0,r[2]-(n||0))+(r[...
function Ke (line 2) | function Ke(e,t,n,r,i,o){var a="width"===t?1:0,s=0,u=0;if(n===(r?"border...
function Ze (line 2) | function Ze(e,t,n){var r=Ie(e),i=(!y.boxSizingReliable()||n)&&"border-bo...
function et (line 2) | function et(e,t,n,r,i){return new et.prototype.init(e,t,n,r,i)}
function st (line 2) | function st(){nt&&(!1===E.hidden&&C.requestAnimationFrame?C.requestAnima...
function ut (line 2) | function ut(){return C.setTimeout(function(){tt=void 0}),tt=Date.now()}
function lt (line 2) | function lt(e,t){var n,r=0,i={height:e};for(t=t?1:0;r<4;r+=2-t)i["margin...
function ct (line 2) | function ct(e,t,n){for(var r,i=(ft.tweeners[t]||[]).concat(ft.tweeners["...
function ft (line 2) | function ft(o,e,t){var n,a,r=0,i=ft.prefilters.length,s=S.Deferred().alw...
function vt (line 2) | function vt(e){return(e.match(P)||[]).join(" ")}
function yt (line 2) | function yt(e){return e.getAttribute&&e.getAttribute("class")||""}
function mt (line 2) | function mt(e){return Array.isArray(e)?e:"string"==typeof e&&e.match(P)|...
function Dt (line 2) | function Dt(n,e,r,i){var t;if(Array.isArray(e))S.each(e,function(e,t){r|...
function Ft (line 2) | function Ft(o){return function(e,t){"string"!=typeof e&&(t=e,e="*");var ...
function Bt (line 2) | function Bt(t,i,o,a){var s={},u=t===Mt;function l(e){var r;return s[e]=!...
function $t (line 2) | function $t(e,t){var n,r,i=S.ajaxSettings.flatOptions||{};for(n in t)voi...
function l (line 2) | function l(e,t,n,r){var i,o,a,s,u,l=t;h||(h=!0,d&&C.clearTimeout(d),c=vo...
FILE: cleverhans_v3.1.0/docs/_static/language_data.js
function splitQuery (line 278) | function splitQuery(query) {
FILE: cleverhans_v3.1.0/docs/_static/searchtools.js
function splitQuery (line 47) | function splitQuery(query) {
function pulse (line 117) | function pulse() {
function displayNextItem (line 247) | function displayNextItem() {
FILE: cleverhans_v3.1.0/docs/_static/underscore-1.3.1.js
function eq (line 669) | function eq(a, b, stack) {
FILE: cleverhans_v3.1.0/docs/_static/underscore.js
function q (line 8) | function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)re...
FILE: cleverhans_v3.1.0/examples/RL-attack/enjoy-adv.py
class DQNModel (line 70) | class DQNModel:
method __init__ (line 76) | def __init__(self, env, dueling, noisy, fname):
method get_act (line 97) | def get_act(self):
method get_session (line 100) | def get_session(self):
method craft_adv (line 103) | def craft_adv(self):
function parse_args (line 118) | def parse_args():
function make_env (line 162) | def make_env(game_name):
function play (line 169) | def play(
FILE: cleverhans_v3.1.0/examples/RL-attack/model.py
function model (line 6) | def model(img_in, num_actions, scope, noisy=False, reuse=False, concat_s...
function dueling_model (line 43) | def dueling_model(
FILE: cleverhans_v3.1.0/examples/RL-attack/train.py
function parse_args (line 35) | def parse_args():
function make_env (line 157) | def make_env(game_name):
function maybe_save_model (line 164) | def maybe_save_model(savedir, container, state):
function maybe_load_model (line 187) | def maybe_load_model(savedir, container):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/generate_imperceptible_adv.py
function ReadFromWav (line 42) | def ReadFromWav(data, batch_size):
class Attack (line 114) | class Attack:
method __init__ (line 115) | def __init__(
method attack_stage1 (line 235) | def attack_stage1(
method attack_stage2 (line 354) | def attack_stage2(
function main (line 514) | def main(argv):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/generate_masking_threshold.py
function compute_PSD_matrix (line 10) | def compute_PSD_matrix(audio, window_size):
function Bark (line 25) | def Bark(f):
function quiet (line 30) | def quiet(f):
function two_slops (line 41) | def two_slops(bark_psd, delta_TM, bark_maskee):
function compute_th (line 60) | def compute_th(PSD, barks, ATH, freqs):
function generate_th (line 121) | def generate_th(audio, fs, window_size=2048):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/generate_robust_adv.py
function ReadFromWav (line 60) | def ReadFromWav(data, batch_size):
function Readrir (line 109) | def Readrir():
class Attack (line 120) | class Attack:
method __init__ (line 121) | def __init__(
method attack_stage1 (line 228) | def attack_stage1(
method attack_stage2 (line 378) | def attack_stage2(
function main (line 533) | def main(argv):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/room_simulator.py
function clip (line 10) | def clip(signal, high, low):
function normalize (line 22) | def normalize(signal, bits=None):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/test_imperceptible_adv.py
function Read_input (line 26) | def Read_input(data, batch_size):
function main (line 78) | def main(argv):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/test_robust_adv.py
function Read_input (line 35) | def Read_input(data, batch_size):
function Readrir (line 90) | def Readrir(num_room):
function main (line 102) | def main(argv):
FILE: cleverhans_v3.1.0/examples/adversarial_asr/tool.py
function _MakeLogMel (line 8) | def _MakeLogMel(audio, sample_rate):
function _CreateAsrFrontend (line 17) | def _CreateAsrFrontend():
function create_features (line 34) | def create_features(input_tf, sample_rate_tf, mask_freq):
function create_inputs (line 53) | def create_inputs(model, features, tgt, batch_size, mask_freq):
function create_speech_rir (line 77) | def create_speech_rir(audios, rir, lengths_audios, max_len, batch_size):
class Transform (line 118) | class Transform(object):
method __init__ (line 123) | def __init__(self, window_size):
method __call__ (line 129) | def __call__(self, x, psd_max_ori):
FILE: cleverhans_v3.1.0/examples/facenet_adversarial_faces/facenet_fgsm.py
class InceptionResnetV1Model (line 11) | class InceptionResnetV1Model(Model):
method __init__ (line 14) | def __init__(self):
method convert_to_classifier (line 24) | def convert_to_classifier(self):
method fprop (line 50) | def fprop(self, x, set_ref=False):
FILE: cleverhans_v3.1.0/examples/facenet_adversarial_faces/set_loader.py
function save_images (line 17) | def save_images(adv, faces1, faces2, size):
function save_images_to_folder (line 24) | def save_images_to_folder(images, size, path):
function load_testset (line 37) | def load_testset(size):
FILE: cleverhans_v3.1.0/examples/imagenet_featadvs/model.py
class ModelImageNetCNN (line 9) | class ModelImageNetCNN(Model):
method __init__ (line 10) | def __init__(self, scope, nb_classes=1000, **kwargs):
method fprop (line 14) | def fprop(self, x, **kwargs):
function make_imagenet_cnn (line 38) | def make_imagenet_cnn(input_shape=(None, 224, 224, 3)):
FILE: cleverhans_v3.1.0/examples/madry_lab_challenges/cifar10/attack_model.py
function main (line 25) | def main(argv):
FILE: cleverhans_v3.1.0/examples/madry_lab_challenges/mnist/attack_model.py
function main (line 26) | def main(argv):
FILE: cleverhans_v3.1.0/examples/madry_lab_challenges/mnist/madry_mnist_model.py
class MadryMNIST (line 19) | class MadryMNIST(Model):
method __init__ (line 20) | def __init__(self, nb_classes=10):
method get_params (line 34) | def get_params(self):
method fprop (line 46) | def fprop(self, x):
method _weight_variable (line 72) | def _weight_variable(shape):
method _bias_variable (line 77) | def _bias_variable(shape):
method _conv2d (line 82) | def _conv2d(x, W):
method _max_pool_2x2 (line 86) | def _max_pool_2x2(x):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/attacks_multigpu.py
class MadryEtAlMultiGPU (line 12) | class MadryEtAlMultiGPU(MadryEtAl):
method __init__ (line 26) | def __init__(self, *args, **kwargs):
method get_or_guess_labels (line 33) | def get_or_guess_labels(self, x, kwargs):
method attack (line 41) | def attack(self, x, y_p, **kwargs):
method generate_np (line 109) | def generate_np(self, x_val, **kwargs):
method parse_params (line 138) | def parse_params(self, ngpu=1, **kwargs):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/evaluator.py
function create_adv_by_name (line 16) | def create_adv_by_name(model, x, attack_type, sess, dataset, y=None, **k...
class Evaluator (line 80) | class Evaluator(object):
method __init__ (line 85) | def __init__(
method log_value (line 140) | def log_value(self, tag, val, desc=""):
method eval_advs (line 151) | def eval_advs(self, x, y, preds_adv, X_test, Y_test, att_type):
method eval_multi (line 182) | def eval_multi(self, inc_epoch=True):
method __call__ (line 245) | def __call__(self, **kwargs):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/make_model.py
function make_basic_cnn (line 11) | def make_basic_cnn(nb_filters=64, nb_classes=10, input_shape=(None, 28, ...
function make_basic_ngpu (line 28) | def make_basic_ngpu(nb_classes=10, input_shape=(None, 28, 28, 1), **kwar...
function make_madry_ngpu (line 39) | def make_madry_ngpu(nb_classes=10, input_shape=(None, 28, 28, 1), **kwar...
function make_model (line 61) | def make_model(model_type="madry", **kwargs):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/model.py
function clone_variable (line 17) | def clone_variable(name, x, trainable=False):
function unify_device_name (line 21) | def unify_device_name(dname):
class MLP (line 28) | class MLP(Model):
method __init__ (line 33) | def __init__(self, nb_classes, layers, input_shape):
method fprop (line 55) | def fprop(self, x, set_ref=False):
method get_params (line 66) | def get_params(self):
class Layer (line 75) | class Layer(object):
method get_output_shape (line 76) | def get_output_shape(self):
class Linear (line 80) | class Linear(Layer):
method __init__ (line 81) | def __init__(self, num_hid):
method set_input_shape (line 84) | def set_input_shape(self, input_shape):
method fprop (line 95) | def fprop(self, x):
method get_params (line 98) | def get_params(self):
class Conv2D (line 102) | class Conv2D(Layer):
method __init__ (line 103) | def __init__(self, output_channels, kernel_shape, strides, padding):
method set_input_shape (line 107) | def set_input_shape(self, input_shape):
method fprop (line 124) | def fprop(self, x):
method get_params (line 132) | def get_params(self):
class ReLU (line 136) | class ReLU(Layer):
method __init__ (line 137) | def __init__(self):
method set_input_shape (line 140) | def set_input_shape(self, shape):
method fprop (line 144) | def fprop(self, x):
method get_params (line 147) | def get_params(self):
class Softmax (line 151) | class Softmax(Layer):
method __init__ (line 152) | def __init__(self):
method set_input_shape (line 155) | def set_input_shape(self, shape):
method fprop (line 159) | def fprop(self, x):
method get_params (line 162) | def get_params(self):
class Flatten (line 166) | class Flatten(Layer):
method __init__ (line 167) | def __init__(self):
method set_input_shape (line 170) | def set_input_shape(self, shape):
method fprop (line 178) | def fprop(self, x):
method get_params (line 181) | def get_params(self):
class MLPnGPU (line 185) | class MLPnGPU(MLP):
method __init__ (line 191) | def __init__(self, nb_classes, layers, input_shape):
method fprop (line 195) | def fprop(self, x):
method set_device (line 200) | def set_device(self, device_name):
method create_sync_ops (line 210) | def create_sync_ops(self, host_device):
method set_training (line 224) | def set_training(self, training=False):
class LayernGPU (line 230) | class LayernGPU(Layer):
method __init__ (line 235) | def __init__(self):
method set_training (line 245) | def set_training(self, training=False):
method get_variable (line 248) | def get_variable(self, name, initializer):
method set_input_shape_ngpu (line 262) | def set_input_shape_ngpu(self, new_input_shape):
method create_sync_ops (line 296) | def create_sync_ops(self, host_device):
method fprop (line 310) | def fprop(self, x):
class LinearnGPU (line 320) | class LinearnGPU(LayernGPU):
method __init__ (line 321) | def __init__(self, num_hid, w_name="W"):
method set_input_shape (line 326) | def set_input_shape(self, input_shape):
method fprop_noscope (line 338) | def fprop_noscope(self, x):
class Conv2DnGPU (line 342) | class Conv2DnGPU(LayernGPU):
method __init__ (line 343) | def __init__(
method set_input_shape (line 351) | def set_input_shape(self, input_shape):
method fprop_noscope (line 372) | def fprop_noscope(self, x):
class MaxPool (line 381) | class MaxPool(LayernGPU):
method __init__ (line 382) | def __init__(self, ksize, strides, padding):
method set_input_shape (line 387) | def set_input_shape(self, input_shape):
method fprop_noscope (line 396) | def fprop_noscope(self, x):
class LayerNorm (line 405) | class LayerNorm(LayernGPU):
method set_input_shape (line 406) | def set_input_shape(self, input_shape):
method fprop_noscope (line 426) | def fprop_noscope(self, x):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/resnet_tf.py
class ResNetTF (line 43) | class ResNetTF(MLPnGPU):
method __init__ (line 46) | def __init__(self, batch_size=None, name=None, **kwargs):
method set_training (line 70) | def set_training(self, training=False):
method fprop (line 74) | def fprop(self, x):
method _stride_arr (line 82) | def _stride_arr(self, stride):
method _build_model (line 86) | def _build_model(self, x):
method build_cost (line 155) | def build_cost(self, labels, logits):
method build_train_op_from_cost (line 172) | def build_train_op_from_cost(self, cost):
method _layer_norm (line 200) | def _layer_norm(self, name, x):
method _residual (line 214) | def _residual(
method _bottleneck_residual (line 253) | def _bottleneck_residual(
method _decay (line 288) | def _decay(self):
method _conv (line 307) | def _conv(self, name, x, filter_size, in_filters, out_filters, strides):
method _relu (line 326) | def _relu(self, x, leakiness=0.0):
method _fully_connected (line 330) | def _fully_connected(self, x, out_dim):
method _global_avg_pool (line 343) | def _global_avg_pool(self, x):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/run_multigpu.py
function run_trainer (line 20) | def run_trainer(hparams):
function main (line 35) | def main(argv=None):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/runner.py
class Runner (line 7) | class Runner(object):
method __init__ (line 13) | def __init__(self, inputs, outputs, sess=None):
method run (line 19) | def run(self, X_batch=None):
method set_input (line 24) | def set_input(self, X_batch=None):
method proc_fvals (line 27) | def proc_fvals(self, fvals):
method is_finished (line 30) | def is_finished(self):
class RunnerMultiGPU (line 34) | class RunnerMultiGPU(Runner):
method __init__ (line 40) | def __init__(self, *args, **kwargs):
method assert_inputs_outputs (line 45) | def assert_inputs_outputs(self):
method set_input (line 64) | def set_input(self, X_batch=None):
method proc_fvals (line 106) | def proc_fvals(self, fvals):
method is_finished (line 139) | def is_finished(self):
class RunnerSingleGPU (line 143) | class RunnerSingleGPU(Runner):
method __init__ (line 144) | def __init__(self, *args, **kwargs):
method set_input (line 147) | def set_input(self, X_batch=None):
method proc_fvals (line 155) | def proc_fvals(self, fvals):
method is_finished (line 161) | def is_finished(self):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/test_attack_multigpu.py
class TestMadryEtAlMultiGPU (line 22) | class TestMadryEtAlMultiGPU(TestMadryEtAl):
method setUp (line 28) | def setUp(self):
method test_single_vs_multi_gpu (line 50) | def test_single_vs_multi_gpu(self):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/test_run_multigpu.py
class TestRunMultiGPU (line 18) | class TestRunMultiGPU(CleverHansTest):
method helper_run_multi_gpu_madryetal (line 19) | def helper_run_multi_gpu_madryetal(self, extra_flags=None):
method test_run_single_gpu_fgsm (line 95) | def test_run_single_gpu_fgsm(self):
method test_run_multi_gpu_madryetal (line 182) | def test_run_multi_gpu_madryetal(self):
method test_run_multi_gpu_naive (line 185) | def test_run_multi_gpu_naive(self):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/test_runner.py
class TestRunnerMultiGPU (line 16) | class TestRunnerMultiGPU(CleverHansTest):
method setUp (line 17) | def setUp(self):
method help_test_runner (line 36) | def help_test_runner(self, ninputs, niter):
method test_queue_full (line 65) | def test_queue_full(self):
method test_queue_half (line 68) | def test_queue_half(self):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/trainer.py
class TrainManager (line 29) | class TrainManager(object):
method __init__ (line 36) | def __init__(self, hparams):
method _init_session (line 55) | def _init_session(self):
method _init_data (line 69) | def _init_data(self):
method _init_inputs (line 108) | def _init_inputs(self):
method _init_model (line 119) | def _init_model(self):
method _init_eval (line 126) | def _init_eval(self):
method eval (line 142) | def eval(self, **kwargs):
method finish (line 146) | def finish(self):
method _update_learning_params (line 151) | def _update_learning_params(self):
method _build_train_op (line 169) | def _build_train_op(self, predictions, y, predictions_adv):
method model_train (line 199) | def model_train(self):
method _init_tf (line 282) | def _init_tf(self, X_batch, Y_batch):
method _run (line 289) | def _run(self, X_batch=None):
method _sync_params (line 294) | def _sync_params(self, forced=False):
method _create_train_graph (line 297) | def _create_train_graph(self):
class TrainerMultiGPU (line 309) | class TrainerMultiGPU(TrainManager):
method __init__ (line 316) | def __init__(self, *args, **kwargs):
method clone_g0_inputs_on_ngpus (line 322) | def clone_g0_inputs_on_ngpus(self, inputs, outputs, g0_inputs):
method _create_train_graph (line 353) | def _create_train_graph(self):
method _sync_params (line 429) | def _sync_params(self, forced=False):
class TrainerSingleGPU (line 434) | class TrainerSingleGPU(TrainManager):
method __init__ (line 440) | def __init__(self, *args, **kwargs):
method _create_train_graph (line 446) | def _create_train_graph(self):
method _sync_params (line 493) | def _sync_params(self, forced=False):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/utils.py
function preprocess_batch (line 5) | def preprocess_batch(images_batch, preproc_func=None):
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/utils_cifar.py
function unpickle (line 45) | def unpickle(file):
function read_CIFAR10 (line 52) | def read_CIFAR10(data_folder):
function read_CIFAR100 (line 119) | def read_CIFAR100(data_folder):
function cifar_tf_preprocess (line 164) | def cifar_tf_preprocess(
FILE: cleverhans_v3.1.0/examples/multigpu_advtrain/utils_svhn.py
function read_SVHN (line 47) | def read_SVHN(data_folder):
function svhn_tf_preprocess (line 89) | def svhn_tf_preprocess(inp, random_crop=True):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dataset/download_images.py
function parse_args (line 43) | def parse_args():
function get_image (line 59) | def get_image(row, output_dir):
function download_image (line 74) | def download_image(image_id, url, x1, y1, x2, y2, output_dir):
function main (line 98) | def main():
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/run_attacks_and_defenses.py
function parse_args (line 16) | def parse_args():
class Submission (line 60) | class Submission(object):
method __init__ (line 63) | def __init__(self, directory, container, entry_point, use_gpu):
method docker_binary (line 78) | def docker_binary(self):
class Attack (line 83) | class Attack(Submission):
method run (line 86) | def run(self, input_dir, output_dir, epsilon):
class Defense (line 117) | class Defense(Submission):
method run (line 120) | def run(self, input_dir, output_dir):
function read_submissions_from_directory (line 148) | def read_submissions_from_directory(dirname, use_gpu):
class AttacksOutput (line 188) | class AttacksOutput(object):
method __init__ (line 191) | def __init__(
method _load_dataset_clipping (line 220) | def _load_dataset_clipping(self, dataset_dir, epsilon):
method clip_and_copy_attack_outputs (line 246) | def clip_and_copy_attack_outputs(self, attack_name, is_targeted):
method attack_names (line 293) | def attack_names(self):
method targeted_attack_names (line 298) | def targeted_attack_names(self):
method attack_image_count (line 303) | def attack_image_count(self):
method dataset_image_count (line 308) | def dataset_image_count(self):
method targeted_attack_image_count (line 313) | def targeted_attack_image_count(self):
method image_by_base_filename (line 317) | def image_by_base_filename(self, filename):
class DatasetMetadata (line 322) | class DatasetMetadata(object):
method __init__ (line 325) | def __init__(self, filename):
method get_true_label (line 349) | def get_true_label(self, image_id):
method get_target_class (line 353) | def get_target_class(self, image_id):
method save_target_classes (line 357) | def save_target_classes(self, filename):
function load_defense_output (line 364) | def load_defense_output(filename):
function compute_and_save_scores_and_ranking (line 380) | def compute_and_save_scores_and_ranking(
function main (line 556) | def main():
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_attacks/fgsm/attack_fgsm.py
function load_images (line 41) | def load_images(input_dir, batch_shape):
function save_images (line 74) | def save_images(images, filenames, output_dir):
class InceptionModel (line 92) | class InceptionModel(object):
method __init__ (line 95) | def __init__(self, nb_classes=None, num_classes=None):
method __call__ (line 111) | def __call__(self, x_input):
function main (line 125) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_attacks/noop/attack_noop.py
function load_images (line 33) | def load_images(input_dir, batch_shape):
function save_images (line 64) | def save_images(images, filenames, output_dir):
function main (line 79) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_attacks/random_noise/attack_random_noise.py
function load_images (line 33) | def load_images(input_dir, batch_shape):
function save_images (line 64) | def save_images(images, filenames, output_dir):
function main (line 79) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_defenses/adv_inception_v3/defense.py
function load_images (line 41) | def load_images(input_dir, batch_shape):
function main (line 74) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_defenses/base_inception_model/defense.py
function load_images (line 41) | def load_images(input_dir, batch_shape):
function main (line 74) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_defenses/ens_adv_inception_resnet_v2/defense.py
function load_images (line 42) | def load_images(input_dir, batch_shape):
function main (line 75) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_defenses/ens_adv_inception_resnet_v2/inception_resnet_v2.py
function block35 (line 35) | def block35(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=...
function block17 (line 62) | def block17(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=...
function block8 (line 90) | def block8(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=N...
function inception_resnet_v2_base (line 118) | def inception_resnet_v2_base(
function inception_resnet_v2 (line 349) | def inception_resnet_v2(
function inception_resnet_v2_arg_scope (line 435) | def inception_resnet_v2_arg_scope(
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_targeted_attacks/iter_target_class/attack_iter_target_class.py
function load_target_class (line 45) | def load_target_class(input_dir):
function load_images (line 51) | def load_images(input_dir, batch_shape):
function save_images (line 84) | def save_images(images, filenames, output_dir):
function main (line 101) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_targeted_attacks/step_target_class/attack_step_target_class.py
function load_target_class (line 41) | def load_target_class(input_dir):
function load_images (line 47) | def load_images(input_dir, batch_shape):
function save_images (line 80) | def save_images(images, filenames, output_dir):
function main (line 97) | def main(_):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/validation_tool/submission_validator_lib.py
function get_extract_command_template (line 42) | def get_extract_command_template(filename):
function shell_call (line 50) | def shell_call(command, **kwargs):
function make_directory_writable (line 75) | def make_directory_writable(dirname):
function load_defense_output (line 107) | def load_defense_output(filename):
class SubmissionValidator (line 123) | class SubmissionValidator(object):
method __init__ (line 126) | def __init__(self, temp_dir, use_gpu):
method _prepare_temp_dir (line 140) | def _prepare_temp_dir(self):
method _extract_submission (line 152) | def _extract_submission(self, filename):
method _verify_submission_size (line 215) | def _verify_submission_size(self):
method _load_and_verify_metadata (line 227) | def _load_and_verify_metadata(self, submission_type):
method _verify_docker_image_size (line 278) | def _verify_docker_image_size(self, image_name):
method _prepare_sample_data (line 301) | def _prepare_sample_data(self, submission_type):
method _run_submission (line 327) | def _run_submission(self, metadata):
method _verify_output (line 386) | def _verify_output(self, submission_type):
method validate_submission (line 428) | def validate_submission(self, filename, submission_type):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/validation_tool/validate_submission.py
function print_in_box (line 30) | def print_in_box(text):
function main (line 41) | def main(args):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/classification_results.py
function read_classification_results (line 30) | def read_classification_results(storage_client, file_path):
function analyze_one_classification_result (line 94) | def analyze_one_classification_result(
class ResultMatrix (line 144) | class ResultMatrix(object):
method __init__ (line 150) | def __init__(self, default_value=0):
method dim0 (line 158) | def dim0(self):
method dim1 (line 163) | def dim1(self):
method __getitem__ (line 167) | def __getitem__(self, key):
method __setitem__ (line 183) | def __setitem__(self, key, value):
method save_to_file (line 199) | def save_to_file(self, filename, remap_dim0=None, remap_dim1=None):
class ClassificationBatches (line 225) | class ClassificationBatches(object):
method __init__ (line 232) | def __init__(self, datastore_client, storage_client, round_name):
method serialize (line 246) | def serialize(self, fobj):
method deserialize (line 250) | def deserialize(self, fobj):
method data (line 255) | def data(self):
method __getitem__ (line 259) | def __getitem__(self, key):
method init_from_adversarial_batches_write_to_datastore (line 263) | def init_from_adversarial_batches_write_to_datastore(
method init_from_datastore (line 295) | def init_from_datastore(self):
method read_batch_from_datastore (line 303) | def read_batch_from_datastore(self, class_batch_id):
method compute_classification_results (line 313) | def compute_classification_results(
method __str__ (line 404) | def __str__(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py
class CompetitionStorageClient (line 34) | class CompetitionStorageClient(object):
method __init__ (line 37) | def __init__(self, project_id, bucket_name):
method list_blobs (line 44) | def list_blobs(self, prefix=""):
method get_blob (line 48) | def get_blob(self, blob_name):
method new_blob (line 52) | def new_blob(self, blob_name):
class NoTransactionBatch (line 57) | class NoTransactionBatch(object):
method __init__ (line 88) | def __init__(self, client):
method begin (line 94) | def begin(self):
method commit (line 102) | def commit(self):
method rollback (line 108) | def rollback(self):
method put (line 125) | def put(self, entity):
method delete (line 140) | def delete(self, key):
method __enter__ (line 155) | def __enter__(self):
method __exit__ (line 159) | def __exit__(self, exc_type, exc_value, traceback):
function iterate_with_exp_backoff (line 168) | def iterate_with_exp_backoff(
class CompetitionDatastoreClient (line 217) | class CompetitionDatastoreClient(object):
method __init__ (line 220) | def __init__(self, project_id, namespace=None):
method key (line 224) | def key(self, *args, **kwargs):
method entity (line 228) | def entity(self, key):
method no_transact_batch (line 232) | def no_transact_batch(self):
method batch (line 236) | def batch(self):
method transaction (line 240) | def transaction(self):
method get (line 244) | def get(self, key, transaction=None):
method query_fetch (line 248) | def query_fetch(self, **kwargs):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py
class DatasetMetadata (line 21) | class DatasetMetadata(object):
method __init__ (line 28) | def __init__(self, fobj):
method get_true_label (line 55) | def get_true_label(self, image_id):
method get_target_class (line 59) | def get_target_class(self, image_id):
method save_target_classes_for_batch (line 63) | def save_target_classes_for_batch(self, filename, image_batches, batch...
function enforce_epsilon_and_compute_hash (line 78) | def enforce_epsilon_and_compute_hash(dataset_batch_dir, adv_dir, output_...
function download_dataset (line 123) | def download_dataset(
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py
class ImageBatchesBase (line 41) | class ImageBatchesBase(object):
method __init__ (line 48) | def __init__(self, datastore_client, entity_kind_batches, entity_kind_...
method _write_single_batch_images_internal (line 72) | def _write_single_batch_images_internal(self, batch_id, client_batch):
method write_to_datastore (line 84) | def write_to_datastore(self):
method write_single_batch_images_to_datastore (line 97) | def write_single_batch_images_to_datastore(self, batch_id):
method init_from_datastore (line 103) | def init_from_datastore(self):
method data (line 118) | def data(self):
method __getitem__ (line 122) | def __getitem__(self, key):
method add_batch (line 126) | def add_batch(self, batch_id, batch_properties=None):
method add_image (line 138) | def add_image(self, batch_id, image_id, image_properties=None):
method count_num_images (line 151) | def count_num_images(self):
method __str__ (line 155) | def __str__(self):
class DatasetBatches (line 179) | class DatasetBatches(ImageBatchesBase):
method __init__ (line 182) | def __init__(self, datastore_client, storage_client, dataset_name):
method _read_image_list (line 198) | def _read_image_list(self, skip_image_ids=None):
method init_from_storage_write_to_datastore (line 238) | def init_from_storage_write_to_datastore(
class AversarialBatches (line 279) | class AversarialBatches(ImageBatchesBase):
method __init__ (line 282) | def __init__(self, datastore_client):
method init_from_dataset_and_submissions_write_to_datastore (line 294) | def init_from_dataset_and_submissions_write_to_datastore(
method count_generated_adv_examples (line 316) | def count_generated_adv_examples(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/submissions.py
function participant_from_submission_path (line 35) | def participant_from_submission_path(submission_path):
class CompetitionSubmissions (line 67) | class CompetitionSubmissions(object):
method __init__ (line 80) | def __init__(self, datastore_client, storage_client, round_name):
method _load_submissions_from_datastore_dir (line 98) | def _load_submissions_from_datastore_dir(self, dir_suffix, id_pattern):
method init_from_storage_write_to_datastore (line 122) | def init_from_storage_write_to_datastore(self):
method _write_to_datastore (line 140) | def _write_to_datastore(self):
method init_from_datastore (line 159) | def init_from_datastore(self):
method attacks (line 184) | def attacks(self):
method targeted_attacks (line 189) | def targeted_attacks(self):
method defenses (line 194) | def defenses(self):
method get_all_attack_ids (line 198) | def get_all_attack_ids(self):
method find_by_id (line 202) | def find_by_id(self, submission_id):
method get_external_id (line 219) | def get_external_id(self, submission_id):
method __str__ (line 238) | def __str__(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/tests/classification_results_test.py
class FakeDatasetMeta (line 21) | class FakeDatasetMeta(object):
method get_true_label (line 24) | def get_true_label(self, _):
method get_target_class (line 27) | def get_target_class(self, _):
class ClassificationResultsTest (line 31) | class ClassificationResultsTest(unittest.TestCase):
method setUp (line 32) | def setUp(self):
method verify_classification_batches (line 66) | def verify_classification_batches(self, class_batches):
method test_init_from_adv_batches_and_submissions (line 116) | def test_init_from_adv_batches_and_submissions(self):
method test_read_batch_from_datastore (line 130) | def test_read_batch_from_datastore(self):
method test_compute_classification_results_from_defense_work (line 147) | def test_compute_classification_results_from_defense_work(self):
method test_read_classification_results (line 295) | def test_read_classification_results(self):
method test_analyze_one_classification_result (line 304) | def test_analyze_one_classification_result(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/tests/fake_cloud_client.py
class FakeBlob (line 13) | class FakeBlob(object):
method __init__ (line 16) | def __init__(self, content):
method download_to_file (line 24) | def download_to_file(self, fobj):
class FakeStorageClient (line 29) | class FakeStorageClient(object):
method __init__ (line 32) | def __init__(self, blobs=None):
method list_blobs (line 52) | def list_blobs(self, prefix=""):
method get_blob (line 56) | def get_blob(self, blob_name):
method new_blob (line 63) | def new_blob(self, blob_name):
class FakeDatastoreKey (line 69) | class FakeDatastoreKey(object):
method __init__ (line 75) | def __init__(self, *args, **kwargs):
method flat_path (line 85) | def flat_path(self):
method __hash__ (line 88) | def __hash__(self):
method __eq__ (line 91) | def __eq__(self, other):
method __ne__ (line 96) | def __ne__(self, other):
method __str__ (line 99) | def __str__(self):
method __repr__ (line 102) | def __repr__(self):
class FakeDatastoreEntity (line 106) | class FakeDatastoreEntity(dict):
method __init__ (line 112) | def __init__(self, key):
method key (line 119) | def key(self):
method __eq__ (line 122) | def __eq__(self, other):
method __ne__ (line 127) | def __ne__(self, other):
method __str__ (line 130) | def __str__(self):
method __repr__ (line 133) | def __repr__(self):
function make_entity (line 139) | def make_entity(key):
class FakeDatastoreClientBatch (line 155) | class FakeDatastoreClientBatch(object):
method __init__ (line 158) | def __init__(self, fake_datastore_client):
method __enter__ (line 163) | def __enter__(self):
method __exit__ (line 166) | def __exit__(self, exc_type, exc_value, traceback):
method put (line 171) | def put(self, entity):
class FakeDatastoreClientTransaction (line 177) | class FakeDatastoreClientTransaction(object):
method __init__ (line 184) | def __init__(self, fake_datastore_client):
method _check_transaction_started (line 197) | def _check_transaction_started(self):
method _check_update_state (line 205) | def _check_update_state(self, old_state, new_state):
method begin (line 214) | def begin(self):
method commit (line 218) | def commit(self):
method rollback (line 239) | def rollback(self):
method put (line 244) | def put(self, entity):
method get (line 250) | def get(self, key):
method __enter__ (line 257) | def __enter__(self):
method __exit__ (line 261) | def __exit__(self, exc_type, exc_value, traceback):
class FakeDatastoreClient (line 277) | class FakeDatastoreClient(object):
method __init__ (line 280) | def __init__(self, entities=None):
method entities (line 294) | def entities(self):
method key (line 298) | def key(self, *args, **kwargs):
method entity (line 302) | def entity(self, key):
method no_transact_batch (line 307) | def no_transact_batch(self):
method transaction (line 311) | def transaction(self):
method get (line 319) | def get(self, key, transaction=None):
method put (line 326) | def put(self, entity):
method batch (line 335) | def batch(self):
method query_fetch (line 339) | def query_fetch(self, **kwargs):
method set_transaction_hook (line 371) | def set_transaction_hook(self, hook):
method __str__ (line 390) | def __str__(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/tests/fake_cloud_client_test.py
class FakeStorageClientTest (line 15) | class FakeStorageClientTest(unittest.TestCase):
method test_list_blobs (line 16) | def test_list_blobs(self):
method test_get_blob (line 36) | def test_get_blob(self):
class FakeDatastoreKeyTest (line 46) | class FakeDatastoreKeyTest(unittest.TestCase):
method test_flat_path (line 47) | def test_flat_path(self):
method test_equality (line 53) | def test_equality(self):
class FakeDatastoreEntityTest (line 74) | class FakeDatastoreEntityTest(unittest.TestCase):
method test_key (line 75) | def test_key(self):
method test_equality_keys (line 79) | def test_equality_keys(self):
method test_equality_dict (line 88) | def test_equality_dict(self):
method test_copy (line 111) | def test_copy(self):
method test_deep_copy (line 125) | def test_deep_copy(self):
class FakeDatastoreClientTest (line 140) | class FakeDatastoreClientTest(unittest.TestCase):
method setUp (line 141) | def setUp(self):
method test_make_key (line 151) | def test_make_key(self):
method test_make_entity (line 155) | def test_make_entity(self):
method test_put_entity (line 158) | def test_put_entity(self):
method test_get_entity (line 168) | def test_get_entity(self):
method test_write_batch (line 174) | def test_write_batch(self):
method test_overwrite_values (line 186) | def test_overwrite_values(self):
method test_query_fetch_all (line 205) | def test_query_fetch_all(self):
method test_query_fetch_kind_filter (line 213) | def test_query_fetch_kind_filter(self):
method test_query_fetch_ancestor_filter (line 222) | def test_query_fetch_ancestor_filter(self):
method test_query_fetch_ancestor_and_kind_filter (line 235) | def test_query_fetch_ancestor_and_kind_filter(self):
method test_query_fetch_data_filter (line 249) | def test_query_fetch_data_filter(self):
class FakeDatastoreClientTransactionTest (line 280) | class FakeDatastoreClientTransactionTest(unittest.TestCase):
method setUp (line 281) | def setUp(self):
method test_transaction_write_only_no_concurrent (line 311) | def test_transaction_write_only_no_concurrent(self):
method test_transaction_read_write_no_concurrent (line 338) | def test_transaction_read_write_no_concurrent(self):
method test_transaction_read_write_concurrent_not_intersecting (line 375) | def test_transaction_read_write_concurrent_not_intersecting(self):
method test_transaction_write_concurrent (line 416) | def test_transaction_write_concurrent(self):
method test_transaction_read_concurrent (line 448) | def test_transaction_read_concurrent(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/tests/image_batches_test.py
class ImageBatchesBaseTest (line 20) | class ImageBatchesBaseTest(unittest.TestCase):
method setUp (line 21) | def setUp(self):
method test_add_batch (line 29) | def test_add_batch(self):
method test_add_image (line 42) | def test_add_image(self):
method test_write_to_datastore (line 64) | def test_write_to_datastore(self):
method test_write_single_batch_images_to_datastore (line 102) | def test_write_single_batch_images_to_datastore(self):
class DatasetBatchesTest (line 125) | class DatasetBatchesTest(unittest.TestCase):
method setUp (line 126) | def setUp(self):
method verify_dataset_batches (line 143) | def verify_dataset_batches(self):
method verify_datastore_entities (line 169) | def verify_datastore_entities(self):
method test_init_from_storage (line 200) | def test_init_from_storage(self):
method test_init_from_datastore (line 205) | def test_init_from_datastore(self):
method test_count_num_images (line 215) | def test_count_num_images(self):
class AdversarialBatchesTest (line 220) | class AdversarialBatchesTest(unittest.TestCase):
method setUp (line 221) | def setUp(self):
method verify_adversarial_batches_without_images (line 252) | def verify_adversarial_batches_without_images(self, adv_batches):
method test_init_from_dataset_and_submissions (line 263) | def test_init_from_dataset_and_submissions(self):
method test_init_from_datastore (line 273) | def test_init_from_datastore(self):
method test_count_generated_adv_examples (line 289) | def test_count_generated_adv_examples(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/tests/submissions_test.py
class ParticipantFromSubmissionPathTest (line 18) | class ParticipantFromSubmissionPathTest(unittest.TestCase):
method test_team_id (line 19) | def test_team_id(self):
method test_baseline_id (line 24) | def test_baseline_id(self):
method test_tar_extension (line 30) | def test_tar_extension(self):
method test_tar_gz_extension (line 35) | def test_tar_gz_extension(self):
class SubmissionsTest (line 42) | class SubmissionsTest(unittest.TestCase):
method setUp (line 43) | def setUp(self):
method verify_submissions (line 60) | def verify_submissions(self):
method verify_datastore_entities (line 114) | def verify_datastore_entities(self):
method test_init_from_storage (line 155) | def test_init_from_storage(self):
method test_init_from_datastore (line 160) | def test_init_from_datastore(self):
method test_get_all_attacks_ids (line 175) | def test_get_all_attacks_ids(self):
method test_find_by_id (line 185) | def test_find_by_id(self):
method test_get_external_id (line 198) | def test_get_external_id(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/tests/work_data_test.py
class WorkPiecesBaseTest (line 20) | class WorkPiecesBaseTest(unittest.TestCase):
method setUp (line 21) | def setUp(self):
method reset_work_pieces (line 38) | def reset_work_pieces(self):
method test_is_unclaimed (line 43) | def test_is_unclaimed(self):
method test_write_to_datastore (line 58) | def test_write_to_datastore(self):
method test_read_from_datastore (line 90) | def test_read_from_datastore(self):
method test_is_all_work_completed (line 102) | def test_is_all_work_completed(self):
method test_read_undone_from_datastore (line 116) | def test_read_undone_from_datastore(self):
method test_read_undone_from_datastore_same_shards (line 127) | def test_read_undone_from_datastore_same_shards(self):
method test_read_undone_from_datastore_different_shards (line 142) | def test_read_undone_from_datastore_different_shards(self):
method test_try_pick_piece_of_work_simple (line 157) | def test_try_pick_piece_of_work_simple(self):
method test_try_pick_piece_of_work_all_completed (line 168) | def test_try_pick_piece_of_work_all_completed(self):
method test_try_pick_piece_of_work_already_claimed (line 177) | def test_try_pick_piece_of_work_already_claimed(self):
method test_try_pick_piece_of_work_claimed_long_ago (line 188) | def test_try_pick_piece_of_work_claimed_long_ago(self):
method test_try_pick_piece_of_work_concurrent_update (line 202) | def test_try_pick_piece_of_work_concurrent_update(self):
method test_try_pick_piece_of_work_concurrent_update_of_other (line 217) | def test_try_pick_piece_of_work_concurrent_update_of_other(self):
method test_update_work_as_completed (line 233) | def test_update_work_as_completed(self):
method test_update_work_as_completed_other_values (line 246) | def test_update_work_as_completed_other_values(self):
method test_update_work_as_completed_with_error (line 265) | def test_update_work_as_completed_with_error(self):
method test_update_work_as_completed_wrong_claimed_worker (line 280) | def test_update_work_as_completed_wrong_claimed_worker(self):
method test_compute_work_stats (line 294) | def test_compute_work_stats(self):
class AttackWorkPiecesTest (line 366) | class AttackWorkPiecesTest(unittest.TestCase):
method setUp (line 367) | def setUp(self):
method test_init_from_adversarial_batches (line 370) | def test_init_from_adversarial_batches(self):
class DefenseWorkPiecesTest (line 417) | class DefenseWorkPiecesTest(unittest.TestCase):
method setUp (line 418) | def setUp(self):
method test_init_from_classification_batches (line 421) | def test_init_from_classification_batches(self):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/work_data.py
function get_integer_time (line 41) | def get_integer_time():
function is_unclaimed (line 46) | def is_unclaimed(work):
class WorkPiecesBase (line 60) | class WorkPiecesBase(object):
method __init__ (line 92) | def __init__(self, datastore_client, work_type_entity_id):
method serialize (line 118) | def serialize(self, fobj):
method deserialize (line 122) | def deserialize(self, fobj):
method work (line 127) | def work(self):
method replace_work (line 131) | def replace_work(self, value):
method __len__ (line 143) | def __len__(self):
method is_all_work_competed (line 146) | def is_all_work_competed(self):
method write_all_to_datastore (line 150) | def write_all_to_datastore(self):
method read_all_from_datastore (line 171) | def read_all_from_datastore(self):
method _read_undone_shard_from_datastore (line 180) | def _read_undone_shard_from_datastore(self, shard_id=None):
method read_undone_from_datastore (line 196) | def read_undone_from_datastore(self, shard_id=None, num_shards=None):
method try_pick_piece_of_work (line 223) | def try_pick_piece_of_work(self, worker_id, submission_id=None):
method update_work_as_completed (line 266) | def update_work_as_completed(
method compute_work_statistics (line 301) | def compute_work_statistics(self):
method __str__ (line 333) | def __str__(self):
class AttackWorkPieces (line 345) | class AttackWorkPieces(WorkPiecesBase):
method __init__ (line 348) | def __init__(self, datastore_client):
method init_from_adversarial_batches (line 355) | def init_from_adversarial_batches(self, adv_batches):
class DefenseWorkPieces (line 376) | class DefenseWorkPieces(WorkPiecesBase):
method __init__ (line 379) | def __init__(self, datastore_client):
method init_from_class_batches (line 386) | def init_from_class_batches(self, class_batches, num_shards=None):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/master.py
function print_header (line 40) | def print_header(text):
function save_dict_to_file (line 49) | def save_dict_to_file(filename, dictionary):
class EvaluationMaster (line 57) | class EvaluationMaster(object):
method __init__ (line 60) | def __init__(
method ask_when_work_is_populated (line 132) | def ask_when_work_is_populated(self, work):
method prepare_attacks (line 158) | def prepare_attacks(self):
method prepare_defenses (line 197) | def prepare_defenses(self):
method _save_work_results (line 227) | def _save_work_results(self, run_stats, scores, num_processed_images, ...
method _save_sorted_results (line 285) | def _save_sorted_results(self, run_stats, scores, image_count, filename):
method _read_dataset_metadata (line 320) | def _read_dataset_metadata(self):
method compute_results (line 334) | def compute_results(self):
method _show_status_for_work (line 560) | def _show_status_for_work(self, work):
method _export_work_errors (line 594) | def _export_work_errors(self, work, output_file):
method show_status (line 610) | def show_status(self):
method cleanup_failed_attacks (line 629) | def cleanup_failed_attacks(self):
method cleanup_attacks_with_zero_images (line 662) | def cleanup_attacks_with_zero_images(self):
method _cleanup_keys_with_confirmation (line 728) | def _cleanup_keys_with_confirmation(self, keys_to_delete):
method cleanup_defenses (line 771) | def cleanup_defenses(self):
method cleanup_datastore (line 786) | def cleanup_datastore(self):
function main (line 818) | def main(args):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/worker.py
function make_directory_writable (line 93) | def make_directory_writable(dirname):
function sudo_remove_dirtree (line 122) | def sudo_remove_dirtree(dir_name):
class WorkerError (line 138) | class WorkerError(Exception):
method __init__ (line 146) | def __init__(self, message, exc=None):
method __str__ (line 157) | def __str__(self):
function get_id_of_running_docker (line 165) | def get_id_of_running_docker(container_name):
function is_docker_still_running (line 172) | def is_docker_still_running(container_name):
function kill_docker_container (line 177) | def kill_docker_container(container_name):
class ExecutableSubmission (line 183) | class ExecutableSubmission(object):
method __init__ (line 186) | def __init__(self, submission_id, submissions, storage_bucket):
method download (line 217) | def download(self):
method temp_copy_extracted_submission (line 335) | def temp_copy_extracted_submission(self):
method run_without_time_limit (line 352) | def run_without_time_limit(self, cmd):
method run_with_time_limit (line 377) | def run_with_time_limit(self, cmd, time_limit=SUBMISSION_TIME_LIMIT):
class AttackSubmission (line 422) | class AttackSubmission(ExecutableSubmission):
method __init__ (line 425) | def __init__(self, submission_id, submissions, storage_bucket):
method run (line 444) | def run(self, input_dir, output_dir, epsilon):
class DefenseSubmission (line 481) | class DefenseSubmission(ExecutableSubmission):
method __init__ (line 484) | def __init__(self, submission_id, submissions, storage_bucket):
method run (line 503) | def run(self, input_dir, output_file_path):
class EvaluationWorker (line 539) | class EvaluationWorker(object):
method __init__ (line 547) | def __init__(
method read_dataset_metadata (line 618) | def read_dataset_metadata(self):
method fetch_attacks_data (line 638) | def fetch_attacks_data(self):
method run_attack_work (line 664) | def run_attack_work(self, work_id):
method run_attacks (line 771) | def run_attacks(self):
method fetch_defense_data (line 823) | def fetch_defense_data(self):
method run_defense_work (line 837) | def run_defense_work(self, work_id):
method run_defenses (line 939) | def run_defenses(self):
method run_work (line 1022) | def run_work(self):
function main (line 1030) | def main(args):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/validation_tool/validate_and_copy_submissions.py
class ValidationStats (line 57) | class ValidationStats(object):
method __init__ (line 60) | def __init__(self):
method _update_stat (line 64) | def _update_stat(self, submission_type, increase_success, increase_fail):
method add_success (line 70) | def add_success(self, submission_type):
method add_failure (line 74) | def add_failure(self, submission_type="unknown"):
method log_stats (line 78) | def log_stats(self):
class SubmissionValidator (line 87) | class SubmissionValidator(object):
method __init__ (line 90) | def __init__(
method copy_submission_locally (line 123) | def copy_submission_locally(self, cloud_path):
method copy_submission_to_destination (line 139) | def copy_submission_to_destination(self, src_filename, dst_subdir, sub...
method validate_and_copy_one_submission (line 163) | def validate_and_copy_one_submission(self, submission_path):
method save_id_to_path_mapping (line 198) | def save_id_to_path_mapping(self):
method run (line 219) | def run(self):
function main (line 240) | def main(args):
FILE: cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/validation_tool/validate_submission_lib.py
function get_extract_command_template (line 44) | def get_extract_command_template(filename):
function shell_call (line 52) | def shell_call(command, **kwargs):
function make_directory_writable (line 77) | def make_directory_writable(dirname):
function load_defense_output (line 109) | def load_defense_output(filename):
class SubmissionValidator (line 125) | class SubmissionValidator(object):
method __init__ (line 128) | def __init__(self, temp_dir, use_gpu):
method _prepare_temp_dir (line 142) | def _prepare_temp_dir(self):
method _extract_submission (line 156) | def _extract_submission(self, filename):
method _verify_submission_size (line 219) | def _verify_submission_size(self):
method _load_and_verify_metadata (line 231) | def _load_and_verify_metadata(self):
method _verify_docker_image_size (line 275) | def _verify_docker_image_size(self, image_name):
method _prepare_sample_data (line 298) | def _prepare_sample_data(self, submission_type):
method _run_submission (line 324) | def _run_submission(self, metadata):
method _verify_output (line 383) | def _verify_output(self, submission_type):
method validate_submission (line 425) | def validate_submission(self, filename):
FILE: cleverhans_v3.1.0/examples/robust_vision_benchmark/cleverhans_attack_example/main.py
function attack (line 9) | def attack(model, session, a):
FILE: cleverhans_v3.1.0/examples/robust_vision_benchmark/cleverhans_attack_example/utils.py
function cleverhans_attack_wrapper (line 6) | def cleverhans_attack_wrapper(cleverhans_attack_fn, reset=True):
function py_func_grad (line 26) | def py_func_grad(func, inp, Tout, stateful=True, name=None, grad=None):
class RVBCleverhansModel (line 37) | class RVBCleverhansModel(cleverhans.model.Model):
method __init__ (line 40) | def __init__(self, adversarial, **kwargs):
method fprop (line 47) | def fprop(self, x):
method _logits_op (line 50) | def _logits_op(self, x, name=None):
FILE: cleverhans_v3.1.0/examples/test_imagenet_attacks.py
function load_images (line 73) | def load_images(input_dir, metadata_file_path, batch_shape):
class InceptionModel (line 96) | class InceptionModel(Model):
method __init__ (line 99) | def __init__(self, nb_classes):
method __call__ (line 105) | def __call__(self, x_input, return_logits=False):
method get_logits (line 123) | def get_logits(self, x_input):
method get_probs (line 126) | def get_probs(self, x_input):
function _top_1_accuracy (line 130) | def _top_1_accuracy(logits, labels):
class TestInception (line 134) | class TestInception(CleverHansTest):
method test_clean_accuracy (line 135) | def test_clean_accuracy(self):
class TestSPSA (line 168) | class TestSPSA(CleverHansTest):
method test_attack_bounds (line 169) | def test_attack_bounds(self):
method test_attack_success (line 219) | def test_attack_success(self):
FILE: cleverhans_v3.1.0/scripts/compute_accuracy.py
function print_accuracies (line 54) | def print_accuracies(
function impl (line 107) | def impl(
function main (line 189) | def main(argv=None):
FILE: cleverhans_v3.1.0/scripts/make_confidence_report.py
function main (line 57) | def main(argv=None):
FILE: cleverhans_v3.1.0/scripts/make_confidence_report_bundle_examples.py
function main (line 49) | def main(argv=None):
FILE: cleverhans_v3.1.0/scripts/make_confidence_report_bundled.py
function main (line 43) | def main(argv=None):
FILE: cleverhans_v3.1.0/scripts/make_confidence_report_spsa.py
function make_confidence_report_spsa (line 59) | def make_confidence_report_spsa(
function main (line 154) | def main(argv=None):
FILE: cleverhans_v3.1.0/scripts/plot_success_fail_curve.py
function main (line 28) | def main(argv=None):
FILE: cleverhans_v3.1.0/scripts/print_report.py
function current (line 24) | def current(report):
function deprecated (line 47) | def deprecated(report):
FILE: cleverhans_v3.1.0/tests_tf/test_attack_bundling.py
function test_unfinished_attack_configs (line 10) | def test_unfinished_attack_configs():
function test_misclassify_request_examples (line 54) | def test_misclassify_request_examples():
FILE: cleverhans_v3.1.0/tests_tf/test_attacks.py
class SimpleModel (line 39) | class SimpleModel(Model):
method __init__ (line 44) | def __init__(self, scope="simple", nb_classes=2, **kwargs):
method fprop (line 48) | def fprop(self, x, **kwargs):
class TrivialModel (line 58) | class TrivialModel(Model):
method __init__ (line 63) | def __init__(self, scope="trivial", nb_classes=2, **kwargs):
method fprop (line 67) | def fprop(self, x, **kwargs):
class DummyModel (line 75) | class DummyModel(Model):
method __init__ (line 80) | def __init__(self, scope="dummy_model", nb_classes=10, **kwargs):
method fprop (line 84) | def fprop(self, x, **kwargs):
class TestAttackClassInitArguments (line 93) | class TestAttackClassInitArguments(CleverHansTest):
method test_model (line 94) | def test_model(self):
method test_sess (line 103) | def test_sess(self):
method test_sess_generate_np (line 110) | def test_sess_generate_np(self):
class TestParseParams (line 127) | class TestParseParams(CleverHansTest):
method test_parse (line 128) | def test_parse(self):
class TestVirtualAdversarialMethod (line 135) | class TestVirtualAdversarialMethod(CleverHansTest):
method setUp (line 136) | def setUp(self):
method test_parse_params (line 149) | def test_parse_params(self):
method test_generate_np (line 158) | def test_generate_np(self):
class CommonAttackProperties (line 166) | class CommonAttackProperties(CleverHansTest):
method setUp (line 172) | def setUp(self):
method generate_adversarial_examples_np (line 188) | def generate_adversarial_examples_np(self, ord, eps, **kwargs):
method help_generate_np_gives_adversarial_example (line 204) | def help_generate_np_gives_adversarial_example(self, ord, eps=0.5, **k...
method test_invalid_input (line 211) | def test_invalid_input(self):
method test_generate_np_gives_adversarial_example_linfinity (line 217) | def test_generate_np_gives_adversarial_example_linfinity(self):
method test_generate_np_gives_adversarial_example_l1 (line 220) | def test_generate_np_gives_adversarial_example_l1(self):
method test_generate_np_gives_adversarial_example_l2 (line 223) | def test_generate_np_gives_adversarial_example_l2(self):
method test_generate_respects_dtype (line 226) | def test_generate_respects_dtype(self):
method test_targeted_generate_np_gives_adversarial_example (line 232) | def test_targeted_generate_np_gives_adversarial_example(self):
method test_generate_np_can_be_called_with_different_eps (line 249) | def test_generate_np_can_be_called_with_different_eps(self):
method test_generate_can_be_called_with_different_eps (line 261) | def test_generate_can_be_called_with_different_eps(self):
method test_generate_np_clip_works_as_expected (line 280) | def test_generate_np_clip_works_as_expected(self):
class TestFastGradientMethod (line 292) | class TestFastGradientMethod(CommonAttackProperties):
method setUp (line 293) | def setUp(self):
class TestOptimizeLinear (line 299) | class TestOptimizeLinear(CleverHansTest):
method setUp (line 304) | def setUp(self):
method test_optimize_linear_linf (line 309) | def test_optimize_linear_linf(self):
method test_optimize_linear_l2 (line 327) | def test_optimize_linear_l2(self):
method test_optimize_linear_l1 (line 345) | def test_optimize_linear_l1(self):
method test_optimize_linear_l1_ties (line 376) | def test_optimize_linear_l1_ties(self):
class TestSPSA (line 404) | class TestSPSA(CleverHansTest):
method setUp (line 405) | def setUp(self):
method test_attack_strength (line 412) | def test_attack_strength(self):
method test_attack_strength_np (line 450) | def test_attack_strength_np(self):
method test_attack_strength_np_batched (line 476) | def test_attack_strength_np_batched(self):
method test_label_argument_int64 (line 497) | def test_label_argument_int64(self):
class TestProjectedGradientDescent (line 515) | class TestProjectedGradientDescent(CommonAttackProperties):
method setUp (line 516) | def setUp(self):
method test_generate_np_gives_adversarial_example_linfinity (line 523) | def test_generate_np_gives_adversarial_example_linfinity(self):
method test_generate_np_gives_adversarial_example_l1 (line 528) | def test_generate_np_gives_adversarial_example_l1(self):
method test_generate_np_gives_adversarial_example_l2 (line 534) | def test_generate_np_gives_adversarial_example_l2(self):
method test_do_not_reach_lp_boundary (line 537) | def test_do_not_reach_lp_boundary(self):
method test_attack_strength_linf (line 553) | def test_attack_strength_linf(self):
method test_attack_strength_l2 (line 578) | def test_attack_strength_l2(self):
method test_grad_clip_l2 (line 598) | def test_grad_clip_l2(self):
method test_clip_eta_linf (line 619) | def test_clip_eta_linf(self):
method test_clip_eta_l2 (line 630) | def test_clip_eta_l2(self):
method test_generate_np_gives_clipped_adversarial_examples (line 640) | def test_generate_np_gives_clipped_adversarial_examples(self):
method test_generate_np_does_not_cache_graph_computation_for_nb_iter (line 663) | def test_generate_np_does_not_cache_graph_computation_for_nb_iter(self):
method test_multiple_initial_random_step (line 701) | def test_multiple_initial_random_step(self):
class TestSparseL1Descent (line 734) | class TestSparseL1Descent(CleverHansTest):
method setUp (line 735) | def setUp(self):
method generate_adversarial_examples_np (line 742) | def generate_adversarial_examples_np(self, eps, **kwargs):
method help_generate_np_gives_adversarial_example (line 753) | def help_generate_np_gives_adversarial_example(self, eps=2.0, **kwargs):
method test_invalid_input (line 760) | def test_invalid_input(self):
method test_generate_np_gives_adversarial_example (line 766) | def test_generate_np_gives_adversarial_example(self):
method test_targeted_generate_np_gives_adversarial_example (line 769) | def test_targeted_generate_np_gives_adversarial_example(self):
method test_generate_np_can_be_called_with_different_eps (line 783) | def test_generate_np_can_be_called_with_different_eps(self):
method test_generate_can_be_called_with_different_eps (line 793) | def test_generate_can_be_called_with_different_eps(self):
method test_generate_np_clip_works_as_expected (line 810) | def test_generate_np_clip_works_as_expected(self):
method test_do_not_reach_lp_boundary (line 827) | def test_do_not_reach_lp_boundary(self):
method test_generate_np_gives_clipped_adversarial_examples (line 840) | def test_generate_np_gives_clipped_adversarial_examples(self):
method test_generate_np_does_not_cache_graph_computation_for_nb_iter (line 857) | def test_generate_np_does_not_cache_graph_computation_for_nb_iter(self):
method test_clip_eta (line 895) | def test_clip_eta(self):
method test_attack_strength (line 905) | def test_attack_strength(self):
method test_grad_clip (line 930) | def test_grad_clip(self):
method test_sparsity (line 955) | def test_sparsity(self):
method test_grad_sparsity_checks (line 977) | def test_grad_sparsity_checks(self):
class TestCarliniWagnerL2 (line 1011) | class TestCarliniWagnerL2(CleverHansTest):
method setUp (line 1012) | def setUp(self):
method test_generate_np_untargeted_gives_adversarial_example (line 1019) | def test_generate_np_untargeted_gives_adversarial_example(self):
method test_generate_np_targeted_gives_adversarial_example (line 1038) | def test_generate_np_targeted_gives_adversarial_example(self):
method test_generate_gives_adversarial_example (line 1059) | def test_generate_gives_adversarial_example(self):
method test_generate_np_gives_clipped_adversarial_examples (line 1087) | def test_generate_np_gives_clipped_adversarial_examples(self):
method test_generate_np_high_confidence_targeted_examples (line 1105) | def test_generate_np_high_confidence_targeted_examples(self):
method test_generate_np_high_confidence_untargeted_examples (line 1140) | def test_generate_np_high_confidence_untargeted_examples(self):
class TestElasticNetMethod (line 1175) | class TestElasticNetMethod(CleverHansTest):
method setUp (line 1176) | def setUp(self):
method test_generate_np_untargeted_gives_adversarial_example (line 1183) | def test_generate_np_untargeted_gives_adversarial_example(self):
method test_generate_np_targeted_gives_adversarial_example (line 1202) | def test_generate_np_targeted_gives_adversarial_example(self):
method test_generate_gives_adversarial_example (line 1223) | def test_generate_gives_adversarial_example(self):
method test_generate_np_gives_clipped_adversarial_examples (line 1251) | def test_generate_np_gives_clipped_adversarial_examples(self):
method test_generate_np_high_confidence_targeted_examples (line 1269) | def test_generate_np_high_confidence_targeted_examples(self):
method test_generate_np_high_confidence_untargeted_examples (line 1306) | def test_generate_np_high_confidence_untargeted_examples(self):
class TestSaliencyMapMethod (line 1341) | class TestSaliencyMapMethod(CleverHansTest):
method setUp (line 1342) | def setUp(self):
method test_generate_np_targeted_gives_adversarial_example (line 1357) | def test_generate_np_targeted_gives_adversarial_example(self):
class TestDeepFool (line 1372) | class TestDeepFool(CleverHansTest):
method setUp (line 1373) | def setUp(self):
method test_generate_np_gives_adversarial_example (line 1380) | def test_generate_np_gives_adversarial_example(self):
method test_generate_gives_adversarial_example (line 1393) | def test_generate_gives_adversarial_example(self):
method test_generate_np_gives_clipped_adversarial_examples (line 1410) | def test_generate_np_gives_clipped_adversarial_examples(self):
class TestMomentumIterativeMethod (line 1427) | class TestMomentumIterativeMethod(TestProjectedGradientDescent):
method setUp (line 1428) | def setUp(self):
method test_generate_np_can_be_called_with_different_decay_factor (line 1433) | def test_generate_np_can_be_called_with_different_decay_factor(self):
method test_multiple_initial_random_step (line 1450) | def test_multiple_initial_random_step(self):
class TestMadryEtAl (line 1455) | class TestMadryEtAl(CleverHansTest):
method setUp (line 1456) | def setUp(self):
method test_attack_can_be_constructed (line 1461) | def test_attack_can_be_constructed(self):
class TestBasicIterativeMethod (line 1466) | class TestBasicIterativeMethod(CleverHansTest):
method setUp (line 1467) | def setUp(self):
method test_attack_can_be_constructed (line 1472) | def test_attack_can_be_constructed(self):
class TestFastFeatureAdversaries (line 1477) | class TestFastFeatureAdversaries(CleverHansTest):
method setUp (line 1478) | def setUp(self):
method test_attack_strength (line 1524) | def test_attack_strength(self):
class TestLBFGS (line 1572) | class TestLBFGS(CleverHansTest):
method setUp (line 1573) | def setUp(self):
method test_generate_np_targeted_gives_adversarial_example (line 1580) | def test_generate_np_targeted_gives_adversarial_example(self):
method test_generate_targeted_gives_adversarial_example (line 1601) | def test_generate_targeted_gives_adversarial_example(self):
method test_generate_np_gives_clipped_adversarial_examples (line 1627) | def test_generate_np_gives_clipped_adversarial_examples(self):
class SimpleSpatialBrightPixelModel (line 1648) | class SimpleSpatialBrightPixelModel(Model):
method __init__ (line 1655) | def __init__(self, scope="simple_spatial", nb_classes=2, **kwargs):
method fprop (line 1659) | def fprop(self, x, **kwargs):
class TestSpatialTransformationMethod (line 1673) | class TestSpatialTransformationMethod(CleverHansTest):
method setUp (line 1676) | def setUp(self):
method test_no_transformation (line 1691) | def test_no_transformation(self):
method test_push_pixels_off_image (line 1713) | def test_push_pixels_off_image(self):
method test_keep_pixels_on_image (line 1745) | def test_keep_pixels_on_image(self):
class TestHopSkipJumpAttack (line 1778) | class TestHopSkipJumpAttack(CleverHansTest):
method setUp (line 1781) | def setUp(self):
method test_generate_np_untargeted_l2 (line 1788) | def test_generate_np_untargeted_l2(self):
method test_generate_untargeted_linf (line 1804) | def test_generate_untargeted_linf(self):
method test_generate_np_targeted_linf (line 1834) | def test_generate_np_targeted_linf(self):
method test_generate_targeted_l2 (line 1860) | def test_generate_targeted_l2(self):
FILE: cleverhans_v3.1.0/tests_tf/test_attacks_tf.py
class SimpleModel (line 23) | class SimpleModel(Model):
method __init__ (line 28) | def __init__(self, scope="simple", nb_classes=2, **kwargs):
method fprop (line 32) | def fprop(self, x, **kwargs):
class TestAttackTF (line 42) | class TestAttackTF(CleverHansTest):
method setUp (line 43) | def setUp(self):
method test_fgm_gradient_max (line 48) | def test_fgm_gradient_max(self):
method helper_pgd_attack (line 69) | def helper_pgd_attack(
method test_pgd_untargeted_attack_with_adam_optimizer (line 138) | def test_pgd_untargeted_attack_with_adam_optimizer(self):
method test_stronger_pgd_untargeted_attack_with_adam_optimizer (line 150) | def test_stronger_pgd_untargeted_attack_with_adam_optimizer(self):
method test_pgd_targeted_attack_with_adam_optimizer (line 162) | def test_pgd_targeted_attack_with_adam_optimizer(self):
method test_stronger_pgd_targeted_attack_with_adam_optimizer (line 174) | def test_stronger_pgd_targeted_attack_with_adam_optimizer(self):
method test_pgd_untargeted_attack_with_sgd_optimizer (line 186) | def test_pgd_untargeted_attack_with_sgd_optimizer(self):
method test_stronger_pgd_untargeted_attack_with_sgd_optimizer (line 198) | def test_stronger_pgd_untargeted_attack_with_sgd_optimizer(self):
method test_pgd_targeted_attack_with_sgd_optimizer (line 210) | def test_pgd_targeted_attack_with_sgd_optimizer(self):
method test_stronger_pgd_targeted_attack_with_sgd_optimizer (line 222) | def test_stronger_pgd_targeted_attack_with_sgd_optimizer(self):
method test_parallel_apply (line 235) | def test_parallel_apply(self):
FILE: cleverhans_v3.1.0/tests_tf/test_confidence_report.py
function test_confidence_report (line 20) | def test_confidence_report():
function test_make_confidence_report_bundled (line 33) | def test_make_confidence_report_bundled():
function test_save_load_confidence_report (line 98) | def test_save_load_confidence_report():
FILE: cleverhans_v3.1.0/tests_tf/test_dataset.py
class LightweightDataset (line 6) | class LightweightDataset(Dataset):
class TestDataset (line 13) | class TestDataset(CleverHansTest):
method test_factory (line 18) | def test_factory(self):
FILE: cleverhans_v3.1.0/tests_tf/test_defenses.py
class SimpleModel (line 18) | class SimpleModel(Model):
method __init__ (line 23) | def __init__(self, scope="simple", nb_classes=2, **kwargs):
method fprop (line 27) | def fprop(self, x, **kwargs):
class TestDefenses (line 41) | class TestDefenses(CleverHansTest):
method setUp (line 42) | def setUp(self):
method test_xe (line 50) | def test_xe(self):
method test_xe_smoothing (line 59) | def test_xe_smoothing(self):
method test_mixup (line 68) | def test_mixup(self):
method test_feature_pairing (line 84) | def test_feature_pairing(self):
FILE: cleverhans_v3.1.0/tests_tf/test_evaluation.py
class TestEvaluation (line 7) | class TestEvaluation(CleverHansTest):
method test_cache (line 10) | def test_cache(self):
FILE: cleverhans_v3.1.0/tests_tf/test_mnist_blackbox.py
class TestMNISTBlackboxF (line 12) | class TestMNISTBlackboxF(CleverHansTest):
method test_mnist_blackbox (line 13) | def test_mnist_blackbox(self):
FILE: cleverhans_v3.1.0/tests_tf/test_mnist_tutorial_cw.py
class TestMNISTTutorialCW (line 7) | class TestMNISTTutorialCW(CleverHansTest):
method test_mnist_tutorial_cw (line 8) | def test_mnist_tutorial_cw(self):
FILE: cleverhans_v3.1.0/tests_tf/test_mnist_tutorial_jsma.py
class TestMNISTTutorialJSMA (line 7) | class TestMNISTTutorialJSMA(CleverHansTest):
method test_mnist_tutorial_jsma (line 8) | def test_mnist_tutorial_jsma(self):
FILE: cleverhans_v3.1.0/tests_tf/test_mnist_tutorial_keras.py
class TestMNISTTutorialKeras (line 12) | class TestMNISTTutorialKeras(CleverHansTest):
method test_mnist_tutorial_keras (line 13) | def test_mnist_tutorial_keras(self):
FILE: cleverhans_v3.1.0/tests_tf/test_mnist_tutorial_keras_tf.py
class TestMNISTTutorialKerasTF (line 12) | class TestMNISTTutorialKerasTF(CleverHansTest):
method test_mnist_tutorial_keras_tf (line 13) | def test_mnist_tutorial_keras_tf(self):
FILE: cleverhans_v3.1.0/tests_tf/test_mnist_tutorial_tf.py
class TestMNISTTutorialTF (line 12) | class TestMNISTTutorialTF(CleverHansTest):
method test_mnist_tutorial_tf (line 13) | def test_mnist_tutorial_tf(self):
FILE: cleverhans_v3.1.0/tests_tf/test_model.py
class TestModelClass (line 14) | class TestModelClass(unittest.TestCase):
method test_get_logits (line 21) | def test_get_logits(self):
method test_get_probs (line 31) | def test_get_probs(self):
method test_fprop (line 41) | def test_fprop(self):
class TestCallableModelWrapperInitArguments (line 52) | class TestCallableModelWrapperInitArguments(unittest.TestCase):
method test_output_layer (line 57) | def test_output_layer(self):
FILE: cleverhans_v3.1.0/tests_tf/test_picklable_model.py
class TestPerImageStandardize (line 11) | class TestPerImageStandardize(CleverHansTest):
method setUp (line 16) | def setUp(self):
method run_and_check_output (line 33) | def run_and_check_output(self, x):
method test_random_inputs (line 40) | def test_random_inputs(self):
method test_ones_inputs (line 47) | def test_ones_inputs(self):
class TestDropout (line 55) | class TestDropout(CleverHansTest):
method test_no_drop (line 60) | def test_no_drop(self):
method test_drop (line 73) | def test_drop(self):
method test_override (line 92) | def test_override(self):
FILE: cleverhans_v3.1.0/tests_tf/test_projected_gradient_descent.py
function test_no_logits (line 15) | def test_no_logits():
function test_rejects_callable (line 36) | def test_rejects_callable():
FILE: cleverhans_v3.1.0/tests_tf/test_serial.py
class TestSerial (line 11) | class TestSerial(CleverHansTest):
method test_save_and_load_var (line 16) | def test_save_and_load_var(self):
FILE: cleverhans_v3.1.0/tests_tf/test_utils.py
class TestUtils (line 15) | class TestUtils(unittest.TestCase):
method test_to_categorical_with_nb_classes_arg (line 16) | def test_to_categorical_with_nb_classes_arg(self):
method test_random_targets_vector (line 21) | def test_random_targets_vector(self):
method test_random_targets_one_hot (line 33) | def test_random_targets_one_hot(self):
method test_random_targets_one_hot_single_label (line 48) | def test_random_targets_one_hot_single_label(self):
method test_other_classes_neg_class_ind (line 62) | def test_other_classes_neg_class_ind(self):
method test_other_classes_invalid_class_ind (line 67) | def test_other_classes_invalid_class_ind(self):
method test_other_classes_return_val (line 72) | def test_other_classes_return_val(self):
method test_get_logits_over_interval (line 77) | def test_get_logits_over_interval(self):
FILE: cleverhans_v3.1.0/tests_tf/test_utils_keras.py
class TestKerasModelWrapper (line 21) | class TestKerasModelWrapper(unittest.TestCase):
method setUp (line 22) | def setUp(self):
method test_softmax_layer_name_is_softmax (line 39) | def test_softmax_layer_name_is_softmax(self):
method test_logit_layer_name_is_logits (line 44) | def test_logit_layer_name_is_logits(self):
method test_get_logits (line 49) | def test_get_logits(self):
method test_get_probs (line 63) | def test_get_probs(self):
method test_get_layer_names (line 77) | def test_get_layer_names(self):
method test_fprop (line 82) | def test_fprop(self):
FILE: cleverhans_v3.1.0/tests_tf/test_utils_tf.py
function numpy_kl_with_logits (line 15) | def numpy_kl_with_logits(p_logits, q_logits):
class TestUtilsTF (line 27) | class TestUtilsTF(CleverHansTest):
method setUp (line 30) | def setUp(self):
method test_clip_by_value_numpy_dtype (line 34) | def test_clip_by_value_numpy_dtype(self):
method test_l2_batch_normalize (line 42) | def test_l2_batch_normalize(self):
method test_kl_with_logits (line 47) | def test_kl_with_logits(self):
method test_clip_eta_norm_0 (line 59) | def test_clip_eta_norm_0(self):
method test_clip_eta_goldilocks (line 76) | def test_clip_eta_goldilocks(self):
method test_zero_out_clipped_grads (line 102) | def test_zero_out_clipped_grads(self):
method test_random_lp_vector_linf (line 122) | def test_random_lp_vector_linf(self):
method test_random_lp_srandom_lp_vector_l1_l2 (line 143) | def test_random_lp_srandom_lp_vector_l1_l2(self):
FILE: docs/_static/doctools.js
function highlight (line 69) | function highlight(node, addItems) {
FILE: docs/_static/jquery-3.5.1.js
function DOMEval (line 103) | function DOMEval( code, node, doc ) {
function toType (line 133) | function toType( obj ) {
function isArrayLike (line 503) | function isArrayLike( obj ) {
function Sizzle (line 755) | function Sizzle( selector, context, results, seed ) {
function createCache (line 903) | function createCache() {
function markFunction (line 923) | function markFunction( fn ) {
function assert (line 932) | function assert( fn ) {
function addHandle (line 956) | function addHandle( attrs, handler ) {
function siblingCheck (line 971) | function siblingCheck( a, b ) {
function createInputPseudo (line 997) | function createInputPseudo( type ) {
function createButtonPseudo (line 1008) | function createButtonPseudo( type ) {
function createDisabledPseudo (line 1019) | function createDisabledPseudo( disabled ) {
function createPositionalPseudo (line 1075) | function createPositionalPseudo( fn ) {
function testContext (line 1098) | function testContext( context ) {
function setFilters (line 2309) | function setFilters() {}
function toSelector (line 2383) | function toSelector( tokens ) {
function addCombinator (line 2393) | function addCombinator( matcher, combinator, base ) {
function elementMatcher (line 2460) | function elementMatcher( matchers ) {
function multipleContexts (line 2474) | function multipleContexts( selector, contexts, results ) {
function condense (line 2483) | function condense( unmatched, map, filter, context, xml ) {
function setMatcher (line 2504) | function setMatcher( preFilter, selector, matcher, postFilter, postFinde...
function matcherFromTokens (line 2604) | function matcherFromTokens( tokens ) {
function matcherFromGroupMatchers (line 2667) | function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
function nodeName (line 3025) | function nodeName( elem, name ) {
function winnow (line 3035) | function winnow( elements, qualifier, not ) {
function sibling (line 3330) | function sibling( cur, dir ) {
function createOptions (line 3423) | function createOptions( options ) {
function Identity (line 3648) | function Identity( v ) {
function Thrower (line 3651) | function Thrower( ex ) {
function adoptValue (line 3655) | function adoptValue( value, resolve, reject, noValue ) {
function resolve (line 3748) | function resolve( depth, deferred, handler, special ) {
function completed (line 4113) | function completed() {
function fcamelCase (line 4208) | function fcamelCase( _all, letter ) {
function camelCase (line 4215) | function camelCase( string ) {
function Data (line 4232) | function Data() {
function getData (line 4401) | function getData( data ) {
function dataAttr (line 4426) | function dataAttr( elem, key, data ) {
function adjustCSS (line 4738) | function adjustCSS( elem, prop, valueParts, tween ) {
function getDefaultDisplay (line 4806) | function getDefaultDisplay( elem ) {
function showHide (line 4829) | function showHide( elements, show ) {
function getAll (line 4961) | function getAll( context, tag ) {
function setGlobalEval (line 4986) | function setGlobalEval( elems, refElements ) {
function buildFragment (line 5002) | function buildFragment( elems, context, scripts, selection, ignored ) {
function returnTrue (line 5097) | function returnTrue() {
function returnFalse (line 5101) | function returnFalse() {
function expectSync (line 5111) | function expectSync( elem, type ) {
function safeActiveElement (line 5118) | function safeActiveElement() {
function on (line 5124) | function on( elem, types, selector, data, fn, one ) {
function leverageNative (line 5612) | function leverageNative( el, type, expectSync ) {
function manipulationTarget (line 5976) | function manipulationTarget( elem, content ) {
function disableScript (line 5987) | function disableScript( elem ) {
function restoreScript (line 5991) | function restoreScript( elem ) {
function cloneCopyEvent (line 6001) | function cloneCopyEvent( src, dest ) {
function fixInput (line 6034) | function fixInput( src, dest ) {
function domManip (line 6047) | function domManip( collection, args, callback, ignored ) {
function remove (line 6139) | function remove( elem, selector, keepData ) {
function computeStyleTests (line 6453) | function computeStyleTests() {
function roundPixelMeasures (line 6497) | function roundPixelMeasures( measure ) {
function curCSS (line 6571) | function curCSS( elem, name, computed ) {
function addGetHookIf (line 6624) | function addGetHookIf( conditionFn, hookFn ) {
function vendorPropName (line 6649) | function vendorPropName( name ) {
function finalPropName (line 6664) | function finalPropName( name ) {
function setPositiveNumber (line 6690) | function setPositiveNumber( _elem, value, subtract ) {
function boxModelAdjustment (line 6702) | function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, ...
function getWidthOrHeight (line 6770) | function getWidthOrHeight( elem, dimension, extra ) {
function Tween (line 7146) | function Tween( elem, options, prop, end, easing ) {
function schedule (line 7269) | function schedule() {
function createFxNow (line 7282) | function createFxNow() {
function genFx (line 7290) | function genFx( type, includeWidth ) {
function createTween (line 7310) | function createTween( value, prop, animation ) {
function defaultPrefilter (line 7324) | function defaultPrefilter( elem, props, opts ) {
function propFilter (line 7496) | function propFilter( props, specialEasing ) {
function Animation (line 7533) | function Animation( elem, properties, options ) {
function stripAndCollapse (line 8248) | function stripAndCollapse( value ) {
function getClass (line 8254) | function getClass( elem ) {
function classesToArray (line 8258) | function classesToArray( value ) {
function buildParams (line 8885) | function buildParams( prefix, obj, traditional, add ) {
function addToPrefiltersOrTransports (line 9039) | function addToPrefiltersOrTransports( structure ) {
function inspectPrefiltersOrTransports (line 9073) | function inspectPrefiltersOrTransports( structure, options, originalOpti...
function ajaxExtend (line 9102) | function ajaxExtend( target, src ) {
function ajaxHandleResponses (line 9122) | function ajaxHandleResponses( s, jqXHR, responses ) {
function ajaxConvert (line 9180) | function ajaxConvert( s, response, jqXHR, isSuccess ) {
function done (line 9696) | function done( status, nativeStatusText, responses, headers ) {
FILE: docs/_static/jquery.js
function b (line 2) | function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e...
function w (line 2) | function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof...
function p (line 2) | function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e...
function se (line 2) | function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeTy...
function ue (line 2) | function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cac...
function le (line 2) | function le(e){return e[S]=!0,e}
function ce (line 2) | function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(...
function fe (line 2) | function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[...
function pe (line 2) | function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourc...
function de (line 2) | function de(t){return function(e){return"input"===e.nodeName.toLowerCase...
function he (line 2) | function he(n){return function(e){var t=e.nodeName.toLowerCase();return(...
function ge (line 2) | function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e....
function ve (line 2) | function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,...
function ye (line 2) | function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}
function me (line 2) | function me(){}
function xe (line 2) | function xe(e){for(var t=0,n=e.length,r="";t<n;t++)r+=e[t].value;return r}
function be (line 2) | function be(s,e,t){var u=e.dir,l=e.next,c=l||u,f=t&&"parentNode"===c,p=r...
function we (line 2) | function we(i){return 1<i.length?function(e,t,n){var r=i.length;while(r-...
function Te (line 2) | function Te(e,t,n,r,i){for(var o,a=[],s=0,u=e.length,l=null!=t;s<u;s++)(...
function Ce (line 2) | function Ce(d,h,g,v,y,e){return v&&!v[S]&&(v=Ce(v)),y&&!y[S]&&(y=Ce(y,e)...
function Ee (line 2) | function Ee(e){for(var i,t,n,r=e.length,o=b.relative[e[0].type],a=o||b.r...
function A (line 2) | function A(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerC...
function D (line 2) | function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,...
function O (line 2) | function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}
function R (line 2) | function R(e){return e}
function M (line 2) | function M(e){throw e}
function I (line 2) | function I(e,t,n,r){var i;try{e&&m(i=e.promise)?i.call(e).done(t).fail(n...
function l (line 2) | function l(i,o,a,s){return function(){var n=this,r=arguments,e=function(...
function B (line 2) | function B(){E.removeEventListener("DOMContentLoaded",B),C.removeEventLi...
function U (line 2) | function U(e,t){return t.toUpperCase()}
function X (line 2) | function X(e){return e.replace(_,"ms-").replace(z,U)}
function G (line 2) | function G(){this.expando=S.expando+G.uid++}
function Z (line 2) | function Z(e,t,n){var r,i;if(void 0===n&&1===e.nodeType)if(r="data-"+t.r...
function se (line 2) | function se(e,t,n,r){var i,o,a=20,s=r?function(){return r.cur()}:functio...
function le (line 2) | function le(e,t){for(var n,r,i,o,a,s,u,l=[],c=0,f=e.length;c<f;c++)(r=e[...
function ve (line 2) | function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagNa...
function ye (line 2) | function ye(e,t){for(var n=0,r=e.length;n<r;n++)Y.set(e[n],"globalEval",...
function xe (line 2) | function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),...
function Ce (line 2) | function Ce(){return!0}
function Ee (line 2) | function Ee(){return!1}
function Se (line 2) | function Se(e,t){return e===function(){try{return E.activeElement}catch(...
function ke (line 2) | function ke(e,t,n,r,i,o){var a,s;if("object"==typeof t){for(s in"string"...
function Ae (line 2) | function Ae(e,i,o){o?(Y.set(e,i,!1),S.event.add(e,i,{namespace:!1,handle...
function qe (line 2) | function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"...
function Le (line 2) | function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}
function He (line 2) | function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.sli...
function Oe (line 2) | function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=...
function Pe (line 2) | function Pe(n,r,i,o){r=g(r);var e,t,a,s,u,l,c=0,f=n.length,p=f-1,d=r[0],...
function Re (line 2) | function Re(e,t,n){for(var r,i=t?S.filter(t,e):e,o=0;null!=(r=i[o]);o++)...
function Be (line 2) | function Be(e,t,n){var r,i,o,a,s=e.style;return(n=n||Ie(e))&&(""!==(a=n....
function $e (line 2) | function $e(e,t){return{get:function(){if(!e())return(this.get=t).apply(...
function e (line 2) | function e(){if(l){u.style.cssText="position:absolute;left:-11111px;widt...
function t (line 2) | function t(e){return Math.round(parseFloat(e))}
function Xe (line 2) | function Xe(e){var t=S.cssProps[e]||Ue[e];return t||(e in ze?e:Ue[e]=fun...
function Je (line 2) | function Je(e,t,n){var r=te.exec(t);return r?Math.max(0,r[2]-(n||0))+(r[...
function Ke (line 2) | function Ke(e,t,n,r,i,o){var a="width"===t?1:0,s=0,u=0;if(n===(r?"border...
function Ze (line 2) | function Ze(e,t,n){var r=Ie(e),i=(!y.boxSizingReliable()||n)&&"border-bo...
function et (line 2) | function et(e,t,n,r,i){return new et.prototype.init(e,t,n,r,i)}
function st (line 2) | function st(){nt&&(!1===E.hidden&&C.requestAnimationFrame?C.requestAnima...
function ut (line 2) | function ut(){return C.setTimeout(function(){tt=void 0}),tt=Date.now()}
function lt (line 2) | function lt(e,t){var n,r=0,i={height:e};for(t=t?1:0;r<4;r+=2-t)i["margin...
function ct (line 2) | function ct(e,t,n){for(var r,i=(ft.tweeners[t]||[]).concat(ft.tweeners["...
function ft (line 2) | function ft(o,e,t){var n,a,r=0,i=ft.prefilters.length,s=S.Deferred().alw...
function vt (line 2) | function vt(e){return(e.match(P)||[]).join(" ")}
function yt (line 2) | function yt(e){return e.getAttribute&&e.getAttribute("class")||""}
function mt (line 2) | function mt(e){return Array.isArray(e)?e:"string"==typeof e&&e.match(P)|...
function Dt (line 2) | function Dt(n,e,r,i){var t;if(Array.isArray(e))S.each(e,function(e,t){r|...
function Ft (line 2) | function Ft(o){return function(e,t){"string"!=typeof e&&(t=e,e="*");var ...
function Bt (line 2) | function Bt(t,i,o,a){var s={},u=t===Mt;function l(e){var r;return s[e]=!...
function $t (line 2) | function $t(e,t){var n,r,i=S.ajaxSettings.flatOptions||{};for(n in t)voi...
function l (line 2) | function l(e,t,n,r){var i,o,a,s,u,l=t;h||(h=!0,d&&C.clearTimeout(d),c=vo...
FILE: docs/_static/language_data.js
function splitQuery (line 278) | function splitQuery(query) {
FILE: docs/_static/searchtools.js
function splitQuery (line 47) | function splitQuery(query) {
function pulse (line 117) | function pulse() {
function displayNextItem (line 247) | function displayNextItem() {
FILE: docs/_static/underscore-1.3.1.js
function eq (line 669) | function eq(a, b, stack) {
FILE: docs/_static/underscore.js
function q (line 8) | function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)re...
FILE: tutorials/jax/datasets.py
function _download (line 36) | def _download(url, filename):
function mnist_raw (line 46) | def mnist_raw():
function mnist (line 79) | def mnist(permute_train=False):
FILE: tutorials/jax/mnist_tutorial.py
function main (line 19) | def main(_):
FILE: tutorials/tf2/cifar10_tutorial.py
class CNN (line 16) | class CNN(Model):
method __init__ (line 17) | def __init__(self, nb_filters=64):
method call (line 33) | def call(self, x):
function ld_cifar10 (line 39) | def ld_cifar10():
function main (line 68) | def main(_):
FILE: tutorials/tf2/mnist_tutorial.py
class Net (line 15) | class Net(Model):
method __init__ (line 16) | def __init__(self):
method call (line 26) | def call(self, x):
function ld_mnist (line 36) | def ld_mnist():
function main (line 53) | def main(_):
FILE: tutorials/torch/cifar10_tutorial.py
class CNN (line 17) | class CNN(torch.nn.Module):
method __init__ (line 20) | def __init__(self, in_channels=1):
method forward (line 27) | def forward(self, x):
function ld_cifar10 (line 36) | def ld_cifar10():
function main (line 59) | def main(_):
FILE: tutorials/torch/datasets.py
function _download (line 18) | def _download(url, filename):
function mnist_raw (line 28) | def mnist_raw(root=_DATA):
class MNISTDataset (line 61) | class MNISTDataset(torch.utils.data.Dataset):
method __init__ (line 64) | def __init__(self, root=_DATA, train=True, transform=None):
method __getitem__ (line 76) | def __getitem__(self, index):
method __len__ (line 85) | def __len__(self):
FILE: tutorials/torch/mnist_tutorial.py
class CNN (line 19) | class CNN(torch.nn.Module):
method __init__ (line 22) | def __init__(self, in_channels=1):
method forward (line 38) | def forward(self, x):
class PyNet (line 48) | class PyNet(nn.Module):
method __init__ (line 51) | def __init__(self, in_channels=1):
method forward (line 60) | def forward(self, x):
function ld_mnist (line 76) | def ld_mnist():
function main (line 100) | def main(_):
Copy disabled (too large)
Download .json
Condensed preview — 494 files, each showing path, character count, and a content snippet. Download the .json file for the full structured content (10,209K chars).
[
{
"path": ".github/ISSUE_TEMPLATE/bug_report.md",
"chars": 741,
"preview": "---\nname: Bug report\nabout: Report a bug in the CleverHans library\n\n---\n\n***The issue tracker should only be used to rep"
},
{
"path": ".github/ISSUE_TEMPLATE/feature_request.md",
"chars": 805,
"preview": "---\nname: Feature request\nabout: Suggest an idea for the CleverHans library\n\n---\n\n***The issue tracker should only be us"
},
{
"path": ".github/cml_gpu_test.yaml",
"chars": 1319,
"preview": "name: CML Single GPU Test\non: [push]\njobs:\n run:\n runs-on: [self-hosted,cml,gpu]\n steps:\n - uses: actions/ch"
},
{
"path": ".github/workflows/style_type_check.yml",
"chars": 1172,
"preview": "name: Style and type checks\n\non:\n push:\n paths:\n - 'cleverhans/**/*'\n - 'tutorials/**/*'\n\n pull_request:\n"
},
{
"path": ".github/workflows/tests-pytorch.yml",
"chars": 682,
"preview": "name: PyTorch Tests\n\non:\n push:\n paths:\n - 'cleverhans/torch/**/*'\n\n pull_request:\n paths:\n - 'cleverh"
},
{
"path": ".github/workflows/tutorials-jax.yml",
"chars": 893,
"preview": "name: JAX Tutorials\n\non:\n push:\n paths:\n - 'cleverhans/jax/**/*'\n - 'tutorials/jax/**/*'\n\n pull_request:\n"
},
{
"path": ".github/workflows/tutorials-pytorch.yml",
"chars": 911,
"preview": "name: PyTorch Tutorials\n\non:\n push:\n paths:\n - 'cleverhans/torch/**/*'\n - 'tutorials/torch/**/*'\n\n pull_r"
},
{
"path": ".github/workflows/tutorials-tf2.yml",
"chars": 902,
"preview": "name: TensorFlow 2 Tutorials\n\non:\n push:\n paths:\n - 'cleverhans/tf2/**/*'\n - 'tutorials/tf2/**/*'\n\n pull_"
},
{
"path": ".gitignore",
"chars": 1101,
"preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packagi"
},
{
"path": ".pre-commit-config.yaml",
"chars": 91,
"preview": "repos:\n- repo: https://github.com/psf/black\n rev: 20.8b1\n hooks:\n - id: black\n"
},
{
"path": ".pylintrc",
"chars": 4271,
"preview": "# Config file for pylint for CleverHans\n# Used by cleverhans.devtools\n\n[FORMAT]\n# TensorFlow 2 space style\nindent-string"
},
{
"path": ".setup_vm_and_run_tests.sh",
"chars": 2831,
"preview": "#!/bin/sh\nset -e\n# Run update once so apt-get will work at all\nsudo apt-get update\n# Install apt-add-repository\nsudo apt"
},
{
"path": "CODE_OF_CONDUCT.rst",
"chars": 705,
"preview": "CleverHans is dedicated to providing a harassment-free experience for\neveryone, regardless of gender, gender identity an"
},
{
"path": "CONTRIBUTING.md",
"chars": 2768,
"preview": "# Contributing to CleverHans\n\nFirst off, thank you for considering contributing to CleverHans.\nFollowing these guideline"
},
{
"path": "Dockerfile",
"chars": 242,
"preview": "FROM ubuntu:14.04\nRUN apt-get update\nRUN apt-get install -y python\nRUN apt-get install -y python-pip\nRUN pip install --u"
},
{
"path": "LICENSE",
"chars": 1131,
"preview": "MIT License\r\n\r\nCopyright (c) 2019 Google Inc., OpenAI and Pennsylvania State University\r\n\r\nPermission is hereby granted,"
},
{
"path": "README.md",
"chars": 11104,
"preview": "# CleverHans (latest release: v4.0.0)\n\n<img src=\"https://github.com/tensorflow/cleverhans/blob/master/assets/logo.png?ra"
},
{
"path": "cleverhans/__init__.py",
"chars": 260,
"preview": "\"\"\"The CleverHans adversarial example library\"\"\"\nfrom cleverhans.devtools.version import append_dev_version\n\n# If possib"
},
{
"path": "cleverhans/devtools/LICENSE.txt",
"chars": 1639,
"preview": "The devtools module is a derivative work from the devtools module of pylearn2.\nWe reproduce the corresponding license he"
},
{
"path": "cleverhans/devtools/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/devtools/autopep8_all.py",
"chars": 387,
"preview": "\"\"\"\nRun this script to run autopep8 on everything in the library\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom __futu"
},
{
"path": "cleverhans/devtools/checks.py",
"chars": 888,
"preview": "\"\"\"Functionality for building tests.\n\nWe have to call this file \"checks\" and not anything with \"test\" as a\nsubstring or "
},
{
"path": "cleverhans/devtools/list_files.py",
"chars": 2157,
"preview": "\"\"\"Code for listing files that belong to the library.\"\"\"\nimport os\nimport cleverhans\n\n\ndef list_files(suffix=\"\"):\n \"\""
},
{
"path": "cleverhans/devtools/mocks.py",
"chars": 2943,
"preview": "\"\"\"Utility functions for mocking up tests.\n\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import division\n"
},
{
"path": "cleverhans/devtools/tests/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/devtools/tests/test_format.py",
"chars": 4808,
"preview": "\"\"\"\nUnit tests for format checking\n\"\"\"\n\nfrom __future__ import print_function\n\n\nimport os\nimport subprocess\n\nimport clev"
},
{
"path": "cleverhans/devtools/version.py",
"chars": 940,
"preview": "\"\"\"\nUtility functions for keeping track of the version of CleverHans.\n\nThese functions provide a finer level of granular"
},
{
"path": "cleverhans/experimental/README.md",
"chars": 109,
"preview": "This directory contains experimental features of CleverHans, which are not\nintegrated into the main API yet.\n"
},
{
"path": "cleverhans/experimental/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/experimental/certification/README.md",
"chars": 1571,
"preview": "# Certification of adversarial robustness\n\nThis code performs certification of adversarial robustness of given network o"
},
{
"path": "cleverhans/experimental/certification/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/experimental/certification/certify.py",
"chars": 6607,
"preview": "\"\"\"Code for running the certification problem.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import divisio"
},
{
"path": "cleverhans/experimental/certification/dual_formulation.py",
"chars": 24122,
"preview": "\"\"\"Code with dual formulation for certification problem.\"\"\"\n# pylint: disable=missing-docstring\nfrom __future__ import a"
},
{
"path": "cleverhans/experimental/certification/nn.py",
"chars": 11199,
"preview": "\"\"\"This file defines the neural network class, where a network is reinitialized from configuration files.\n\nThe class als"
},
{
"path": "cleverhans/experimental/certification/optimization.py",
"chars": 17512,
"preview": "\"\"\"Code for setting up the optimization problem for certification.\"\"\"\n# pylint: disable=missing-docstring\nfrom __future_"
},
{
"path": "cleverhans/experimental/certification/tests/dual_formulation_test.py",
"chars": 8080,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.dual_formulation.\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __futu"
},
{
"path": "cleverhans/experimental/certification/tests/nn_test.py",
"chars": 2270,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.nn.\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __future__ import ab"
},
{
"path": "cleverhans/experimental/certification/tests/optimization_test.py",
"chars": 8561,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.optimization.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __futur"
},
{
"path": "cleverhans/experimental/certification/tests/utils_test.py",
"chars": 3136,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.utils.\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __future__ import"
},
{
"path": "cleverhans/experimental/certification/utils.py",
"chars": 11418,
"preview": "\"\"\"File containing some simple helper functions.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import divis"
},
{
"path": "cleverhans/generic/README.md",
"chars": 205,
"preview": "# Generic Code (framework independent)\n\nThis folder contains code that is framework independent (for example, it uses \nt"
},
{
"path": "cleverhans/generic/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/jax/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/jax/attacks/__init__.py",
"chars": 89,
"preview": "from cleverhans.jax.attacks.projected_gradient_descent import projected_gradient_descent\n"
},
{
"path": "cleverhans/jax/attacks/fast_gradient_method.py",
"chars": 3050,
"preview": "import jax.numpy as np\nfrom jax import grad, vmap\nfrom jax.nn import log_softmax as logsoftmax\n\nfrom cleverhans.jax.util"
},
{
"path": "cleverhans/jax/attacks/projected_gradient_descent.py",
"chars": 3740,
"preview": "import jax.numpy as np\n\nfrom cleverhans.jax.attacks.fast_gradient_method import fast_gradient_method\nfrom cleverhans.jax"
},
{
"path": "cleverhans/jax/utils.py",
"chars": 1349,
"preview": "import jax.numpy as np\n\n\ndef one_hot(x, k, dtype=np.float32):\n \"\"\"Create a one-hot encoding of x of size k.\"\"\"\n re"
},
{
"path": "cleverhans/plot/__init__.py",
"chars": 35,
"preview": "\"\"\"\nPlotting and visualization\n\"\"\"\n"
},
{
"path": "cleverhans/plot/image.py",
"chars": 4541,
"preview": "\"\"\"\nFunctionality for displaying or saving images.\n\"\"\"\nfrom tempfile import mkstemp\nimport os\nimport platform\n\nimport nu"
},
{
"path": "cleverhans/plot/pyplot_defaults.py",
"chars": 956,
"preview": "\"\"\"Defaults for pyplot\n\nImport this file to set some default parameters for pyplot.\nThese are designed to make the plot "
},
{
"path": "cleverhans/plot/pyplot_image.py",
"chars": 5843,
"preview": "\"\"\"\nFunctionality for showing images in pyplot.\nSee also cleverhans.plot.image for loading/saving image files, showing\ni"
},
{
"path": "cleverhans/plot/save_pdf.py",
"chars": 314,
"preview": "\"\"\"\nThe save_pdf function.\n\"\"\"\nfrom matplotlib.backends.backend_pdf import PdfPages\nfrom matplotlib import pyplot\n\n\ndef "
},
{
"path": "cleverhans/plot/success_fail.py",
"chars": 12713,
"preview": "\"\"\"Functions for plotting succes-failure curves\n\nReference: https://openreview.net/forum?id=H1g0piA9tQ\n\"\"\"\nimport warnin"
},
{
"path": "cleverhans/tf2/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/tf2/attacks/__init__.py",
"chars": 1,
"preview": "\n"
},
{
"path": "cleverhans/tf2/attacks/basic_iterative_method.py",
"chars": 744,
"preview": "\"\"\"\nThe BasicIterativeMethod attack.\n\"\"\"\n\nfrom cleverhans.tf2.attacks.projected_gradient_descent import projected_gradie"
},
{
"path": "cleverhans/tf2/attacks/carlini_wagner_l2.py",
"chars": 12813,
"preview": "\"\"\"The CarliniWagnerL2 attack.\n\"\"\"\nimport numpy as np\nimport tensorflow as tf\nfrom cleverhans.tf2.utils import get_or_gu"
},
{
"path": "cleverhans/tf2/attacks/fast_gradient_method.py",
"chars": 3281,
"preview": "\"\"\"The Fast Gradient Method attack.\"\"\"\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans.tf2.utils import opt"
},
{
"path": "cleverhans/tf2/attacks/madry_et_al.py",
"chars": 700,
"preview": "\"\"\"\nThe MadryEtAl attack\n\"\"\"\n\nfrom cleverhans.tf2.attacks.projected_gradient_descent import projected_gradient_descent\n\n"
},
{
"path": "cleverhans/tf2/attacks/momentum_iterative_method.py",
"chars": 4505,
"preview": "\"\"\"The MomentumIterativeMethod attack.\"\"\"\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans.tf2.utils import "
},
{
"path": "cleverhans/tf2/attacks/projected_gradient_descent.py",
"chars": 5251,
"preview": "\"\"\"The Projected Gradient Descent attack.\"\"\"\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans.tf2.attacks.fa"
},
{
"path": "cleverhans/tf2/attacks/spsa.py",
"chars": 17227,
"preview": "# pylint: disable=missing-docstring\n\nimport tensorflow as tf\n\ntf_dtype = tf.as_dtype(\"float32\")\n\n\ndef spsa(\n model_fn"
},
{
"path": "cleverhans/tf2/utils.py",
"chars": 9703,
"preview": "import numpy as np\nimport tensorflow as tf\n\n\ndef clip_eta(eta, norm, eps):\n \"\"\"\n Helper function to clip the pertu"
},
{
"path": "cleverhans/torch/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/torch/attacks/__init__.py",
"chars": 36,
"preview": "# pylint: disable=missing-docstring\n"
},
{
"path": "cleverhans/torch/attacks/carlini_wagner_l2.py",
"chars": 8461,
"preview": "\"\"\"The CarliniWagnerL2 attack.\"\"\"\nimport torch\n\n\nINF = float(\"inf\")\n\n\ndef carlini_wagner_l2(\n model_fn,\n x,\n n_"
},
{
"path": "cleverhans/torch/attacks/fast_gradient_method.py",
"chars": 4108,
"preview": "\"\"\"The Fast Gradient Method attack.\"\"\"\nimport numpy as np\nimport torch\n\nfrom cleverhans.torch.utils import optimize_line"
},
{
"path": "cleverhans/torch/attacks/hop_skip_jump_attack.py",
"chars": 13878,
"preview": "\"\"\"\nBoundary Attack++\n\"\"\"\nimport numpy as np\nimport torch\n\n\ndef hop_skip_jump_attack(\n model_fn,\n x,\n norm,\n "
},
{
"path": "cleverhans/torch/attacks/noise.py",
"chars": 1332,
"preview": "\"\"\"\nThe Noise Attack\n\"\"\"\n\nimport numpy as np\nimport torch\n\n\ndef noise(x, eps=0.3, order=np.inf, clip_min=None, clip_max="
},
{
"path": "cleverhans/torch/attacks/projected_gradient_descent.py",
"chars": 5716,
"preview": "\"\"\"The Projected Gradient Descent attack.\"\"\"\nimport numpy as np\nimport torch\n\nfrom cleverhans.torch.attacks.fast_gradien"
},
{
"path": "cleverhans/torch/attacks/semantic.py",
"chars": 647,
"preview": "\"\"\"\nSemantic adversarial Examples\n\"\"\"\n\n\ndef semantic(x, center=True, max_val=1.0):\n \"\"\"\n Semantic adversarial exam"
},
{
"path": "cleverhans/torch/attacks/sparse_l1_descent.py",
"chars": 7292,
"preview": "\"\"\"The SparseL1Descent attack.\"\"\"\nimport numpy as np\nimport torch\n\nfrom cleverhans.torch.utils import zero_out_clipped_g"
},
{
"path": "cleverhans/torch/attacks/spsa.py",
"chars": 8556,
"preview": "\"\"\"The SPSA attack.\"\"\"\nimport numpy as np\nimport torch\nfrom torch import optim\nfrom cleverhans.torch.utils import clip_e"
},
{
"path": "cleverhans/torch/tests/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans/torch/tests/test_attacks.py",
"chars": 35214,
"preview": "# pylint: disable=missing-docstring\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future"
},
{
"path": "cleverhans/torch/tests/test_utils.py",
"chars": 4610,
"preview": "# pylint: disable=missing-docstring\nimport numpy as np\nimport torch\n\nimport cleverhans.torch.utils as utils\nfrom cleverh"
},
{
"path": "cleverhans/torch/utils.py",
"chars": 5384,
"preview": "\"\"\"Utils for PyTorch\"\"\"\n\nimport numpy as np\n\nimport torch\n\n\ndef clip_eta(eta, norm, eps):\n \"\"\"\n PyTorch implementa"
},
{
"path": "cleverhans/utils.py",
"chars": 12028,
"preview": "\"\"\"\nGeneric utility functions useful for writing Python code in general\n\"\"\"\nfrom __future__ import absolute_import\nfrom "
},
{
"path": "cleverhans_v3.1.0/CODE_OF_CONDUCT.rst",
"chars": 705,
"preview": "CleverHans is dedicated to providing a harassment-free experience for\neveryone, regardless of gender, gender identity an"
},
{
"path": "cleverhans_v3.1.0/CONTRIBUTING.md",
"chars": 1338,
"preview": "# Contributing to CleverHans\n\nFirst off, thank you for considering contributing to CleverHans.\nFollowing these guideline"
},
{
"path": "cleverhans_v3.1.0/Dockerfile",
"chars": 242,
"preview": "FROM ubuntu:14.04\nRUN apt-get update\nRUN apt-get install -y python\nRUN apt-get install -y python-pip\nRUN pip install --u"
},
{
"path": "cleverhans_v3.1.0/LICENSE",
"chars": 1131,
"preview": "MIT License\r\n\r\nCopyright (c) 2019 Google Inc., OpenAI and Pennsylvania State University\r\n\r\nPermission is hereby granted,"
},
{
"path": "cleverhans_v3.1.0/README.md",
"chars": 14388,
"preview": "# CleverHans (latest release: v3.1.0)\n\nNote: This is the final version of CleverHans v3, which supports TensorFlow 1, Py"
},
{
"path": "cleverhans_v3.1.0/cleverhans/__init__.py",
"chars": 260,
"preview": "\"\"\"The CleverHans adversarial example library\"\"\"\nfrom cleverhans.devtools.version import append_dev_version\n\n# If possib"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attack_bundling.py",
"chars": 52056,
"preview": "\"\"\"\nRuns multiple attacks against each example.\n\nReferences: https://openreview.net/forum?id=H1g0piA9tQ\n http"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/__init__.py",
"chars": 2112,
"preview": "\"\"\"\nThe Attack class, providing a universal abstract interface describing attacks, and many implementations of it.\n\"\"\"\nf"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/attack.py",
"chars": 14739,
"preview": "\"\"\"\nThe Attack interface.\n\"\"\"\n\nfrom abc import ABCMeta\nimport collections\nimport warnings\n\nimport numpy as np\nimport ten"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/basic_iterative_method.py",
"chars": 452,
"preview": "\"\"\"\nThe BasicIterativeMethod attack.\n\"\"\"\n\nfrom cleverhans.attacks.projected_gradient_descent import ProjectedGradientDes"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/carlini_wagner_l2.py",
"chars": 18716,
"preview": "\"\"\"The CarliniWagnerL2 attack\n\"\"\"\n# pylint: disable=missing-docstring\nimport logging\n\nimport numpy as np\nimport tensorfl"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/deep_fool.py",
"chars": 9623,
"preview": "\"\"\"The DeepFool attack\n\n\"\"\"\nimport copy\nimport logging\nimport warnings\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/elastic_net_method.py",
"chars": 24618,
"preview": "\"\"\"The ElasticNetMethod attack.\n\"\"\"\n# pylint: disable=missing-docstring\nimport logging\n\nimport numpy as np\nimport tensor"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/fast_feature_adversaries.py",
"chars": 5724,
"preview": "\"\"\"\nThe FastFeatureAdversaries attack\n\"\"\"\n# pylint: disable=missing-docstring\nimport warnings\n\nimport numpy as np\nimport"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/fast_gradient_method.py",
"chars": 10556,
"preview": "\"\"\"\nThe FastGradientMethod attack.\n\"\"\"\n\nimport warnings\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans.att"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/hop_skip_jump_attack.py",
"chars": 20591,
"preview": "\"\"\" Boundary Attack++\n\"\"\"\nimport logging\nimport numpy as np\nimport tensorflow as tf\nfrom warnings import warn\nfrom cleve"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/lbfgs.py",
"chars": 12213,
"preview": "\"\"\"The LBFGS attack\n\"\"\"\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans.attacks.attack import Attack\nfrom c"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/madry_et_al.py",
"chars": 417,
"preview": "\"\"\"\nThe MadryEtAl attack\n\"\"\"\n\nfrom cleverhans.attacks.projected_gradient_descent import ProjectedGradientDescent\n\n\nclass"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/max_confidence.py",
"chars": 4772,
"preview": "\"\"\"The MaxConfidence attack.\n\"\"\"\nimport warnings\n\nimport tensorflow as tf\n\nfrom cleverhans.attacks.attack import Attack\n"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/momentum_iterative_method.py",
"chars": 6905,
"preview": "\"\"\"The MomentumIterativeMethod attack.\n\"\"\"\n\nimport warnings\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/noise.py",
"chars": 2998,
"preview": "\"\"\"The Noise attack\n\n\"\"\"\nimport warnings\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverhans.attacks.attack imp"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/projected_gradient_descent.py",
"chars": 10418,
"preview": "\"\"\"\nThe ProjectedGradientDescent attack.\n\"\"\"\n\nimport warnings\n\nimport numpy as np\nimport tensorflow as tf\n\nfrom cleverha"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/saliency_map_method.py",
"chars": 10783,
"preview": "\"\"\"The SalienceMapMethod attack\n\"\"\"\n# pylint: disable=missing-docstring\nimport warnings\n\nimport numpy as np\nfrom six.mov"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/semantic.py",
"chars": 1276,
"preview": "\"\"\"Semantic adversarial examples\n\"\"\"\n\nfrom cleverhans.attacks.attack import Attack\n\n\nclass Semantic(Attack):\n \"\"\"\n "
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/sparse_l1_descent.py",
"chars": 14083,
"preview": "\"\"\"\nThe SparseL1Descent attack.\n\"\"\"\n\nimport warnings\nfrom distutils.version import LooseVersion\n\nimport tensorflow as tf"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/spatial_transformation_method.py",
"chars": 4270,
"preview": "\"\"\"The SpatialTransformationMethod attack\n\"\"\"\nimport warnings\n\nfrom cleverhans.attacks.attack import Attack\n\n\nclass Spat"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/spsa.py",
"chars": 30205,
"preview": "\"\"\"The SPSA attack\n\"\"\"\n# pylint: disable=missing-docstring\nimport warnings\n\nimport numpy as np\nfrom six.moves import xra"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks/virtual_adversarial_method.py",
"chars": 5246,
"preview": "\"\"\"The VirtualAdversarialMethod attack\n\n\"\"\"\n\nimport warnings\n\nimport tensorflow as tf\n\nfrom cleverhans.attacks.attack im"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks_tf.py",
"chars": 8442,
"preview": "# pylint: disable=missing-docstring\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future"
},
{
"path": "cleverhans_v3.1.0/cleverhans/attacks_tfe.py",
"chars": 7238,
"preview": "\"\"\"\nAttacks for TensorFlow Eager\n\"\"\"\nfrom distutils.version import LooseVersion\n\nimport numpy as np\nimport tensorflow as"
},
{
"path": "cleverhans_v3.1.0/cleverhans/augmentation.py",
"chars": 2059,
"preview": "\"\"\"\nDataset augmentation functionality\n\nNOTE: This module is much more free to change than many other modules\nin CleverH"
},
{
"path": "cleverhans_v3.1.0/cleverhans/canary.py",
"chars": 2789,
"preview": "\"\"\"\nCanary code that dies if the underlying hardware / drivers aren't working right.\n\"\"\"\nimport time\n\nimport numpy as np"
},
{
"path": "cleverhans_v3.1.0/cleverhans/compat.py",
"chars": 3602,
"preview": "\"\"\"\nWrapper functions for writing code that is compatible with many versions\nof TensorFlow.\n\"\"\"\nimport warnings\nimport t"
},
{
"path": "cleverhans_v3.1.0/cleverhans/confidence_report.py",
"chars": 16477,
"preview": "\"\"\"Functionality for making confidence reports.\n\nA confidence report is a dictionary.\nEach dictionary key is the name of"
},
{
"path": "cleverhans_v3.1.0/cleverhans/dataset.py",
"chars": 10046,
"preview": "\"\"\"Dataset class for CleverHans\n\n\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __future__ import absolute_import\nfrom __"
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/LICENSE.txt",
"chars": 1639,
"preview": "The devtools module is a derivative work from the devtools module of pylearn2.\nWe reproduce the corresponding license he"
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/autopep8_all.py",
"chars": 387,
"preview": "\"\"\"\nRun this script to run autopep8 on everything in the library\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom __futu"
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/checks.py",
"chars": 888,
"preview": "\"\"\"Functionality for building tests.\n\nWe have to call this file \"checks\" and not anything with \"test\" as a\nsubstring or "
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/list_files.py",
"chars": 2157,
"preview": "\"\"\"Code for listing files that belong to the library.\"\"\"\nimport os\nimport cleverhans\n\n\ndef list_files(suffix=\"\"):\n \"\""
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/mocks.py",
"chars": 2943,
"preview": "\"\"\"Utility functions for mocking up tests.\n\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import division\n"
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/tests/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/tests/test_format.py",
"chars": 4808,
"preview": "\"\"\"\nUnit tests for format checking\n\"\"\"\n\nfrom __future__ import print_function\n\n\nimport os\nimport subprocess\n\nimport clev"
},
{
"path": "cleverhans_v3.1.0/cleverhans/devtools/version.py",
"chars": 940,
"preview": "\"\"\"\nUtility functions for keeping track of the version of CleverHans.\n\nThese functions provide a finer level of granular"
},
{
"path": "cleverhans_v3.1.0/cleverhans/evaluation.py",
"chars": 30202,
"preview": "\"\"\"\nFunctionality for evaluating expressions across entire datasets.\nIncludes multi-GPU support for fast evaluation.\n\"\"\""
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/README.md",
"chars": 109,
"preview": "This directory contains experimental features of cleverhans, which are not\nintegrated into the main API yet.\n"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/README.md",
"chars": 1571,
"preview": "# Certification of adversarial robustness\n\nThis code performs certification of adversarial robustness of given network o"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/certify.py",
"chars": 6607,
"preview": "\"\"\"Code for running the certification problem.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import divisio"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/dual_formulation.py",
"chars": 24122,
"preview": "\"\"\"Code with dual formulation for certification problem.\"\"\"\n# pylint: disable=missing-docstring\nfrom __future__ import a"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/nn.py",
"chars": 11199,
"preview": "\"\"\"This file defines the neural network class, where a network is reinitialized from configuration files.\n\nThe class als"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/optimization.py",
"chars": 17512,
"preview": "\"\"\"Code for setting up the optimization problem for certification.\"\"\"\n# pylint: disable=missing-docstring\nfrom __future_"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/tests/dual_formulation_test.py",
"chars": 8080,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.dual_formulation.\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __futu"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/tests/nn_test.py",
"chars": 2270,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.nn.\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __future__ import ab"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/tests/optimization_test.py",
"chars": 8561,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.optimization.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __futur"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/tests/utils_test.py",
"chars": 3136,
"preview": "\"\"\"Tests for cleverhans.experimental.certification.utils.\"\"\"\n# pylint: disable=missing-docstring\n\nfrom __future__ import"
},
{
"path": "cleverhans_v3.1.0/cleverhans/experimental/certification/utils.py",
"chars": 11418,
"preview": "\"\"\"File containing some simple helper functions.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import divis"
},
{
"path": "cleverhans_v3.1.0/cleverhans/initializers.py",
"chars": 636,
"preview": "\"\"\"\nInitializers.\n\"\"\"\n\nimport tensorflow as tf\n\n\nclass HeReLuNormalInitializer(tf.initializers.random_normal):\n \"\"\"\n "
},
{
"path": "cleverhans_v3.1.0/cleverhans/loss.py",
"chars": 20535,
"preview": "\"\"\"Loss functions for training models.\"\"\"\nimport copy\nimport json\nimport os\nimport warnings\n\nimport numpy as np\nimport t"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model.py",
"chars": 11595,
"preview": "\"\"\"\nThe Model class and related functionality.\n\"\"\"\nfrom abc import ABCMeta\nimport warnings\n\nimport tensorflow as tf\n\nfro"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/__init__.py",
"chars": 528,
"preview": "\"\"\"\nA module for hosting a variety of models of interest to the adversarial\nexample community.\n\nWarning:\n This module i"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/all_convolutional.py",
"chars": 1783,
"preview": "\"\"\"Extremely simple model where all parameters are from convolutions.\n\"\"\"\n\nimport math\nimport tensorflow as tf\n\nfrom cle"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/basic_cnn.py",
"chars": 1683,
"preview": "\"\"\"\nA pure TensorFlow implementation of a convolutional neural network.\n\"\"\"\n# pylint: disable=missing-docstring\nfrom __f"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/deep_k_nearest_neighbors/README.md",
"chars": 2022,
"preview": "# Deep k-Nearest Neighbors\n\nCode in `dknn.py` shows how to reproduce one of the results from the\nfollowing paper, using "
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/deep_k_nearest_neighbors/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/deep_k_nearest_neighbors/dknn.py",
"chars": 22873,
"preview": "\"\"\"\nThis code reproduces the MNIST results from the paper\nDeep k-Nearest Neighbors: Towards Confident, Interpretable and"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/madry_lab_challenges/__init__.py",
"chars": 66,
"preview": "\"\"\"\nModels from\nhttps://github.com/MadryLab/cifar10_challenge\n\"\"\"\n"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/madry_lab_challenges/cifar10_model.py",
"chars": 11476,
"preview": "\"\"\"cleverhans.model.Model implementation of cifar10_challenge.model.Model\n\nThis re-implementation factors variable creat"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/madry_lab_challenges/make_cifar10_joblib.py",
"chars": 2017,
"preview": "\"\"\"Makes a .joblib file containing the trained model\n\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import"
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/soft_nearest_neighbor_loss/SNNL_regularized_model.py",
"chars": 1930,
"preview": "\"\"\"\nA Simple Neural Net to optimize with SNNL and Cross Entropy\n\"\"\"\n# pylint: disable=missing-docstring\nfrom __future__ "
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/soft_nearest_neighbor_loss/SNNL_regularized_train.py",
"chars": 6606,
"preview": "\"\"\"\nThis model shows how to train a model with Soft Nearest Neighbor Loss\nregularization. The paper which presents this "
},
{
"path": "cleverhans_v3.1.0/cleverhans/model_zoo/soft_nearest_neighbor_loss/__init__.py",
"chars": 258,
"preview": "\"\"\"\nA model to demonstrate the use of soft nearest neighbor loss presented in\nFrosst, Nicholas, Nicolas Papernot, and Ge"
},
{
"path": "cleverhans_v3.1.0/cleverhans/picklable_model.py",
"chars": 28970,
"preview": "\"\"\"Models that support pickling.\n\nNOTE: This module is much more free to change than many other modules\nin CleverHans. C"
},
{
"path": "cleverhans_v3.1.0/cleverhans/plot/__init__.py",
"chars": 35,
"preview": "\"\"\"\nPlotting and visualization\n\"\"\"\n"
},
{
"path": "cleverhans_v3.1.0/cleverhans/plot/image.py",
"chars": 4541,
"preview": "\"\"\"\nFunctionality for displaying or saving images.\n\"\"\"\nfrom tempfile import mkstemp\nimport os\nimport platform\n\nimport nu"
},
{
"path": "cleverhans_v3.1.0/cleverhans/plot/pyplot_defaults.py",
"chars": 956,
"preview": "\"\"\"Defaults for pyplot\n\nImport this file to set some default parameters for pyplot.\nThese are designed to make the plot "
},
{
"path": "cleverhans_v3.1.0/cleverhans/plot/pyplot_image.py",
"chars": 5843,
"preview": "\"\"\"\nFunctionality for showing images in pyplot.\nSee also cleverhans.plot.image for loading/saving image files, showing\ni"
},
{
"path": "cleverhans_v3.1.0/cleverhans/plot/save_pdf.py",
"chars": 314,
"preview": "\"\"\"\nThe save_pdf function.\n\"\"\"\nfrom matplotlib.backends.backend_pdf import PdfPages\nfrom matplotlib import pyplot\n\n\ndef "
},
{
"path": "cleverhans_v3.1.0/cleverhans/plot/success_fail.py",
"chars": 12713,
"preview": "\"\"\"Functions for plotting succes-failure curves\n\nReference: https://openreview.net/forum?id=H1g0piA9tQ\n\"\"\"\nimport warnin"
},
{
"path": "cleverhans_v3.1.0/cleverhans/serial.py",
"chars": 8004,
"preview": "\"\"\"Serialization functionality.\n\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __futu"
},
{
"path": "cleverhans_v3.1.0/cleverhans/train.py",
"chars": 13412,
"preview": "\"\"\"\nMulti-replica synchronous training\n\n\nNOTE: This module is much more free to change than many other modules\nin Clever"
},
{
"path": "cleverhans_v3.1.0/cleverhans/utils.py",
"chars": 12028,
"preview": "\"\"\"\nGeneric utility functions useful for writing Python code in general\n\"\"\"\nfrom __future__ import absolute_import\nfrom "
},
{
"path": "cleverhans_v3.1.0/cleverhans/utils_keras.py",
"chars": 9346,
"preview": "\"\"\"\nModel construction utilities based on keras\n\"\"\"\nfrom distutils.version import LooseVersion\nimport warnings\nimport te"
},
{
"path": "cleverhans_v3.1.0/cleverhans/utils_mnist.py",
"chars": 1304,
"preview": "# pylint: disable=missing-docstring\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future"
},
{
"path": "cleverhans_v3.1.0/cleverhans/utils_pytorch.py",
"chars": 3105,
"preview": "\"\"\"Basic utilities for pytorch code\"\"\"\n\nimport warnings\nfrom random import getrandbits\n\nimport numpy as np\nimport tensor"
},
{
"path": "cleverhans_v3.1.0/cleverhans/utils_tf.py",
"chars": 32235,
"preview": "\"\"\"Utility functions for writing TensorFlow code\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import divisi"
},
{
"path": "cleverhans_v3.1.0/cleverhans/utils_tfe.py",
"chars": 8321,
"preview": "\"\"\"\nUtility functions for writing tf eager code\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import divisi"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/__init__.py",
"chars": 1146,
"preview": "\"\"\"\nThe CleverHans tutorials.\nWhile mostly designed to be run as standalone scripts, the tutorials together also form an"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/cifar10_tutorial_tf.py",
"chars": 8743,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples using FGSM\nand train a model using adversarial training wit"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/evaluate_pickled_model.py",
"chars": 3333,
"preview": "\"\"\"\nThis script evaluates trained models that have been saved to the filesystem.\nSee mnist_tutorial_picklable.py for ins"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_blackbox.py",
"chars": 12639,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples\nusing FGSM in black-box setting.\nThe original paper can be "
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_cw.py",
"chars": 9790,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples\nusing C&W attack in white-box setting.\nThe original paper c"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_jsma.py",
"chars": 9509,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples\nusing JSMA in white-box setting.\nThe original paper can be "
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_keras.py",
"chars": 7715,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples using FGSM\nand train a model using adversarial training wit"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_keras_tf.py",
"chars": 8647,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples using FGSM\nand train a model using adversarial training wit"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_picklable.py",
"chars": 10006,
"preview": "\"\"\"\nThis tutorial shows how to use cleverhans.picklable_model\nto create models that can be saved for evaluation later.\n\""
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_pytorch.py",
"chars": 6501,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples using FGSM\nand train a model using adversarial training wit"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_tf.py",
"chars": 8278,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples using FGSM\nand train a model using adversarial training wit"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/mnist_tutorial_tfe.py",
"chars": 9882,
"preview": "\"\"\"\nThis tutorial shows how to generate adversarial examples using FGSM\nand train a model using adversarial training wit"
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/tutorial_models.py",
"chars": 903,
"preview": "\"\"\"\nA pure TensorFlow implementation of a neural network. This can be\nused as a drop-in replacement for a Keras model.\n\""
},
{
"path": "cleverhans_v3.1.0/cleverhans_tutorials/tutorial_models_tfe.py",
"chars": 3909,
"preview": "\"\"\"\nA TensorFlow Eager implementation of a neural network.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ im"
},
{
"path": "cleverhans_v3.1.0/docs/.nojekyll",
"chars": 0,
"preview": ""
},
{
"path": "cleverhans_v3.1.0/docs/README.html",
"chars": 5382,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/abc.html",
"chars": 29119,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/attack.html",
"chars": 48482,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/basic_iterative_method.html",
"chars": 4727,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/carlini_wagner_l2.html",
"chars": 66572,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/deep_fool.html",
"chars": 35341,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/elastic_net_method.html",
"chars": 93448,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/fast_feature_adversaries.html",
"chars": 23243,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/fast_gradient_method.html",
"chars": 35807,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/hop_skip_jump_attack.html",
"chars": 81763,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/lbfgs.html",
"chars": 47511,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/madry_et_al.html",
"chars": 4615,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/max_confidence.html",
"chars": 22284,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/momentum_iterative_method.html",
"chars": 26979,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/noise.html",
"chars": 13281,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/projected_gradient_descent.html",
"chars": 38315,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/saliency_map_method.html",
"chars": 44165,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/semantic.html",
"chars": 7136,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
},
{
"path": "cleverhans_v3.1.0/docs/_modules/cleverhans/attacks/sparse_l1_descent.html",
"chars": 52887,
"preview": "\n<!DOCTYPE html>\n\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, in"
}
]
// ... and 294 more files (download for full content)
About this extraction
This page contains the full source code of the cleverhans-lab/cleverhans GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 494 files (9.3 MB), approximately 2.5M tokens, and a symbol index with 2257 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.