-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_attack_100.sh
executable file
·59 lines (50 loc) · 1.99 KB
/
run_attack_100.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# exit on first error
set -e
# directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ATTACKS_DIR="${SCRIPT_DIR}/attacks"
TARGETED_ATTACKS_DIR="${SCRIPT_DIR}/targeted_attacks"
DATASET_DIR="${SCRIPT_DIR}/dataset/100images"
DATASET_METADATA_FILE="${SCRIPT_DIR}/dataset/dev_dataset_100.csv"
MAX_EPSILON=16
mkdir -p "${ATTACKS_DIR}"
mkdir -p "${TARGETED_ATTACKS_DIR}"
touch "${ATTACKS_DIR}/placeholder"
touch "${TARGETED_ATTACKS_DIR}/placeholder"
# Prepare working directory and copy all necessary files.
# In particular copy attacks defenses and dataset, so originals won't
# be overwritten.
WORKING_DIR=${1:-"$(dirname "${SCRIPT_DIR}")"/100working}
mkdir -p "${WORKING_DIR}"
echo "Preparing working directory: ${WORKING_DIR}"
sudo rm -rf "${WORKING_DIR}/attacks"
sudo rm -rf "${WORKING_DIR}/targeted_attacks"
sudo rm -rf "${WORKING_DIR}/intermediate_results/all_adv_examples/"
mkdir -p "${WORKING_DIR}/attacks"
mkdir -p "${WORKING_DIR}/targeted_attacks"
mkdir -p "${WORKING_DIR}/dataset"
mkdir -p "${WORKING_DIR}/intermediate_results"
mkdir -p "${WORKING_DIR}/output_dir"
cp -R "${ATTACKS_DIR}"/* "${WORKING_DIR}/attacks"
cp -R "${TARGETED_ATTACKS_DIR}"/* "${WORKING_DIR}/targeted_attacks"
cp -R "${DATASET_DIR}"/* "${WORKING_DIR}/dataset"
cp "${DATASET_METADATA_FILE}" "${WORKING_DIR}/dataset.csv"
if hash nvidia-docker 2>/dev/null; then
echo "Detected GPU is available."
GPU_FLAG="--gpu"
else
echo "No GPU detected. Will run on CPU."
GPU_FLAG="--nogpu"
fi
echo "Running attacks on 100 sample images"
python "${SCRIPT_DIR}/run_attack_100.py" \
--attacks_dir="${WORKING_DIR}/attacks" \
--targeted_attacks_dir="${WORKING_DIR}/targeted_attacks" \
--dataset_dir="${WORKING_DIR}/dataset" \
--intermediate_results_dir="${WORKING_DIR}/intermediate_results" \
--dataset_metadata="${WORKING_DIR}/dataset.csv" \
--output_dir="${WORKING_DIR}/output_dir" \
--epsilon="${MAX_EPSILON}" \
${GPU_FLAG}
echo "Output is saved in directory '${WORKING_DIR}/output_dir'"