# DeepDefend Package Documentation

## Changelog

* **0.1.5 (Latest)**:&#x20;
  * Added MIM (Momentum Iterative Method) and EAD (Elastic Net Attack) attacks.
  * Added Word Swap and Character Swap attacks for text-based models.
  * Added Pixel Deflection, Gaussian Blur, Total Variation Minimization, and Median Smoothing defenses.
  * Added Word Masking defense for text-based models.
  * Added a comprehensive support table for different model types.
  * Fixed logical errors in several defense functions.
  * Improved Keras compatibility for training-time defenses.
* **0.1.4**: Added SPSA (Simultaneous Perturbation Stochastic Approximation) attack and JPEG Compression defense. We also fixed flawed logic in some of our defense functions.
* **0.1.3**: Updated DeepDefend with 5 new functions under `defenses`, including: Randomized Smoothing, Feature Denoising, Thermometer Encoding, Adversarial Logit Pairing (ALP), and Spatial Smoothing.

{% hint style="info" %}
Updates to DeepDefend's attack module will be less frequent due to the potential misuse of adversarial attacks on AI models.
{% endhint %}

* **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:

```bash
pip install deepdefend
```

{% hint style="warning" %}
**DeepDefend** is an experimental package, please be sure to report any issues, bugs, or errors you come across when using it.
{% endhint %}

***

## Example Usage

### Adversarial Attacks

```python
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)
```
