Skip to main content

SecML-Torch Library

Project description

SecML-Torch: A Library for Robustness Evaluation of Deep Learning Models

pypi py_versions coverage docs

SecML-Torch (SecMLT) is an open-source Python library designed to facilitate research in the area of Adversarial Machine Learning (AML) and robustness evaluation. The library provides a simple yet powerful interface for generating various types of adversarial examples, as well as tools for evaluating the robustness of machine learning models against such attacks.

Installation

You can install SecMLT via pip:

pip install secml-torch

This will install the core version of SecMLT, including only the main functionalities such as native implementation of attacks and PyTorch wrappers.

Install with extras

The library can be installed together with other plugins that enable further functionalities.

  • Foolbox, a Python toolbox to create adversarial examples.
  • Tensorboard, a visualization toolkit for machine learning experimentation.

Install one or more extras with the command:

pip install secml-torch[foolbox,tensorboard]

To enable the adv_lib extra, you have to manually install the library from the original repository:

pip install git+https://github.com/jeromerony/adversarial-library

Key Features

  • Built for Deep Learning: SecMLT is compatible with the popular machine learning framework PyTorch.
  • Various types of adversarial attacks: SecMLT includes support for a wide range of attack methods (evasion, poisoning, ...) such as different implementations imported from popular AML libraries (Foolbox, Adversarial Library).
  • Customizable attacks: SecMLT offers several levels of analysis for the models, including modular implementations of existing attacks to extend with different loss functions, optimizers, and more.
  • Attack debugging: Built-in debugging of evaluations by logging events and metrics along the attack runs (even on Tensorboard).

Usage

Here's a brief example of using SecMLT to evaluate the robustness of a trained classifier:

from secmlt.adv.evasion.pgd import PGD
from secmlt.metrics.classification import Accuracy
from secmlt.models.pytorch.base_pytorch_nn import BasePytorchClassifier


model = ...
torch_data_loader = ...

# Wrap model
model = BasePytorchClassifier(model)

# create and run attack
attack = PGD(
    perturbation_model="l2",
    epsilon=0.4,
    num_steps=100,
    step_size=0.01,
)

adversarial_loader = attack(model, torch_data_loader)

# Test accuracy on adversarial examples
robust_accuracy = Accuracy()(model, adversarial_loader)

For more detailed usage instructions and examples, please refer to the official documentation or to the examples.

Contributing

We welcome contributions from the research community to expand the library's capabilities or add new features. If you would like to contribute to SecMLT, please follow our contribution guidelines.

Contributors

Maura
maurapintor
zangobot/
zangobot
lucascionis/
lucascionis

Acknowledgements

SecML has been partially developed with the support of European Union’s ELSA – European Lighthouse on Secure and Safe AI, Horizon Europe, grant agreement No. 101070617, and Sec4AI4Sec - Cybersecurity for AI-Augmented Systems, Horizon Europe, grant agreement No. 101120393.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

secml_torch-1.2.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

secml_torch-1.2.1-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file secml_torch-1.2.1.tar.gz.

File metadata

  • Download URL: secml_torch-1.2.1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for secml_torch-1.2.1.tar.gz
Algorithm Hash digest
SHA256 2f3fcde274b2e2f700526f3582ed2b97f16e8713934c3ad9d6167d676e89ef80
MD5 688afc2aa0accb5a8fb365379f4fa1c2
BLAKE2b-256 2e026fead6ea617ffbc56a162620dcf7cd58193a29887761912e3ccd86c96fe0

See more details on using hashes here.

File details

Details for the file secml_torch-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: secml_torch-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for secml_torch-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c90e00ff12f6fa0fb0d3187e32b6e0574cc2f4e89a341a05cd5214b70008766a
MD5 6d6be3a9b3ab802f61607e82e77cb148
BLAKE2b-256 2b4cba6b62fe9a31460bf1881112d84bc055b98ca79ed36bee1f01fa6ed79f74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page