MCPcopy Index your code
hub / github.com/Trustworthy-AI-Group/TransferAttack

github.com/Trustworthy-AI-Group/TransferAttack @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
2,815 symbols 6,913 edges 243 files 736 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TransferAttack

About

GitHub stars GitHub issues GitHub forks

TransferAttack is a pytorch framework to boost the adversarial transferability for image classification.

Devling into Adversarial Transferability on Image Classification: Review, Benchmark, and Evaluation.

Overview

We also release a list of papers about transfer-based attacks here.

Why TransferAttack

There are a lot of reasons for TransferAttack, such as:

  • A benchmark for evaluating new transfer-based attacks: TransferAttack categorizes existing transfer-based attacks into several types and fairly evaluates various transfer-based attacks under the same setting.
  • Evaluate the robustness of deep models: TransferAttack provides a plug-and-play interface to verify the robustness of models, such as CNNs and ViTs.
  • A summary of transfer-based attacks: TransferAttack reviews numerous transfer-based attacks, making it easy to get the whole picture of transfer-based attacks for practitioners.

Citation

If our paper or this code is useful for your research, please cite our paper:

@article{wang2026devling,
     title={{Devling into Adversarial Transferability on Image Classification: Review, Benchmark, and Evaluation}},
     author={Xiaosen Wang and Zhijin Ge and Bohan Liu and Zheng Fang and Fengfan Zhou and Ruixuan Zhang and Shaokang Wang and Yuyang Luo},
     journal={arXiv preprint arXiv:2602.23117},
     year={2026}
}

Requirements

  • Python >= 3.6
  • PyTorch >= 1.12.1
  • Torchvision >= 0.13.1
  • timm >= 0.6.12
pip install -r requirements.txt

Usage

