-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_imagnet.sh
125 lines (100 loc) · 4.76 KB
/
main_imagnet.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
function log_msg {
echo "`date` $@"
}
# DATASETS=(cif10 cif10vgg cif100 cif100vgg imagenet imagenet32 imagenet64 imagenet128 celebaHQ32 celebaHQ64 celebaHQ128)
DATASETS="imagenet"
ATTACKS="fgsm bim std pgd df cw"
# ATTACKS="std"
DETECTORS="InputPFS LayerPFS InputMFS LayerMFS LID Mahalanobis"
CLF="LR RF"
IMAGENET32CLASSES="25 50 100 250 1000"
# NRSAMPLES="300 500 1000 1200 1500 2000"
NRSAMPLES="1500"
#-----------------------------------------------------------------------------------------------------------------------------------
log_msg "Networks are already trained!"
#-----------------------------------------------------------------------------------------------------------------------------------
genereratecleandata ()
{
log_msg "Generate Clean Data for Foolbox Attacks and Autoattack!"
for net in $DATASETS; do
if [ "$net" == imagenet ]; then
python -u generate_clean_data.py --net "$net" --num_classes 1000
fi
done
}
#-----------------------------------------------------------------------------------------------------------------------------------
attacks ()
{
log_msg "Attack Clean Data with Foolbox Attacks and Autoattack!"
for net in $DATASETS; do
for att in $ATTACKS; do
if [ "$net" == imagenet ]; then
if [ "$att" == std ]; then
python -u attacks.py --net "$net" --attack "$att" --img_size 32 --batch_size 128 --num_classes 1000
else
python -u attacks.py --net "$net" --attack "$att" --img_size 32 --batch_size 500 --num_classes 1000
fi
fi
done
done
}
#-----------------------------------------------------------------------------------------------------------------------------------
extractcharacteristics ()
{
log_msg "Extract Characteristics"
for net in $DATASETS; do
for att in $ATTACKS; do
for det in $DETECTORS; do
python -u extract_characteristics.py --net "$net" --attack "$att" --detector "$det" --num_classes 1000
done
done
done
}
# #-----------------------------------------------------------------------------------------------------------------------------------
detectadversarials ()
{
log_msg "Detect Adversarials!"
for net in $DATASETS; do
for att in $ATTACKS; do
for det in $DETECTORS; do
for nrsamples in $NRSAMPLES; do
for classifier in $CLF; do
python -u detect_adversarials.py --net "$net" --attack "$att" --detector "$det" --wanted_samples "$nrsamples" --clf "$classifier" --num_classes 1000
done
done
done
done
done
}
# for nr in {1,2,3,4}; do
# echo "Generate Clean Data: run: $nr"
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/clean_data', net=['imagenet'] )"
# genereratecleandata
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/clean_data', net=['imagenet'], dest='./log_evaluation/imagenet', run_nr=$nr)"
# done
# for nr in {1,2,3,4}; do
# echo "Attacks: run: $nr"
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/attacks', net=['imagenet'] )"
# attacks
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/attacks', net=['imagenet'], dest='./log_evaluation/imagenet', run_nr=$nr)"
# done
# for nr in 1; do
# python -c "import evaluate_detection; evaluate_detection.copy_run_to_root(root='./data', net=['imagenet'], dest='./log_evaluation/imagenet', run_nr=$nr)"
# extractcharacteristics
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/extracted_characteristics', net=['imagenet'], dest='./log_evaluation/imagenet', run_nr=$nr)"
# done
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/clean_data', net=['imagenet'] )"
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/attacks', net=['imagenet'] )"
# genereratecleandata
# attacks
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/clean_data', net=['imagenet'], dest='./log_evaluation/imagenet', run_nr=2)"
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/attacks', net=['imagenet'], dest='./log_evaluation/imagenet', run_nr=2)"
# extractcharacteristics
# detectadversarials
# #-----------------------------------------------------------------------------------------------------------------------------------
log_msg "finished"
exit 0
# : <<'END'
# just a comment!
# END