SkillAgentSearch skills...

DeepRobust

A pytorch adversarial library for attack and defense methods on images and graphs

Install / Use

/learn @DSE-MSU/DeepRobust

README

<p align="center"> <img center src="https://github.com/DSE-MSU/DeepRobust/blob/master/adversary_examples/Deeprobust.png" width = "450" alt="logo"> </p>
<!-- <a href="https://github.com/DSE-MSU/DeepRobust/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/DSE-MSU/DeepRobust"></a> <a href="https://github.com/DSE-MSU/DeepRobust/network/members" ><img alt="GitHub forks" src="https://img.shields.io/github/forks/DSE-MSU/DeepRobust"> </a> -->

<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/DSE-MSU/DeepRobust"> <a href="https://github.com/DSE-MSU/DeepRobust/issues"> <img alt="GitHub issues" src="https://img.shields.io/github/issues/DSE-MSU/DeepRobust"></a> <img alt="GitHub" src="https://img.shields.io/github/license/DSE-MSU/DeepRobust"> Contributing Tweet

<!-- <img alt="GitHub top language" src="https://img.shields.io/github/languages/top/DSE-MSU/DeepRobust"> --> <!-- <div align=center><img src="https://github.com/DSE-MSU/DeepRobust/blob/master/adversarial.png" width="500"/></div> <div align=center><img src="https://github.com/DSE-MSU/DeepRobust/blob/master/adversary_examples/graph_attack_example.png" width="00" /></div> -->

Documentation | Paper | Samples

[AAAI 2021] DeepRobust is a PyTorch adversarial library for attack and defense methods on images and graphs.

  • If you are new to DeepRobust, we highly suggest you read the documentation page or the following content in this README to learn how to use it.
  • If you have any questions or suggestions regarding this library, feel free to create an issue here. We will reply as soon as possible :)
<p float="left"> <img src="https://github.com/DSE-MSU/DeepRobust/blob/master/adversary_examples/adversarial.png" width="430" /> <img src="https://github.com/DSE-MSU/DeepRobust/blob/master/adversary_examples/graph_attack_example.png" width="380" /> </p>

List of including algorithms can be found in [Image Package] and [Graph Package].

Environment & Installation

Usage

Acknowledgement

For more details about attacks and defenses, you can read the following papers.

If our work could help your research, please cite: DeepRobust: A PyTorch Library for Adversarial Attacks and Defenses

@article{li2020deeprobust,
  title={Deeprobust: A pytorch library for adversarial attacks and defenses},
  author={Li, Yaxin and Jin, Wei and Xu, Han and Tang, Jiliang},
  journal={arXiv preprint arXiv:2005.06149},
  year={2020}
}

