SecML-Torch: A Library for Robustness Evaluation of Deep Learning Models
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.
- Adversarial Library, a powerful library of various adversarial attacks resources in PyTorch.
Install one or more extras with the command:
pip install secml-torch[foolbox,tensorboard,adv_lib]
Key Features
SecML-Torch (SecMLT) is a PyTorch-native toolkit for evaluating and improving adversarial robustness. It provides:
- Built-in support for evaluating PyTorch models.
- Efficient native implementations of common evasion attacks (e.g. PGD, FMN), built directly for PyTorch, and poisoning/backdoor attacks.
- Wrappers for external libraries (Foolbox, Adversarial Library) so you can run and compare attacks from a single interface.
- Modular design to build adaptive/custom attacks to swap losses, optimizers, perturbation models, and add EoT easily with a few lines of code.
- Attack ensembling modules to obtain worst-case per-sample robustness evaluations.
- Robustness evaluation tools including metrics, logging, and trackers to ensure reproducibility and easy reporting.
- Attack debugging support such as built-in hooks and TensorBoard integration to monitor and inspect attack behavior.
Check out the tutorials to see SecML-Torch in action.
| Category | Attack / Attack Type | Native Implementation in SecML-Torch | Wrapped / Imported / Backend Alternatives |
|---|---|---|---|
| Advantages: GPU-native, efficient, modular/customizable, debugging tools | Advantages: expands the attack catalogue, easy cross-checks | ||
| Test time | PGD (fixed-epsilon, iterative attack) | ✔ Native implementation | ✔ Also via backend wrappers (Foolbox, Adversarial Library). |
| Test time | FMN (minimum-norm, iterative attack) | ✔ Native implementation | ✔ Also via backend wrappers (Foolbox, Adversarial Library). |
| Test time | DDN (minimum-norm, iterative attack) | ✔ Native implementation | ✔ Also via backend wrappers (Foolbox, Adversarial Library). |
| Test time | FGSM (Fast Gradient Sign Method) | - | ✔ Available via backend wrappers (Foolbox, Adversarial Library). |
| Test time | CW (Carlini & Wagner L2) | - | ✔ Available via backend wrappers (Foolbox, Adversarial Library). |
| Test time | DeepFool | - | ✔ Available via backend wrappers (Foolbox, Adversarial Library). |
| Test time | VAT (Virtual Adversarial Training) | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | HopSkipJump (black-box attack) | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | Boundary Attack (black-box attack) | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | Spatial Attack | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | Additive Noise | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | Salt & Pepper Noise | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | Gaussian Blur | - | ✔ Available via backend wrapper (Foolbox). |
| Test time | Contrast Reduction | - | ✔ Available via backend wrapper (Foolbox). |
| Training time | Backdoor | ✔ Native implementation | - |
| Training time | Label Flip Poisoning | ✔ Native implementation | - |
Check out what's cooking! Have a look at our roadmap!
Usage
Here's a brief example of using SecMLT to evaluate the robustness of a trained classifier:
from secmlt.adv.evasion import PGD
from secmlt.metrics import Accuracy
model = ...
torch_data_loader = ...
# 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.
Acknowledgements
SecML-Torch 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, Sec4AI4Sec - Cybersecurity for AI-Augmented Systems, Horizon Europe, grant agreement No. 101120393, CoEvolution - A Comprehensive Trustworthy Framework for Connected Machine Learning and Secure Interconnected AI Solutions, Horizon Europe, grant agreement No. 101168560, by the project SERICS (PE00000014) under the MUR National Recovery and Resilience Plan funded by the European Union - NextGenerationEU, and by the project FISA-2023-00128 - A Platform for conformity assessment of AI Systems with the EU Artificial Intelligence Act, Fondo Italiano Scienze Applicate, Ministero dell'Università e della Ricerca.
Metadata
Release files for secml-torch 1.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| secml_torch-1.5.2.tar.gz | 60.1 kB | With provenance | Details for secml_torch-1.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| secml_torch-1.5.2-py3-none-any.whl | Python 3 | none | any | Details for secml_torch-1.5.2-py3-none-any.whl |
Total release size: 166.8 kB
Release files / secml_torch-1.5.2.tar.gz
| Download URL | secml_torch-1.5.2.tar.gz |
|---|---|
| Size | 60.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9c73d8cd9e84c527e459e280ba135ba4c51f8be97a3f17fae7e76e92d2cee9a
|
|
BLAKE2b-256 checksum How to use checksums |
183c466400eda8db88e2484bc8b9086c7f984aa7b0e0edb4f9beb6403a5cc9d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logRelease files / secml_torch-1.5.2-py3-none-any.whl
| Download URL | secml_torch-1.5.2-py3-none-any.whl |
|---|---|
| Size | 106.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4492e1360ecfcda1a172ad812346481c779331ffe1807d18b3ae9756ed8fea83
|
|
BLAKE2b-256 checksum How to use checksums |
7dd569a78ef9007e09cca596b590ab95884e2a8d7e020f7845e1a10465ac5cfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logSecurity for secml-torch 1.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for secml_torch-1.5.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.