Python implementation of "Appropriate Balance of Diversification and Intensification Improves Performance and Efficiency of Adversarial Attacks".
- Python >= 3.9
- CUDA >= 11.6
- PyTorch >= 1.12.0+cu116
- TorchVision >= 0.13.0+cu116
- gcc >= 4.5
Installing dependencies
pip install -U pip && pip install -r requirements.txt
Build C++ extensions
cd src/extension && python setup.py build_ext --inplace && cd -
- ImageNet
cd data/imagenet
- Download
ILSVRC2012_img_val.tar
andILSVRC2012_devkit_t12.tar.gz
from ImageNet official site mkdir val && tar -xf ILSVRC2012_img_val.tar -C ./val
tar -xzf ILSVRC2012_devkit_t12.tar.gz
python build_dataset.py
mv val val_original && mv ILSVRC2012_img_val_for_ImageFolder val
python efficient_diversified_attack.py -p ../configs/config_eda.yaml -g 0 -o ../debug --log_level 20 --export_level 60
python efficient_diversified_attack.py [-h] -o OUTPUT_DIR -p [PARAM ...]
[--cmd_param [CMD_PARAM ...]] [-g GPU]
[-bs BATCH_SIZE] [--n_threads N_THREADS]
[--image_indices IMAGE_INDICES]
[--log_level LOG_LEVEL]
[--export_level {10,20,30,40,50,60}]
[--experiment]
Optional arguments:
-h, --help show this help message and exit
-o OUTPUT_DIR, --output_dir OUTPUT_DIR
Output directory name (not path)
-p [PARAM ...], --param [PARAM ...]
--cmd_param [CMD_PARAM ...]
list of "<param>:<cast type>:<value>" ex) model_name:str:XXX param.max_iter:int:100
-g GPU, --gpu GPU
-bs BATCH_SIZE, --batch_size BATCH_SIZE
--n_threads N_THREADS
--image_indices IMAGE_INDICES
path to yaml file which contains target image indices
--log_level LOG_LEVEL
10:DEBUG,20:INFO,30:WARNING,40:ERROR,50:CRITICAL
--export_level {10,20,30,40,50,60}
--experiment attack all images when this flag is on
The default parameter file for EDA is configs/config_eda.yaml
.
python global_search_and_local_search.py -p ../configs/config_gsls.yaml -g 0 -o ../debug --log_level 20 --export_level 60
python global_search_and_local_search.py [-h] -o OUTPUT_DIR -p [PARAM ...] [--cmd_param [CMD_PARAM ...]] [-g GPU] [-bs BATCH_SIZE] [--n_threads N_THREADS]
[--image_indices IMAGE_INDICES] [--log_level LOG_LEVEL] [--export_level {10,20,30,40,50,60}] [--experiment]
Optional arguments:
-h, --help show this help message and exit
-o OUTPUT_DIR, --output_dir OUTPUT_DIR
Output directory name (not path)
-p [PARAM ...], --param [PARAM ...]
--cmd_param [CMD_PARAM ...]
list of "param:cast type:value" ex) model_name:str:XXX param.max_iter:int:100
-g GPU, --gpu GPU
-bs BATCH_SIZE, --batch_size BATCH_SIZE
--n_threads N_THREADS
--image_indices IMAGE_INDICES
path to yaml file which contains target image indices
--log_level LOG_LEVEL
10:DEBUG,20:INFO,30:WARNING,40:ERROR,50:CRITICAL
--export_level {10,20,30,40,50,60}
--experiment attack all images when this flag is on
python target_selection_and_targeted_attack.py -p ../configs/config_tsta.yaml -g 0 -o ../debug --log_level 20 --export_level 60
python target_selection_and_targeted_attack.py [-h] -o OUTPUT_DIR -p [PARAM ...] [--cmd_param [CMD_PARAM ...]] [-g GPU] [-bs BATCH_SIZE] [--n_threads N_THREADS]
[--image_indices IMAGE_INDICES] [--log_level LOG_LEVEL] [--export_level {10,20,30,40,50,60}] [--experiment]
Optional arguments:
-h, --help show this help message and exit
-o OUTPUT_DIR, --output_dir OUTPUT_DIR
Output directory name (not path)
-p [PARAM ...], --param [PARAM ...]
--cmd_param [CMD_PARAM ...]
list of "param:cast type:value" ex) model_name:str:XXX param.max_iter:int:100
-g GPU, --gpu GPU
-bs BATCH_SIZE, --batch_size BATCH_SIZE
--n_threads N_THREADS
--image_indices IMAGE_INDICES
path to yaml file which contains target image indices
--log_level LOG_LEVEL
10:DEBUG,20:INFO,30:WARNING,40:ERROR,50:CRITICAL
--export_level {10,20,30,40,50,60}
--experiment attack all images when this flag is on
The execution result files are stored under OUTPUT_DIR
specified with the -o
option, in a structure like OUTPUT_DIR/<date>/<time>/<dataset>/<model_name>/
.
The attack success rate and execution time are listed in OUTPUT_DIR/<date>/<time>/<dataset>/<model_name>/short_summary_<method>.txt
.
The execution commands are generated by executing the following command.
cd reproduce_experiments/; python generate_cmds_gsls.py
Then, move to src
and execute sh cmds_all_ads_gsls.sh
.
The execution commands are generated by executing the following command.
cd reproduce_experiments/; python generate_cmds_eda.py
Then, move to src
and execute sh cmds_all_eda.sh
.
The execution commands are generated by executing the following command.
cd reproduce_experiments/; python generate_cmds_eda_and_target_selection.py
Then, move to src
and execute sh cmds_all_eda_ablation.sh
.