RepositoryPython
ashafahi

ashafahi/free_adv_train

Official TensorFlow Implementation of Adversarial Training for Free! which trains robust models at no extra cost compared to natural training.

176stars
30forks
5issues
0views

Free Adversarial Training

This repository belongs to the Free Adversarial Training paper. The implementation is inspired by CIFAR10 Adversarial Example Challenge so to them we give the credit. This repo is for the CIFAR-10 and CIFAR-100 datasets and is in Tensorflow. Our Free-m models can acheive comparable performance with conventional PGD adversarial training at a fraction of the time.

News!: We have released our ImageNet implementation of Free adversarial training in Pytorch !

CIFAR-10 WRN 32-10 (L-inf epsilon=8):
ModelNaturalPGD-100CW-10010 restart PGD-20train-time (min)
Natrual95.010.000.000.00780
Free-291.4533.2034.5733.41816
Free-487.8340.3541.9640.73800
Free-885.9646.1946.6046.33785
Free-1083.9445.7945.8645.94785
Madry 7-PGD (public model)87.2545.2946.5245.535418
CIFAR-100 WRN 32-10 (L-inf epsilon=8):
ModelNaturalPGD-20PGD-100train-time (min)
Natrual78.840.000.00811
Free-269.2015.3714.86816
Free-465.2820.6420.15767
Free-862.1325.8825.58780
Free-1059.2725.1524.88776
Madry 2-PGD trained67.9417.0816.502053
Madry 7-PGD trained59.8722.7622.525157

Demo

To train a new robust model for free! run the following command specifying the replay parameter m:

python free_train.py -m 8

To evaluate a robust model using PGD-20 with 2 random restarts run:

python multi_restart_pgd_attack.py --model_dir $MODEL_DIR --num_restarts 2

Note that if you have trained a CIFAR-100 model, even for evaluation, you should pass the dataset argument. For example:

python multi_restart_pgd_attack.py --model_dir $MODEL_DIR_TO_CIFAR100 --num_restarts 2 -d cifar100

Requirements

To install all the requirements plus tensorflow for multi-gpus run: (Inspired By Illarion ikhlestov )

pip install -r requirements/gpu.txt

Alternatively, to install the requirements plus tensorflow for cpu run:

pip install -r requirements/cpu.txt

To prepare the data, please see Datasets section.

If you find the paper or the code useful for your study, please consider citing the free training paper:

@article{shafahi2019adversarial,
  title={Adversarial Training for Free!},
  author={Shafahi, Ali and Najibi, Mahyar and Ghiasi, Amin and Xu, Zheng and Dickerson, John and Studer, Christoph and Davis, Larry S and Taylor, Gavin and Goldstein, Tom},
  journal={arXiv preprint arXiv:1904.12843},
  year={2019}
}

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
Trusted-AI/adversarial-robustness-toolbox

Adversarial Robustness Toolbox (ART) - Python Library for Machine Learning Security - Evasion, Poisoning, Extraction, Inference - Red and Blue Teams

6.3k
Nov 27, 2026
RepositoryPython
QData/TextAttack

TextAttack 🐙 is a Python framework for adversarial attacks, data augmentation, and model training in NLP https://textattack.readthedocs.io/en/master/

3.5k
Aug 15, 2026
RepositoryJupyter Notebook
MadryLab/photoguard

Raising the Cost of Malicious AI-Powered Image Editing

1.0k
Feb 27, 2023
RepositoryC++
Koukyosyumei/AIJack

Security and Privacy Risk Simulator for Machine Learning (arXiv:2312.17667)

429
May 30, 2026
RepositoryJupyter Notebook
shangtse/robust-physical-attack

Physical adversarial attack for fooling the Faster R-CNN object detector

170
Jan 13, 2020
RepositoryPython
bethgelab/foolbox

A Python toolbox to create adversarial examples that fool neural networks in PyTorch, TensorFlow, and JAX

3.0k
Dec 3, 2025
RepositoryPython
microsoftarchive/promptbench

A unified evaluation framework for large language models

2.8k
Feb 20, 2026
RepositoryPython
thunlp/TAADpapers

Must-read Papers on Textual Adversarial Attack and Defense

1.6k
Jun 4, 2025
RepositoryPython
thunlp/OpenAttack

An Open-Source Package for Textual Adversarial Attack.

782
Jul 20, 2023