We adopt an academic-standard ImageNet-compatible dataset comprising 1,000 PNG images for our experiments. Download the data from GoogleDrive or [Huggingface Spaces into /path/to/data. Then you can execute the attack as follows:

python main.py --input_dir ./path/to/data --output_dir adv_data/mifgsm/resnet50 --attack mifgsm --model=resnet50
python main.py --input_dir ./path/to/data --output_dir adv_data/mifgsm/resnet50 --eval

Attacks and Models

Untargeted Attacks

Category Attack Main Idea
Gradient-based FGSM (Goodfellow et al., 2015) Add a small perturbation in the direction of gradient
I-FGSM (Kurakin et al., 2015) Iterative version of FGSM
MI-FGSM (Dong et al., 2018) Integrate the momentum term into the I-FGSM
NI-FGSM (Lin et al., 2020) Integrate the Nesterov's accelerated gradient into I-FGSM
PI-FGSM (Gao et al., 2020) Reuse the cut noise and apply a heuristic project strategy to generate patch-wise noise
VMI-FGSM (Wang et al., 2021) Variance tuning MI-FGSM
VNI-FGSM (Wang et al., 2021) Variance tuning NI-FGSM
EMI-FGSM (Wang et al., 2021) Accumulate the gradients of several data points linearly sampled in the direction of previous gradient
AI-FGTM (Zou et al., 2022) Adopt Adam to adjust the step size and momentum using the tanh function
I-FGS²M (Zhang et al., 2021) Assigning staircase weights to each interval of the gradient
SMI-FGRM (Han et al., 2023) Substitute the sign function with data rescaling and use the depth first sampling technique to stabilize the update direction.
VA-I-FGSM (Zhang et al., 2022) Adopt a larger step size and auxiliary gradients from other categories
RAP (Qin et al., 2022) Inject the worst-case perturbation when calculating the gradient.
PC-I-FGSM (Wan et al., 2023) Gradient Prediction-Correction on MI-FGSM
IE-FGSM (Peng et al., 2023) Integrate anticipatory data point to stabilize the update direction.
GRA (Zhu et al., 2023) Correct the gradient using the average gradient of several data points sampled in the neighborhood and adjust the update gradient with a decay indicator
GNP (Wu et al., 2023) Introduce a gradient norm penalty (GNP) term into the loss function
MIG (Ma et al., 2023) Utilize integrated gradient to steer the generation of adversarial perturbations
DTA (Yang et al., 2023) Calculate the gradient on several examples using small stepsize
PGN (Ge et al., 2023) Penalizing gradient norm on the original loss function
MEF (Qiu et al., 2024) Construct a max-min bi-level optimization problem aimed at finding flat adversarial regions
ANDA (Fang et al., 2024) Explicitly characterize adversarial perturbations from a learned distribution by taking advantage of the asymptotic normality property of stochastic gradient ascent.
GI-FGSM (Wang et al., 2024) Use global momentum initialization to better stablize update direction.
FGSRA (Wang et al., 2024) Leverage frequency information and introduce similarity weights to assess neighborhood contribution.
AdaMSI-FGM (Long et al., 2024) Guarantees convergence by incorporating an innovative, non-monotonic adaptive momentum parameter and replacing the problematic sign operation with an adaptive step-size scheme.
MUMODIG (Ren et al., 2025) Improve integrated gradients attacks by generating integration paths through multiple baseline samples and enforcing the monotonicity of each path.
LI-Boost (Liu et al., 2025) Optimize the adversarial perturbation using the gradient of adversarial examples with several sampled perturbations according to a logarithmic distribution, thus enhancing the local invariance.
GAA (Gan et al., 2025) Aggregate adversarial examples in the neighborhood with worst-aware loss and substitute loss to obtain a flatter local minimum.
Foolmix (Li et al., 2025) Strengthen the transferability of adversarial examples by dual-blending and direction update strategy.
Input transformation-based DIM (Xie et al., 2019) Random resize and add padding to the input sample
TIM (Dong et al., 2019) Adopt a Gaussian kernel to smooth the gradient before updating the perturbation
SIM (Ling et al., 2020) Calculate the average gradient of several scaled images
DEM (Zou et al., 2020) Calculate the average gradient of several DIM's transformed images
Admix (Wang et al., 2021) Mix up the images from other categories
ATTA (Wu et al., 2021) Train an adversarial transformation network to perform the input-transformation
MaskBlock (Fan et al., 2022) Calculate the average gradients of multiple randomly block-level masked images.
SSM (Long et al., 2022) Randomly scale images and add noise in the frequency domain
AITL (Yuan et al., 2022) Select the most effective combination of image transformations specific to the input image.
PAM (Zhang et al., 2023) Mix adversarial examples with base images, where ratios are genreated by a trianed semantic predictor, for gradient accumulation.
LPM (Wei et al., 2023) Boosting Adversarial Transferability with Learnable Pat

Core symbols most depended-on inside this repo

init_delta
called by 96
transferattack/attack.py
get_logits
called by 89
transferattack/model_related/faug.py
update_delta
called by 78
transferattack/gradient/gaa.py
load_state_dict
called by 72
transferattack/model_related/awt.py
get_momentum
called by 68
transferattack/gradient/adamsi_fgm.py
get_grad
called by 61
transferattack/model_related/ana.py
transform
called by 60
transferattack/gradient/mig.py
get_loss
called by 46
transferattack/gradient/mig.py

Shape

Method 1,772
Class 551
Function 492

Languages

Python100%
C++1%

Modules by API surface

defense/diffpure/score_sde/models/layers.py68 symbols
transferattack/input_transformation/l2t.py60 symbols
defense/diffpure/guided_diffusion/logger.py59 symbols
defense/hgd/inceptionresnet.py46 symbols
defense/hgd/inception.py46 symbols
transferattack/model_related/ata_vit_utils/Transformer_Explainability/modules/layers_ours.py45 symbols
defense/diffpure/score_sde/sampling.py44 symbols
defense/diffpure/guided_diffusion/unet.py43 symbols
transferattack/model_related/dhf.py42 symbols
transferattack/model_related/ata_vit_utils/Transformer_Explainability/baselines/ViT/ViT_LRP.py41 symbols
transferattack/input_transformation/aitl.py40 symbols
transferattack/model_related/setr_networks/swin_transformer.py37 symbols

For agents

$ claude mcp add TransferAttack \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact