DeepDefend Package Documentation

Package documentation for DeepDefend, our Python package.

Changelog

  • 0.1.3 (Latest): Updated DeepDefend with 5 new functions under defenses, including: Randomized Smoothing, Feature Denoising, Thermometer Encoding, Adversarial Logit Pairing (ALP), and Spatial Smoothing.

Updates to DeepDefend's attack module will be less frequent due to the potential misuse of adversarial attacks on AI models.

  • 0.1.2: Updated PYPI project description.

  • 0.1.1: 6 new functions.

  • 0.1.0: Initial release.

Installation

You can install DeepDefend using PyPi, please make sure that you are using Python 3.6 or later before installing DeepDefend:

pip install deepdefend

Example Usage

Adversarial Attacks

import tensorflow as tf
from deepdefend.attacks import fgsm, pgd, bim, cw, deepfool, jsma

# Load a pre-trained TensorFlow model
model = ...

# Load example input and label data (replace this with your own data loading code)
x_example = ...  # example input data
y_example = ...  # true label

# Perform FGSM attack on the example data
adversarial_example_fgsm = fgsm(model, x_example, y_example, epsilon=0.01)

# Perform PGD attack on the example data
adversarial_example_pgd = pgd(model, x_example, y_example, epsilon=0.01, alpha=0.01, num_steps=10)

# Perform BIM attack on the example data
adversarial_example_bim = bim(model, x_example, y_example, epsilon=0.01, alpha=0.01, num_steps=10)

# Perform CW attack on the example data
adversarial_example_cw = cw(model, x_example, y_example, epsilon=0.01, c=1, kappa=0, num_steps=10, alpha=0.01)

# Perform Deepfool attack on the example data
adversarial_example_deepfool = deepfool(model, x_example, y_example, num_steps=10)

# Perform JSMA attack on the example data
adversarial_example_jsma = jsma(model, x_example, y_example, theta=0.1, gamma=0.1, num_steps=10)

Last updated

Was this helpful?