Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianguo99 committed Dec 6, 2023
1 parent e0edf60 commit eff90be
Show file tree
Hide file tree
Showing 78 changed files with 21 additions and 10,592 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
__pycache__/
*.pdf
*.npz
advertorch/__pycache__/
advertorch.egg-info
deepcp/__pycache__/
deepcp.egg-info
data/
.pytest_cache/
.cache/
Expand Down
18 changes: 3 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to AdverTorch
# Contributing to deepcp

Thank you considering contributing to AdverTorch!
Thank you considering contributing to deepcp!

This document provide brief guidelines for potential contributors.

Expand All @@ -10,19 +10,7 @@ We ask that you follow the `PEP8` coding style in your pull requests, [`flake8`]

---
### Detailed guidelines for contributing new attacks
- *(mandatory)* The implementation file should be added to the folder `advertorch/attacks`, and the class should be imported in `advertorch/attacks/__init__.py`.
- *(mandatory)* The attack should be included in different unit tests, this can be done by adding the attack class to different lists in `advertorch/test_utils.py`
+ add to `general_input_attacks` if it can perturb input tensor of any shape (not limited to images),
+ add to `image_only_attacks` if it only works on images,
+ add to `label_attacks` if the attack manipulates labels,
+ add to `feature_attacks` if the attack manipulates features,
+ add to `batch_consistent_attacks` if the attack's behavior should be the same when it is applied to a single example or a batch,
+ add to `targeted_only_attacks` if the attack is a label attack and does not work for the untargeted case,
+ add entry to `attack_kwargs` in `advertorch/tests/test_attacks_running.py`, for setting the hyperparameters used for test.
- *(mandatory)* Benchmark the attack with at least one performance measure, by adding a script to `advertorch_examples/attack_benchmarks`.
- *(mandatory)* If the contributor has a GPU computer, run `pytest` locally to make sure all the tests pass. (This is because travis-ci currently do not provide GPU machines for continuous integration.) If the contributor does not have a GPU computer, please let us know in the pull request.
- *(optional)* When an attack can be compared against other implementations, a comparison test could be added to `advertorch/external_tests`.
- *(optional)* Add an ipython notebook example.


