質問編集履歴
6
全体的な修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,11 +32,11 @@
|
|
32
32
|
|
33
33
|
%matplotlib inline
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
|
37
|
-
----------------------------
|
37
|
+
#----------------------------
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
|
40
40
|
|
41
41
|
!wget https://github.com/GANs-in-Action/gans-in-action/raw/Chapter-10/chapter-10/DSC_0897.jpg
|
42
42
|
|
@@ -44,9 +44,9 @@
|
|
44
44
|
|
45
45
|
!wget https://raw.githubusercontent.com/GANs-in-Action/gans-in-action/master/chapter-10/initialization_vals_for_noise.csv
|
46
46
|
|
47
|
-
------------------------------------------------------
|
47
|
+
#------------------------------------------------------
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
|
50
50
|
|
51
51
|
def load_image(img_path: str):
|
52
52
|
|
@@ -62,11 +62,11 @@
|
|
62
62
|
|
63
63
|
image = load_image('DSC_0897.jpg')
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
|
66
|
+
|
67
|
-
-------------------------------------------------------
|
67
|
+
#-------------------------------------------------------
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
|
71
71
|
keras.backend.set_learning_phase(0)
|
72
72
|
|
@@ -122,15 +122,15 @@
|
|
122
122
|
|
123
123
|
pp.pprint(decode_predictions(new_preds, top=20)[0]))
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
|
126
|
+
|
127
|
-
------------------------------------------------------------
|
127
|
+
# ------------------------------------------------------------
|
128
|
-
|
129
|
-
|
128
|
+
|
129
|
+
|
130
130
|
|
131
131
|
plt.figure(figsize=(12,12))
|
132
132
|
|
133
|
-
|
133
|
+
|
134
134
|
|
135
135
|
plt.subplot(1, 3, 1)
|
136
136
|
|
@@ -166,17 +166,17 @@
|
|
166
166
|
|
167
167
|
plt.show()
|
168
168
|
|
169
|
-
|
170
|
-
|
169
|
+
|
170
|
+
|
171
|
-
--------------------------------------------
|
171
|
+
# --------------------------------------------
|
172
|
-
|
173
|
-
|
172
|
+
|
173
|
+
|
174
174
|
|
175
175
|
max_vals = pd.read_csv('initialization_vals_for_noise.csv')
|
176
176
|
|
177
|
-
|
178
|
-
|
177
|
+
|
178
|
+
|
179
|
-
-----------------------------------------
|
179
|
+
#-----------------------------------------
|
180
180
|
|
181
181
|
|
182
182
|
|
@@ -260,11 +260,11 @@
|
|
260
260
|
|
261
261
|
plt.show()
|
262
262
|
|
263
|
-
|
264
|
-
|
263
|
+
|
264
|
+
|
265
|
-
----------------------------------------------------
|
265
|
+
##----------------------------------------------------
|
266
|
-
|
267
|
-
|
266
|
+
|
267
|
+
|
268
268
|
|
269
269
|
fig = plt.figure(figsize=(20,20))
|
270
270
|
|
@@ -320,7 +320,7 @@
|
|
320
320
|
|
321
321
|
|
322
322
|
|
323
|
-
|
323
|
+
|
324
324
|
|
325
325
|
for i in range(1,101):
|
326
326
|
|
@@ -340,9 +340,9 @@
|
|
340
340
|
|
341
341
|
plt.show()
|
342
342
|
|
343
|
-
|
344
|
-
|
343
|
+
|
344
|
+
|
345
|
-
--------------------------------------------------
|
345
|
+
#--------------------------------------------------
|
346
346
|
|
347
347
|
|
348
348
|
|
@@ -362,17 +362,17 @@
|
|
362
362
|
|
363
363
|
AssertionError Traceback (most recent call last)
|
364
364
|
|
365
|
-
<ipython-input-
|
365
|
+
<ipython-input-3-9446ca790563> in <module>()
|
366
|
-
|
366
|
+
|
367
|
-
|
367
|
+
164 mu = mu_list.pop(0)
|
368
|
-
|
368
|
+
|
369
|
-
|
369
|
+
165 sigma = sigma_list.pop(0)
|
370
|
-
|
370
|
+
|
371
|
-
--
|
371
|
+
--> 166 make_subplot(10,10, i, new_row=True)
|
372
|
-
|
372
|
+
|
373
|
-
|
373
|
+
167 else:
|
374
|
-
|
374
|
+
|
375
|
-
|
375
|
+
168 make_subplot(10,10, i)
|
376
376
|
|
377
377
|
|
378
378
|
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,19 +46,21 @@
|
|
46
46
|
|
47
47
|
------------------------------------------------------
|
48
48
|
|
49
|
+
|
50
|
+
|
49
|
-
|
51
|
+
def load_image(img_path: str):
|
50
|
-
|
52
|
+
|
51
|
-
|
53
|
+
image = img.load_img(img_path, target_size=(224, 224))
|
52
|
-
|
54
|
+
|
53
|
-
|
55
|
+
plt.imshow(image)
|
54
|
-
|
56
|
+
|
55
|
-
|
57
|
+
x = img.img_to_array(image)
|
56
|
-
|
58
|
+
|
57
|
-
|
59
|
+
return x
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
|
61
|
+
|
62
|
+
|
61
|
-
|
63
|
+
image = load_image('DSC_0897.jpg')
|
62
64
|
|
63
65
|
|
64
66
|
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -284,9 +284,13 @@
|
|
284
284
|
|
285
285
|
label = np.argmax(first_pred)
|
286
286
|
|
287
|
-
attack = foolbox.attacks.ProjectedGradientDescentAttack(fmodel, threshold=.999,
|
288
|
-
|
289
|
-
|
287
|
+
attack = foolbox.attacks.ProjectedGradientDescentAttack(fmodel, threshold=.999,
|
288
|
+
|
289
|
+
distance=foolbox.distances.Linfinity,
|
290
|
+
|
291
|
+
criterion=ConfidentMisclassification(.999))
|
292
|
+
|
293
|
+
adversarial = attack(rand_noise[:, :, ::-1], label) ##ここです##
|
290
294
|
|
291
295
|
noise_preds = kmodel.predict(np.expand_dims(adversarial, axis=0))
|
292
296
|
|
3
インテンドの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,46 +1,48 @@
|
|
1
1
|
```
|
2
2
|
|
3
|
-
|
3
|
+
!pip install tensorflow==2.0.0
|
4
|
-
|
4
|
+
|
5
|
-
|
5
|
+
!pip install keras==2.3.1
|
6
|
-
|
6
|
+
|
7
|
-
|
7
|
+
!pip install foolbox==2.4.0
|
8
|
-
|
8
|
+
|
9
|
-
|
9
|
+
!pip3 install h5py==2.10.0
|
10
|
-
|
10
|
+
|
11
|
-
|
11
|
+
import h5py
|
12
|
-
|
12
|
+
|
13
|
-
|
13
|
+
import numpy as np
|
14
|
-
|
14
|
+
|
15
|
-
|
15
|
+
from keras.applications.resnet50 import ResNet50
|
16
|
-
|
16
|
+
|
17
|
-
|
17
|
+
from foolbox.criteria import Misclassification, ConfidentMisclassification
|
18
|
-
|
18
|
+
|
19
|
-
|
19
|
+
from keras.preprocessing import image as img
|
20
|
-
|
20
|
+
|
21
|
-
|
21
|
+
from keras.applications.resnet50 import preprocess_input, decode_predictions
|
22
|
-
|
22
|
+
|
23
|
-
|
23
|
+
import matplotlib.pyplot as plt
|
24
|
-
|
24
|
+
|
25
|
-
|
25
|
+
import foolbox
|
26
|
-
|
26
|
+
|
27
|
-
|
27
|
+
import pprint as pp
|
28
|
+
|
28
|
-
|
29
|
+
import keras
|
30
|
+
|
29
|
-
|
31
|
+
import pandas as pd
|
30
|
-
|
32
|
+
|
31
|
-
|
33
|
+
%matplotlib inline
|
32
34
|
|
33
35
|
|
34
36
|
|
35
37
|
----------------------------
|
36
38
|
|
39
|
+
|
40
|
+
|
37
|
-
|
41
|
+
!wget https://github.com/GANs-in-Action/gans-in-action/raw/Chapter-10/chapter-10/DSC_0897.jpg
|
38
42
|
|
39
43
|
!wget https://github.com/GANs-in-Action/gans-in-action/raw/Chapter-10/chapter-10/DSC_0896.jpg
|
40
44
|
|
41
|
-
|
45
|
+
!wget https://raw.githubusercontent.com/GANs-in-Action/gans-in-action/master/chapter-10/initialization_vals_for_noise.csv
|
42
|
-
|
43
|
-
|
44
46
|
|
45
47
|
------------------------------------------------------
|
46
48
|
|
@@ -64,45 +66,59 @@
|
|
64
66
|
|
65
67
|
|
66
68
|
|
67
|
-
|
69
|
+
keras.backend.set_learning_phase(0)
|
68
|
-
|
70
|
+
|
69
|
-
|
71
|
+
kmodel = ResNet50(weights='imagenet')
|
70
|
-
|
72
|
+
|
71
|
-
|
73
|
+
preprocessing = (np.array([104, 116, 123]), 1)
|
74
|
+
|
72
|
-
|
75
|
+
#Kerasからfoolboxモデルのオブジェクトを生成する
|
73
|
-
|
74
|
-
|
76
|
+
|
75
|
-
|
77
|
+
fmodel = foolbox.models.KerasModel(kmodel, bounds=(0, 255),
|
76
|
-
|
78
|
+
|
77
|
-
|
79
|
+
preprocessing=preprocessing)
|
80
|
+
|
78
|
-
|
81
|
+
#画像を(1,224,224,3)にしてResNet-50に合わせ、
|
82
|
+
|
79
|
-
|
83
|
+
#推定に使う画像がバッチに収まるようにする
|
80
|
-
|
84
|
+
|
81
|
-
|
85
|
+
to_classify = np.expand_dims(image, axis=0)
|
86
|
+
|
82
|
-
|
87
|
+
#predictを呼び出し、結果を表示する
|
88
|
+
|
83
|
-
|
89
|
+
preds = kmodel.predict(to_classify)
|
90
|
+
|
84
|
-
|
91
|
+
print('Predicted:',
|
92
|
+
|
85
|
-
|
93
|
+
pp.pprint(decode_predictions(preds, top=20)[0]))
|
94
|
+
|
86
|
-
|
95
|
+
#あとでラベルとして使うため、一番大きな数のインデックスを得る
|
96
|
+
|
87
|
-
|
97
|
+
label = np.argmax(preds)
|
98
|
+
|
99
|
+
|
100
|
+
|
88
|
-
|
101
|
+
#Keras ReNet-50はRGBではなくBGRのため、::-1で色チャンネルを逆転させる
|
89
|
-
|
90
|
-
|
102
|
+
|
91
|
-
|
103
|
+
image = image[:, :, ::-1]
|
104
|
+
|
92
|
-
|
105
|
+
#高い分類間違い基準を持った、攻撃のためのオブジェクトを作る
|
106
|
+
|
93
|
-
|
107
|
+
attack = foolbox.v1.attacks.FGSM(fmodel, threshold=.9,
|
94
|
-
|
108
|
+
|
95
|
-
|
109
|
+
criterion=ConfidentMisclassification(.9))
|
110
|
+
|
96
|
-
|
111
|
+
#ソース画像に攻撃を加える
|
112
|
+
|
97
|
-
|
113
|
+
adversarial = attack(image, label)
|
114
|
+
|
98
|
-
|
115
|
+
#敵対的サンプルのラベルを新たに推定する
|
99
|
-
|
100
|
-
|
116
|
+
|
101
|
-
|
117
|
+
new_preds = kmodel.predict(np.expand_dims(adversarial, axis=0))
|
102
|
-
|
118
|
+
|
103
|
-
|
119
|
+
print('Predicted:',
|
104
|
-
|
120
|
+
|
105
|
-
|
121
|
+
pp.pprint(decode_predictions(new_preds, top=20)[0]))
|
106
122
|
|
107
123
|
|
108
124
|
|
@@ -110,43 +126,43 @@
|
|
110
126
|
|
111
127
|
|
112
128
|
|
113
|
-
|
129
|
+
plt.figure(figsize=(12,12))
|
114
|
-
|
115
|
-
|
116
|
-
|
130
|
+
|
131
|
+
|
132
|
+
|
117
|
-
|
133
|
+
plt.subplot(1, 3, 1)
|
118
|
-
|
134
|
+
|
119
|
-
|
135
|
+
plt.title('Original')
|
120
|
-
|
136
|
+
|
121
|
-
|
137
|
+
plt.imshow(image[:,:,::-1] / 255) # division by 255 to convert [0, 255] to [0, 1]
|
122
|
-
|
138
|
+
|
123
|
-
|
139
|
+
plt.axis('off')
|
124
|
-
|
125
|
-
|
126
|
-
|
140
|
+
|
141
|
+
|
142
|
+
|
127
|
-
|
143
|
+
plt.subplot(1, 3, 2)
|
128
|
-
|
144
|
+
|
129
|
-
|
145
|
+
plt.title('Adversarial')
|
130
|
-
|
146
|
+
|
131
|
-
|
147
|
+
plt.imshow(adversarial[:, :, ::-1] / 255) # ::-1 to convert BGR to RGB
|
132
|
-
|
148
|
+
|
133
|
-
|
149
|
+
plt.axis('off')
|
134
|
-
|
135
|
-
|
136
|
-
|
150
|
+
|
151
|
+
|
152
|
+
|
137
|
-
|
153
|
+
plt.subplot(1, 3, 3)
|
138
|
-
|
154
|
+
|
139
|
-
|
155
|
+
plt.title('Difference')
|
140
|
-
|
156
|
+
|
141
|
-
|
157
|
+
difference = adversarial[:, :, ::-1] - image
|
142
|
-
|
158
|
+
|
143
|
-
|
159
|
+
plt.imshow(difference / abs(difference).max() * 0.2 + 0.5)
|
144
|
-
|
160
|
+
|
145
|
-
|
161
|
+
plt.axis('off')
|
146
|
-
|
147
|
-
|
148
|
-
|
162
|
+
|
163
|
+
|
164
|
+
|
149
|
-
|
165
|
+
plt.show()
|
150
166
|
|
151
167
|
|
152
168
|
|
@@ -154,91 +170,93 @@
|
|
154
170
|
|
155
171
|
|
156
172
|
|
157
|
-
|
173
|
+
max_vals = pd.read_csv('initialization_vals_for_noise.csv')
|
158
174
|
|
159
175
|
|
160
176
|
|
161
177
|
-----------------------------------------
|
162
178
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
num = ro
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
ma
|
234
|
-
|
235
|
-
el
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
179
|
+
|
180
|
+
|
181
|
+
fig = plt.figure(figsize=(20,20))
|
182
|
+
|
183
|
+
# 平均と分散をfloatのリストにする
|
184
|
+
|
185
|
+
sigma_list = list(max_vals.sigma)
|
186
|
+
|
187
|
+
mu_list = list(max_vals.mu)
|
188
|
+
|
189
|
+
conf_list = []
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
# 図10.8を表示するためのコア関数
|
194
|
+
|
195
|
+
def make_subplot(x, y, z, new_row=False):
|
196
|
+
|
197
|
+
# それぞれの平均と分散を持ったのノイズをサンプリング
|
198
|
+
|
199
|
+
rand_noise = np.random.normal(loc=mu, scale=sigma, size=(224,224, 3))
|
200
|
+
|
201
|
+
# 0-255の画素値のみを許す
|
202
|
+
|
203
|
+
rand_noise = np.clip(rand_noise, 0, 255.)
|
204
|
+
|
205
|
+
# 最初の推定を得る
|
206
|
+
|
207
|
+
noise_preds = kmodel.predict(np.expand_dims(rand_noise, axis=0))
|
208
|
+
|
209
|
+
# 推定したクラスと確信度を得る
|
210
|
+
|
211
|
+
prediction, num = decode_predictions(noise_preds, top=20)[0][0][1:3]
|
212
|
+
|
213
|
+
num = round(num * 100, 2)
|
214
|
+
|
215
|
+
conf_list.append(num)
|
216
|
+
|
217
|
+
# 図10.8のための注釈用コードをセットアップしたのちに、注釈文を足す
|
218
|
+
|
219
|
+
ax = fig.add_subplot(x,y,z)
|
220
|
+
|
221
|
+
ax.annotate(prediction, xy=(0.1, 0.6), xycoords=ax.transAxes, fontsize=16, color='yellow')
|
222
|
+
|
223
|
+
ax.annotate(f'{num}%' , xy=(0.1, 0.4), xycoords=ax.transAxes, fontsize=20, color='orange')
|
224
|
+
|
225
|
+
if new_row:
|
226
|
+
|
227
|
+
ax.annotate(f'$\mu$:{mu}, $\sigma$:{sigma}' , xy=(-.2, 0.8), xycoords=ax.transAxes,
|
228
|
+
|
229
|
+
rotation=90, fontsize=16, color='black')
|
230
|
+
|
231
|
+
# [0, 255]を[0, 1]に変換するため、255で割る
|
232
|
+
|
233
|
+
ax.imshow(rand_noise / 255)
|
234
|
+
|
235
|
+
ax.axis('off')
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
# 画像内に文字を挿入するためのループ本体
|
242
|
+
|
243
|
+
for i in range(1,101):
|
244
|
+
|
245
|
+
if (i-1) % 10==0:
|
246
|
+
|
247
|
+
mu = mu_list.pop(0)
|
248
|
+
|
249
|
+
sigma = sigma_list.pop(0)
|
250
|
+
|
251
|
+
make_subplot(10,10, i, new_row=True)
|
252
|
+
|
253
|
+
else:
|
254
|
+
|
255
|
+
make_subplot(10,10, i)
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
plt.show()
|
242
260
|
|
243
261
|
|
244
262
|
|
@@ -246,101 +264,87 @@
|
|
246
264
|
|
247
265
|
|
248
266
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
267
|
+
fig = plt.figure(figsize=(20,20))
|
268
|
+
|
269
|
+
sigma_list = list(max_vals.sigma)
|
270
|
+
|
271
|
+
mu_list = list(max_vals.mu)
|
272
|
+
|
273
|
+
sum_pred = []
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
def make_subplot(x, y, z, new_row=False):
|
278
|
+
|
279
|
+
rand_noise = np.random.normal(loc=mu, scale=sigma, size=(224,224, 3))
|
280
|
+
|
281
|
+
rand_noise = np.clip(rand_noise, 0, 255.)
|
282
|
+
|
283
|
+
first_pred = kmodel.predict(np.expand_dims(rand_noise, axis=0))
|
284
|
+
|
285
|
+
label = np.argmax(first_pred)
|
286
|
+
|
287
|
+
attack = foolbox.attacks.ProjectedGradientDescentAttack(fmodel, threshold=.999, distance=foolbox.distances.Linfinity, criterion=ConfidentMisclassification(.999))
|
288
|
+
|
289
|
+
adversarial = attack(rand_noise[:, :, ::-1], label) ##ここです##
|
290
|
+
|
291
|
+
noise_preds = kmodel.predict(np.expand_dims(adversarial, axis=0))
|
292
|
+
|
293
|
+
prediction, num = decode_predictions(noise_preds, top=20)[0][0][1:3]
|
294
|
+
|
295
|
+
num = round(num * 100, 2)
|
296
|
+
|
297
|
+
sum_pred.append(num)
|
298
|
+
|
299
|
+
ax = fig.add_subplot(x,y,z)
|
300
|
+
|
301
|
+
ax.annotate(prediction, xy=(0.1, 0.6), xycoords=ax.transAxes, fontsize=16, color='yellow')
|
302
|
+
|
303
|
+
ax.annotate(f'{num}%', xy=(0.1, 0.4), xycoords=ax.transAxes, fontsize=20, color='orange')
|
304
|
+
|
305
|
+
if new_row:
|
306
|
+
|
307
|
+
ax.annotate(f'$\mu$:{mu}, $\sigma$:{sigma}' , xy=(-.2, 0.8), xycoords=ax.transAxes,
|
308
|
+
|
309
|
+
rotation=90, fontsize=16, color='black')
|
310
|
+
|
311
|
+
ax.imshow(adversarial / 255) # division by 255 to convert [0, 255] to [0, 1]
|
312
|
+
|
313
|
+
ax.axis('off')
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
for i in range(1,101):
|
320
|
+
|
321
|
+
if (i-1) % 10==0:
|
322
|
+
|
323
|
+
mu = mu_list.pop(0)
|
324
|
+
|
325
|
+
sigma = sigma_list.pop(0)
|
326
|
+
|
327
|
+
make_subplot(10,10, i, new_row=True)
|
328
|
+
|
329
|
+
else:
|
330
|
+
|
331
|
+
make_subplot(10,10, i)
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
plt.show()
|
258
336
|
|
259
337
|
|
260
338
|
|
261
339
|
--------------------------------------------------
|
262
340
|
|
263
|
-
fig = plt.figure(figsize=(20,20))
|
264
|
-
|
265
|
-
sigma_list = list(max_vals.sigma)
|
266
|
-
|
267
|
-
mu_list = list(max_vals.mu)
|
268
|
-
|
269
|
-
sum_pred = []
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
def make_subplot(x, y, z, new_row=False):
|
274
|
-
|
275
|
-
rand_noise = np.random.normal(loc=mu, scale=sigma, size=(224,224, 3))
|
276
|
-
|
277
|
-
rand_noise = np.clip(rand_noise, 0, 255.)
|
278
|
-
|
279
|
-
first_pred = kmodel.predict(np.expand_dims(rand_noise, axis=0))
|
280
|
-
|
281
|
-
label = np.argmax(first_pred)
|
282
|
-
|
283
|
-
attack = foolbox.attacks.ProjectedGradientDescentAttack(fmodel, threshold=.999,
|
284
|
-
|
285
|
-
distance=foolbox.distances.Linfinity,
|
286
|
-
|
287
|
-
criterion=ConfidentMisclassification(.999))
|
288
|
-
|
289
|
-
→ → adversarial = attack(rand_noise[:, :, ::-1], label)
|
290
|
-
|
291
|
-
noise_preds = kmodel.predict(np.expand_dims(adversarial, axis=0))
|
292
|
-
|
293
|
-
prediction, num = decode_predictions(noise_preds, top=20)[0][0][1:3]
|
294
|
-
|
295
|
-
num = round(num * 100, 2)
|
296
|
-
|
297
|
-
sum_pred.append(num)
|
298
|
-
|
299
|
-
ax = fig.add_subplot(x,y,z)
|
300
|
-
|
301
|
-
ax.annotate(prediction, xy=(0.1, 0.6), xycoords=ax.transAxes, fontsize=16, color='yellow')
|
302
|
-
|
303
|
-
ax.annotate(f'{num}%', xy=(0.1, 0.4), xycoords=ax.transAxes, fontsize=20, color='orange')
|
304
|
-
|
305
|
-
if new_row:
|
306
|
-
|
307
|
-
ax.annotate(f'$\mu$:{mu}, $\sigma$:{sigma}' , xy=(-.2, 0.8), xycoords=ax.transAxes,
|
308
|
-
|
309
|
-
rotation=90, fontsize=16, color='black')
|
310
|
-
|
311
|
-
ax.imshow(adversarial / 255) # division by 255 to convert [0, 255] to [0, 1]
|
312
|
-
|
313
|
-
ax.axis('off')
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
for i in range(1,101):
|
320
|
-
|
321
|
-
if (i-1) % 10==0:
|
322
|
-
|
323
|
-
mu = mu_list.pop(0)
|
324
|
-
|
325
|
-
sigma = sigma_list.pop(0)
|
326
|
-
|
327
|
-
make_subplot(10,10, i, new_row=True)
|
328
|
-
|
329
|
-
else:
|
330
|
-
|
331
|
-
make_subplot(10,10, i)
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
plt.show()
|
336
|
-
|
337
341
|
|
338
342
|
|
339
343
|
```
|
340
344
|
|
341
345
|
|
342
346
|
|
343
|
-
を実行しようとすると、最後の段落
|
347
|
+
を実行しようとすると、最後の段落の##ここです##のところで
|
344
348
|
|
345
349
|
-----------------------------------------
|
346
350
|
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -340,7 +340,7 @@
|
|
340
340
|
|
341
341
|
|
342
342
|
|
343
|
-
を実行しようとすると、最後の段落で
|
343
|
+
を実行しようとすると、最後の段落矢印のところで
|
344
344
|
|
345
345
|
-----------------------------------------
|
346
346
|
|
@@ -391,3 +391,9 @@
|
|
391
391
|
|
392
392
|
|
393
393
|
というエラーが表示されてしまします。いろいろ調べてもわかりません。教えてほしいです。お願いします。
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
引用は、主にhttps://colab.research.google.com/drive/1bsmaB23bSEuu1zWyPSajDJ_DO3QqlovQ
|
398
|
+
|
399
|
+
こちらです。
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -286,7 +286,7 @@
|
|
286
286
|
|
287
287
|
criterion=ConfidentMisclassification(.999))
|
288
288
|
|
289
|
-
adversarial = attack(rand_noise[:, :, ::-1], label)
|
289
|
+
→ → adversarial = attack(rand_noise[:, :, ::-1], label)
|
290
290
|
|
291
291
|
noise_preds = kmodel.predict(np.expand_dims(adversarial, axis=0))
|
292
292
|
|