File size: 6,122 Bytes
d6b2940
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b108498a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from test_atks import test_atks_on_cifar10\n",
    "from test_import import test_import_version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3d08de15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.4.1\n"
     ]
    }
   ],
   "source": [
    "test_import_version()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2fd7a267",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torchattacks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "aea26465",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Files already downloaded and verified\n",
      "VANILA      : clean_acc=1.00 robust_acc=1.00 sec=0.00\n",
      "GN          : clean_acc=1.00 robust_acc=0.20 sec=0.00\n",
      "FGSM        : clean_acc=1.00 robust_acc=0.40 sec=0.02\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.40 sec=0.02\n",
      "BIM         : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "RFGSM       : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "PGD         : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "EOTPGD      : clean_acc=1.00 robust_acc=0.00 sec=0.22\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.22\n",
      "FFGSM       : clean_acc=1.00 robust_acc=0.20 sec=0.01\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.20 sec=0.01\n",
      "TPGD        : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "MIFGSM      : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "UPGD        : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "APGD        : clean_acc=1.00 robust_acc=0.00 sec=0.30\n",
      "APGDT       : clean_acc=1.00 robust_acc=0.00 sec=0.33\n",
      "DIFGSM      : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "TIFGSM      : clean_acc=1.00 robust_acc=0.20 sec=0.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.20 sec=0.07\n",
      "Jitter      : clean_acc=1.00 robust_acc=0.00 sec=0.25\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.40 sec=0.25\n",
      "NIFGSM      : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.06\n",
      "PGDRS       : clean_acc=1.00 robust_acc=0.80 sec=0.11\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.80 sec=0.11\n",
      "SINIFGSM    : clean_acc=1.00 robust_acc=0.00 sec=0.91\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.91\n",
      "VMIFGSM     : clean_acc=1.00 robust_acc=0.00 sec=1.15\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=1.15\n",
      "VNIFGSM     : clean_acc=1.00 robust_acc=0.00 sec=1.17\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=1.17\n",
      "SPSA        : clean_acc=1.00 robust_acc=0.40 sec=1.44\n",
      "- targeted  : clean_acc=1.00 robust_acc=1.00 sec=1.44\n",
      "JSMA        : clean_acc=1.00 robust_acc=0.00 sec=19.91\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=19.91\n",
      "EADL1       : clean_acc=1.00 robust_acc=0.00 sec=8.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=8.07\n",
      "EADEN       : clean_acc=1.00 robust_acc=0.00 sec=7.04\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=7.04\n",
      "PIFGSM      : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "PIFGSMPP    : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=1.00 sec=0.07\n",
      "CW          : clean_acc=1.00 robust_acc=0.00 sec=0.30\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.20 sec=0.30\n",
      "PGDL2       : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=0.07\n",
      "DeepFool    : clean_acc=1.00 robust_acc=0.20 sec=1.75\n",
      "PGDRSL2     : clean_acc=1.00 robust_acc=0.80 sec=0.13\n",
      "- targeted  : clean_acc=1.00 robust_acc=1.00 sec=0.13\n",
      "SparseFool  : clean_acc=1.00 robust_acc=0.60 sec=16.86\n",
      "OnePixel    : clean_acc=1.00 robust_acc=0.60 sec=0.83\n",
      "- targeted  : clean_acc=1.00 robust_acc=1.00 sec=0.83\n",
      "Pixle       : clean_acc=1.00 robust_acc=0.00 sec=1.15\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=1.15\n",
      "FAB         : clean_acc=1.00 robust_acc=0.00 sec=1.98\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=1.98\n",
      "AutoAttack  : clean_acc=1.00 robust_acc=0.00 sec=0.30\n",
      "Square      : clean_acc=1.00 robust_acc=0.00 sec=6.29\n",
      "- targeted  : clean_acc=1.00 robust_acc=0.00 sec=6.29\n"
     ]
    }
   ],
   "source": [
    "for atk_class in [atk_class for atk_class in torchattacks.__all__ if atk_class not in torchattacks.__wrapper__]:\n",
    "    test_atks_on_cifar10(atk_class=atk_class,\n",
    "                         device='cuda',\n",
    "                         model_dir='../demo/models/',\n",
    "                         data_dir='../demo/data/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "086977ef",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}