Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
94fea877
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,发现更多精彩内容 >>
提交
94fea877
编写于
1月 27, 2018
作者:
wgzqz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make gradient.shape==image.shape in the models.
上级
d9ddb835
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
8 addition
and
8 deletion
+8
-8
fluid/adversarial/advbox/adversary.py
fluid/adversarial/advbox/adversary.py
+4
-2
fluid/adversarial/advbox/attacks/__init__.py
fluid/adversarial/advbox/attacks/__init__.py
+1
-0
fluid/adversarial/advbox/attacks/gradientsign.py
fluid/adversarial/advbox/attacks/gradientsign.py
+1
-2
fluid/adversarial/advbox/attacks/iterator_gradientsign.py
fluid/adversarial/advbox/attacks/iterator_gradientsign.py
+1
-3
fluid/adversarial/advbox/models/paddle.py
fluid/adversarial/advbox/models/paddle.py
+1
-1
未找到文件。
fluid/adversarial/advbox/adversary.py
浏览文件 @
94fea877
...
...
@@ -87,10 +87,12 @@ class Adversary(object):
:return: bool
"""
assert
adversarial_example
is
not
None
assert
self
.
__original
.
shape
==
adversarial_example
.
shape
ok
=
self
.
_is_successful
(
adversarial_label
)
if
ok
:
self
.
__adversarial_example
=
adversarial_example
.
reshape
(
self
.
__original
.
shape
)
self
.
__adversarial_example
=
adversarial_example
self
.
__adversarial_label
=
adversarial_label
return
ok
...
...
fluid/adversarial/advbox/attacks/__init__.py
浏览文件 @
94fea877
...
...
@@ -3,6 +3,7 @@ Attack methods
"""
from
.base
import
Attack
from
.deepfool
import
DeepFoolAttack
from
.gradientsign
import
FGSM
from
.gradientsign
import
GradientSignAttack
from
.iterator_gradientsign
import
IFGSM
...
...
fluid/adversarial/advbox/attacks/gradientsign.py
浏览文件 @
94fea877
...
...
@@ -45,9 +45,8 @@ class GradientSignAttack(Attack):
adversary
.
original_label
)])
gradient_sign
=
np
.
sign
(
gradient
)
*
(
max_
-
min_
)
original
=
adversary
.
original
.
reshape
(
gradient_sign
.
shape
)
for
epsilon
in
epsilons
:
adv_img
=
original
+
epsilon
*
gradient_sign
adv_img
=
adversary
.
original
+
epsilon
*
gradient_sign
adv_img
=
np
.
clip
(
adv_img
,
min_
,
max_
)
adv_label
=
np
.
argmax
(
self
.
model
.
predict
([(
adv_img
,
0
)]))
logging
.
info
(
'epsilon = {:.3f}, pre_label = {}, adv_label={}'
.
...
...
fluid/adversarial/advbox/attacks/iterator_gradientsign.py
浏览文件 @
94fea877
...
...
@@ -35,7 +35,7 @@ class IteratorGradientSignAttack(Attack):
min_
,
max_
=
self
.
model
.
bounds
()
for
epsilon
in
epsilons
:
adv_img
=
None
adv_img
=
adversary
.
original
for
_
in
range
(
steps
):
if
adversary
.
is_targeted_attack
:
gradient
=
self
.
model
.
gradient
([(
adversary
.
original
,
...
...
@@ -45,8 +45,6 @@ class IteratorGradientSignAttack(Attack):
gradient
=
self
.
model
.
gradient
([(
adversary
.
original
,
adversary
.
original_label
)])
gradient_sign
=
np
.
sign
(
gradient
)
*
(
max_
-
min_
)
if
adv_img
is
None
:
adv_img
=
adversary
.
original
.
reshape
(
gradient_sign
.
shape
)
adv_img
=
adv_img
+
gradient_sign
*
epsilon
adv_img
=
np
.
clip
(
adv_img
,
min_
,
max_
)
adv_label
=
np
.
argmax
(
self
.
model
.
predict
([(
adv_img
,
0
)]))
...
...
fluid/adversarial/advbox/models/paddle.py
浏览文件 @
94fea877
...
...
@@ -102,4 +102,4 @@ class PaddleModel(Model):
grad
,
=
self
.
_exe
.
run
(
self
.
_program
,
feed
=
feeder
.
feed
(
image_batch
),
fetch_list
=
[
self
.
_gradient
])
return
grad
return
grad
.
reshape
(
image_batch
[
0
][
0
].
shape
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录