> For the complete documentation index, see [llms.txt](https://infinitode-docs.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitode-docs.gitbook.io/documentation/package-documentation/deepdefend-package-documentation.md).

# DeepDefend Package Documentation

Package documentation for DeepDefend, our Python package.

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://infinitode-docs.gitbook.io/documentation/package-documentation/deepdefend-package-documentation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