---
### Copyright notice at the beginning of files
Expand Down
5 changes: 2 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
include tests/*.py
include external_tests/*.py
include advertorch/VERSION
include deepcp/VERSION
include pytest.ini
include LICENSE
include LICENSE.GPL
include advertorch_examples/trained_models/*.pt
include advertorch_examples/*.ipynb
include deepcp_examples/*.ipynb
81 changes: 7 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<!-- <a href="https://github.com/borealisai/advertorch" target="_blank"><img src="https://raw.githubusercontent.com/borealisai/advertorch/master/assets/logo.png?raw=true" alt="advertorch logo" width="200"></a>
[![Build Status](https://travis-ci.org/BorealisAI/advertorch.svg?branch=master)](https://travis-ci.org/BorealisAI/advertorch)
<a href="https://github.com/borealisai/advertorch" target="_blank"><img src="https://raw.githubusercontent.com/borealisai/advertorch/master/assets/advertorch.png?raw=true" alt="advertorch text" width="100"></a> -->

DeepCP is a Python toolbox for conformal prediction research. The primary functionalities are implemented in PyTorch. Specifically, DeepCP contains modules of post-hoc methods and training methods for classification problems and regression problems.


#### Latest version (v0.1)
DeepCP is a Python toolbox for conformal prediction research on deep learning models. The primary functionalities are implemented in PyTorch. Specifically, DeepCP contains modules of post-hoc methods and training methods for classification problems and regression problems.

## Installation

### Installing AdverTorch itself
### Installing DeepCP itself

We developed DeepCP under Python 3.8 and PyTorch 1.0.0 & 0.4.1. To install DeepCP, simply run
We developed DeepCP under Python 3.9 and PyTorch 2.0.1. To install DeepCP, simply run

```
pip install deeptorch
pip install deepcp
```

or clone the repo and run
Expand All @@ -30,39 +20,9 @@ To install the package in "editable" mode:
pip install -e .
```

### Setting up the testing environments

Some attacks are tested against implementations in [Foolbox](https://github.com/bethgelab/foolbox) or [CleverHans](https://github.com/tensorflow/cleverhans) to ensure correctness. Currently, they are tested under the following versions of related libraries.
```
conda install -c anaconda tensorflow-gpu==1.11.0
pip install git+https://github.com/tensorflow/cleverhans.git@336b9f4ed95dccc7f0d12d338c2038c53786ab70
pip install Keras==2.2.2
pip install foolbox==1.3.2
```


## Examples
```python
# prepare your pytorch model as "model"
# prepare a batch of data and label as "cln_data" and "true_label"
# ...

from advertorch.attacks import LinfPGDAttack

adversary = LinfPGDAttack(
model, loss_fn=nn.CrossEntropyLoss(reduction="sum"), eps=0.3,
nb_iter=40, eps_iter=0.01, rand_init=True, clip_min=0.0, clip_max=1.0,
targeted=False)

adv_untargeted = adversary.perturb(cln_data, true_label)

target = torch.ones_like(true_label) * 3
adversary.targeted = True
adv_targeted = adversary.perturb(cln_data, target)
```

```python

logits_cal = ...
Y_cal = ...

Expand All @@ -77,48 +37,21 @@ Y_Sets = predictor.predict(logits_test)

# evaluate the prediction sets
metrics = utils.coverage_rate(Y_sets,Y_test)

```

For runnable examples see [`advertorch_examples/tutorial_attack_defense_bpda_mnist.ipynb`](https://github.com/BorealisAI/advertorch/blob/master/advertorch_examples/tutorial_attack_defense_bpda_mnist.ipynb) for how to attack and defend; see [`advertorch_examples/tutorial_train_mnist.py`](https://github.com/BorealisAI/advertorch/blob/master/advertorch_examples/tutorial_train_mnist.py) for how to adversarially train a robust model on MNIST.

## Documentation

The documentation webpage is on readthedocs https://advertorch.readthedocs.io.


## Coming Soon

AdverTorch is still under active development. We will add the following features/items down the road:
DeepCP is still under active development. We will add the following features/items down the road:

* more examples
* support for other machine learning frameworks, e.g. TensorFlow
* more attacks, defenses and other related functionalities
* support for other Python versions and future PyTorch versions
* contributing guidelines
* more CP algorithms
* loss functions for CP
* ...


## Known issues

`FastFeatureAttack` and `JacobianSaliencyMapAttack` do not pass the tests against the version of CleverHans used. (They use to pass tests on a previous version of CleverHans.) This issue is being investigated. In the file `test_attacks_on_cleverhans.py`, they are marked as "skipped" in `pytest` tests.

## License

This project is licensed under the LGPL. The terms and conditions can be found in the LICENSE and LICENSE.GPL files.

## Citation

If you use AdverTorch in your research, we kindly ask that you cite the following [technical report](https://arxiv.org/abs/1902.07623):

```
@article{ding2019advertorch,
title={{AdverTorch} v0.1: An Adversarial Robustness Toolbox based on PyTorch},
author={Ding, Gavin Weiguang and Wang, Luyu and Jin, Xiaomeng},
journal={arXiv preprint arXiv:1902.07623},
year={2019}
}
```


## Contributors
Expand Down
Binary file removed assets/advertorch.png
Binary file not shown.
Binary file removed assets/logo.png
Binary file not shown.
1 change: 0 additions & 1 deletion deepcp/VERSION

This file was deleted.

15 changes: 0 additions & 15 deletions deepcp/__init__.py

This file was deleted.

66 changes: 0 additions & 66 deletions deepcp/attacks/__init__.py

This file was deleted.

73 changes: 0 additions & 73 deletions deepcp/attacks/base.py

This file was deleted.

23 changes: 0 additions & 23 deletions deepcp/attacks/blackbox/__init__.py

This file was deleted.

Loading

0 comments on commit eff90be

Please sign in to comment.