Changelog

  • [11/2023] Try <span style="color:red"> git clone https://github.com/DSE-MSU/DeepRobust.git; cd DeepRobust; python setup_empty.py install </span> to directly install DeepRobust without installing dependency packages.
  • [11/2023] DeepRobust 0.2.9 Released. Please try pip install deeprobust==0.2.9. We have fixed the OOM issue of metattack on new pytorch versions.
  • [06/2023] We have added a backdoor attack UGBA, WWW'23 to graph package. We can now use UGBA to conduct unnoticeable backdoor attack on large-scale graphs such as ogb-arxiv (see example in test_ugba.py)!
  • [02/2023] DeepRobust 0.2.8 Released. Please try pip install deeprobust==0.2.8! We have added a scalable attack PRBCD, NeurIPS'21 to graph package. We can now use PRBCD to attack large-scale graphs such as ogb-arxiv (see example in test_prbcd.py)!
  • [02/2023] Add a robust model AirGNN, NeurIPS'21 to graph package. Try python examples/graph/test_airgnn.py! See details in test_airgnn.py
  • [11/2022] DeepRobust 0.2.6 Released. Please try pip install deeprobust==0.2.6! We have more updates coming. Please stay tuned!
  • [11/2021] A subpackage that includes popular black box attacks in image domain is released. Find it here. Link
  • [11/2021] DeepRobust 0.2.4 Released. Please try pip install deeprobust==0.2.4!
  • [10/2021] add scalable attack and MedianGCN. Thank Jintang for his contribution!
  • [06/2021] [Image Package] Add preprocessing method: APE-GAN.
  • [05/2021] DeepRobust is published at AAAI 2021. Check here!
  • [05/2021] DeepRobust 0.2.2 Released. Please try pip install deeprobust==0.2.2!
  • [04/2021] [Image Package] Add support for ImageNet. See details in test_ImageNet.py
  • [04/2021] [Graph Package] Add support for OGB datasets. See more details in the tutorial page.
  • [03/2021] [Graph Package] Added node embedding attack and victim models! See this tutorial page.
  • [02/2021] [Graph Package] DeepRobust now provides tools for converting the datasets between Pytorch Geometric and DeepRobust. See more details in the tutorial page! DeepRobust now also support GAT, Chebnet and SGC based on pyg; see details in test_gat.py, test_chebnet.py and test_sgc.py
  • [12/2020] DeepRobust now can be installed via pip! Try pip install deeprobust!
  • [12/2020] [Graph Package] Add four more datasets and one defense algorithm. More details can be found here. More datasets and algorithms will be added later. Stay tuned :)
  • [07/2020] Add documentation page!
  • [06/2020] Add docstring to both image and graph package

Basic Environment

  • python >= 3.6 (python 3.5 should also work)
  • pytorch >= 1.2.0

see setup.py or requirements.txt for more information.

Installation

Install from pip

pip install deeprobust 

Install from source

git clone https://github.com/DSE-MSU/DeepRobust.git
cd DeepRobust
python setup.py install

If you find the dependencies are hard to install, please try the following: python setup_empty.py install (only install deeprobust without installing other packages)

Test Examples

python examples/image/test_PGD.py
python examples/image/test_pgdtraining.py
python examples/graph/test_gcn_jaccard.py --dataset cora
python examples/graph/test_mettack.py --dataset cora --ptb_rate 0.05

Usage

Image Attack and Defense

  1. Train model

    Example: Train a simple CNN model on MNIST dataset for 20 epoch on gpu.

    import deeprobust.image.netmodels.train_model as trainmodel
    trainmodel.train('CNN', 'MNIST', 'cuda', 20)
    

    Model would be saved in deeprobust/trained_models/.

  2. Instantiated attack methods and defense methods.

    Example: Generate adversary example with PGD attack.

    from deeprobust.image.attack.pgd import PGD
    from deeprobust.image.config import attack_params
    from deeprobust.image.utils import download_model
    import torch
    import deeprobust.image.netmodels.resnet as resnet
    from torchvision import transforms,datasets
    
    URL = "https://github.com/I-am-Bot/deeprobust_model/raw/master/CIFAR10_ResNet18_epoch_20.pt"
    download_model(URL, "$MODEL_PATH$")
    
    model = resnet.ResNet18().to('cuda')
    model.load_state_dict(torch.load("$MODEL_PATH$"))
    model.eval()
    
    transform_val = transforms.Compose([transforms.ToTensor()])
    test_loader  = torch.utils.data.DataLoader(
                    datasets.CIFAR10('deeprobust/image/data', train = False, download=True,
                    transform = transform_val),
                    batch_size = 10, shuffle=True)
    
    x, y = next(iter(test_loader))
    x = x.to('cuda').float()
    
    adversary = PGD(model, 'cuda')
    Adv_img = adversary.generate(x, y, **attack_params['PGD_CIFAR10'])
    

    Example: Train defense model.

Related Skills

View on GitHub
GitHub Stars1.1k
CategoryEducation
Updated1d ago
Forks192

Languages

Python

Security Score

100/100

Audited on Mar 30, 2026

No findings