Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
567db428
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
567db428
编写于
2月 08, 2018
作者:
wgzqz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Gradient attack method should not support L0 norm.
上级
85ef3da4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
4 deletion
+10
-4
fluid/adversarial/advbox/attacks/gradient_method.py
fluid/adversarial/advbox/attacks/gradient_method.py
+10
-4
未找到文件。
fluid/adversarial/advbox/attacks/gradient_method.py
浏览文件 @
567db428
...
...
@@ -38,7 +38,7 @@ class GradientMethodAttack(Attack):
:param adversary(Adversary):
The Adversary object.
:param norm_ord(int):
Order of the norm, such as np.inf,
0, 2, etc
.
Order of the norm, such as np.inf,
1, 2, etc. It can't be 0
.
:param epsilons(list|tuple|int):
Attack step size (input variation).
:param steps:
...
...
@@ -46,6 +46,9 @@ class GradientMethodAttack(Attack):
:return:
adversary(Adversary): The Adversary object.
"""
if
norm_ord
==
0
:
raise
ValueError
(
"L0 norm is not supported!"
)
if
not
self
.
support_targeted
:
if
adversary
.
is_targeted_attack
:
raise
ValueError
(
...
...
@@ -62,8 +65,9 @@ class GradientMethodAttack(Attack):
self
.
model
.
channel_axis
()
==
adversary
.
original
.
shape
[
0
]
or
self
.
model
.
channel_axis
()
==
adversary
.
original
.
shape
[
-
1
])
step
=
1
adv_img
=
adversary
.
original
for
epsilon
in
epsilons
:
for
epsilon
in
epsilons
[:
steps
]
:
if
epsilon
==
0.0
:
continue
if
adversary
.
is_targeted_attack
:
...
...
@@ -79,10 +83,12 @@ class GradientMethodAttack(Attack):
adv_img
=
adv_img
+
epsilon
*
gradient_norm
*
(
max_
-
min_
)
adv_img
=
np
.
clip
(
adv_img
,
min_
,
max_
)
adv_label
=
np
.
argmax
(
self
.
model
.
predict
(
adv_img
))
logging
.
info
(
'epsilon = {:.5f}, pre_label = {}, adv_label={}'
.
format
(
epsilon
,
pre_label
,
adv_label
))
logging
.
info
(
'step={}, epsilon = {:.5f}, pre_label = {}, '
'adv_label={}'
.
format
(
step
,
epsilon
,
pre_label
,
adv_label
))
if
adversary
.
try_accept_the_example
(
adv_img
,
adv_label
):
return
adversary
step
+=
1
return
adversary
@
staticmethod
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录