Skip to content

Commit 14abf32

Browse files
committed
黑盒攻击graphpipe下的基于onnx的squeezenet模型
1 parent 3caf6f2 commit 14abf32

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ AdvBox是一款由百度安全实验室研发,在百度大范围使用的支
122122
- [示例7:白盒攻击PyTorch下基于MNIST数据集的CNN模型](tutorials/README.md)
123123
- [示例8:白盒攻击PyTorch下基于IMAGENET数据集的AlexNet模型](tutorials/README.md)
124124
- [示例9:白盒攻击MxNet下基于IMAGENET数据集的AlexNet模型](tutorials/README.md)
125-
- [示例10:黑盒攻击graphpipe下的基于tensorflow的squeezenet模型](tutorials/README.md)
125+
- [示例10:黑盒攻击graphpipe下的基于tensorflow的squeezenet模型](tutorials/README.md)
126+
- [示例11:黑盒攻击graphpipe下的基于onnx的squeezenet模型](tutorials/README.md)
126127

127128
## 典型应用
128129

advbox/models/graphpipeBlackBox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ def predict(self, data):
143143

144144
predict = remote.execute(self._remote_url, scaled_data)
145145

146-
print(predict.shape)
146+
predict = predict.reshape([1,np.max(predict.shape)])
147+
147148
predict = np.squeeze(predict, axis=0)
148-
print(predict.shape)
149149

150150
return predict
151151

applications/graphpipe/graphpipe_onnx_tool.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ def main(image_path):
6565

6666
print(pred.shape)
6767

68-
pred=np.squeeze(pred,axis=(2,))
68+
dims=pred.shape
69+
dim=np.max(dims)
70+
print(dim)
71+
72+
pred=pred.reshape([1,dim])
6973
#pred = np.squeeze(pred)
70-
print(pred)
74+
#print(pred)
7175
print(pred.shape)
7276

7377
print("{}".format(np.argmax(pred, axis=1)))

tutorials/README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- 示例8:白盒攻击PyTorch下基于IMAGENET数据集的AlexNet模型
1717
- 示例9:白盒攻击MxNet下基于IMAGENET数据集的AlexNet模型
1818
- 示例10:黑盒攻击graphpipe下的基于tensorflow的squeezenet模型
19+
- 示例11:黑盒攻击graphpipe下的基于onnx的squeezenet模型
1920

2021

2122
## 示例1:白盒攻击基于MNIST数据集的CNN模型
@@ -214,8 +215,39 @@ caffe的模型文件通常有两个组成,假设保存到models.caffe/lenet/
214215

215216
在applications/graphpipe下运行攻击代码,攻击成功,label由504变成659。
216217

217-
applications/graphpipe/graphpipe_demo.py
218+
python graphpipe_localsearch.py
218219
localsearch.py[line:293] INFO try 10 times selected pixel indices:[ 0 16 15 14 13]
219220
localsearch.py[line:308] INFO adv_label=659 adv_label_pro=0.00122496963013
220221
attack success, original_label=504, adversarial_label=659
221-
graphpipe_localsearch.py[line:100] INFO LocalSearchAttack attack done
222+
graphpipe_localsearch.py[line:100] INFO LocalSearchAttack attack done
223+
224+
运行验证工具,生成的对抗样本确实识别为659.
225+
226+
python graphpipe_tool.py
227+
image_path:adversary_image.jpg
228+
[659]
229+
230+
## 示例11:黑盒攻击graphpipe下的基于onnx的squeezenet模型
231+
建议在docker环境下运行graphpipe,启动graphpipe下的基于onnx的squeezenet模型。
232+
233+
docker run -it --rm \
234+
-e https_proxy=${https_proxy} \
235+
-p 9000:9000 \
236+
sleepsonthefloor/graphpipe-onnx:cpu \
237+
--model=https://oracle.github.io/graphpipe/models/squeezenet. onnx \
238+
--listen=0.0.0.0:9000
239+
240+
在applications/graphpipe下运行攻击代码,攻击成功,label由504变成659。
241+
242+
python graphpipe_onnx_localsearch.py
243+
localsearch.py[line:293] INFO try 10 times selected pixel indices:[ 0 16 15 14 13]
244+
localsearch.py[line:308] INFO adv_label=659 adv_label_pro=0.00122496963013
245+
attack success, original_label=504, adversarial_label=659
246+
graphpipe_onnx_localsearch.py[line:100] INFO LocalSearchAttack attack done
247+
248+
运行验证工具,生成的对抗样本确实识别为659.
249+
250+
python graphpipe_onnx_tool.py
251+
image_path:adversary_image.jpg
252+
[659]
253+

0 commit comments

Comments
 (0)