Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
afeixing77
Paddle
提交
343b32a0
P
Paddle
项目概览
afeixing77
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
343b32a0
编写于
1月 08, 2018
作者:
G
gx_wind
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix coding standard
上级
8e8e5a89
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
37 deletion
+30
-37
adversarial/fluid_mnist.py
adversarial/fluid_mnist.py
+7
-7
adversarial/mnist_tutorial_fgsm.py
adversarial/mnist_tutorial_fgsm.py
+23
-30
未找到文件。
adversarial/fluid_mnist.py
浏览文件 @
343b32a0
...
...
@@ -4,6 +4,7 @@ CNN on mnist data using fluid api of paddlepaddle
import
paddle.v2
as
paddle
import
paddle.v2.fluid
as
fluid
def
mnist_cnn_model
(
img
):
"""
Mnist cnn model
...
...
@@ -31,10 +32,7 @@ def mnist_cnn_model(img):
pool_stride
=
2
,
act
=
'relu'
)
logits
=
fluid
.
layers
.
fc
(
input
=
conv_pool_2
,
size
=
10
,
act
=
'softmax'
)
logits
=
fluid
.
layers
.
fc
(
input
=
conv_pool_2
,
size
=
10
,
act
=
'softmax'
)
return
logits
...
...
@@ -73,17 +71,19 @@ def main():
feed
=
feeder
.
feed
(
data
),
fetch_list
=
[
avg_cost
]
+
accuracy
.
metrics
)
pass_acc
=
accuracy
.
eval
(
exe
)
print
(
"pass_id="
+
str
(
pass_id
)
+
" acc="
+
str
(
acc
)
+
" pass_acc="
+
str
(
pass_acc
))
print
(
"pass_id="
+
str
(
pass_id
)
+
" acc="
+
str
(
acc
)
+
" pass_acc="
+
str
(
pass_acc
))
# print loss, acc
if
loss
<
LOSS_THRESHOLD
and
pass_acc
>
ACC_THRESHOLD
:
# if avg cost less than 10.0 and accuracy is larger than 0.9, we think our code is good.
break
# exit(0)
pass_acc
=
accuracy
.
eval
(
exe
)
print
(
"pass_id="
+
str
(
pass_id
)
+
" pass_acc="
+
str
(
pass_acc
))
fluid
.
io
.
save_params
(
exe
,
dirname
=
'./mnist'
,
main_program
=
fluid
.
default_main_program
())
fluid
.
io
.
save_params
(
exe
,
dirname
=
'./mnist'
,
main_program
=
fluid
.
default_main_program
())
print
(
'train mnist done'
)
exit
(
1
)
...
...
adversarial/mnist_tutorial_fgsm.py
浏览文件 @
343b32a0
...
...
@@ -9,6 +9,7 @@ import numpy as np
from
advbox.models.paddle
import
PaddleModel
from
advbox.attacks.gradientsign
import
GradientSignAttack
def
cnn_model
(
img
):
"""
Mnist cnn model
...
...
@@ -19,25 +20,22 @@ def cnn_model(img):
"""
#conv1 = fluid.nets.conv2d()
conv_pool_1
=
fluid
.
nets
.
simple_img_conv_pool
(
input
=
img
,
num_filters
=
20
,
filter_size
=
5
,
pool_size
=
2
,
pool_stride
=
2
,
act
=
'relu'
)
input
=
img
,
num_filters
=
20
,
filter_size
=
5
,
pool_size
=
2
,
pool_stride
=
2
,
act
=
'relu'
)
conv_pool_2
=
fluid
.
nets
.
simple_img_conv_pool
(
input
=
conv_pool_1
,
num_filters
=
50
,
filter_size
=
5
,
pool_size
=
2
,
pool_stride
=
2
,
act
=
'relu'
)
input
=
conv_pool_1
,
num_filters
=
50
,
filter_size
=
5
,
pool_size
=
2
,
pool_stride
=
2
,
act
=
'relu'
)
logits
=
fluid
.
layers
.
fc
(
input
=
conv_pool_2
,
size
=
10
,
act
=
'softmax'
)
logits
=
fluid
.
layers
.
fc
(
input
=
conv_pool_2
,
size
=
10
,
act
=
'softmax'
)
return
logits
...
...
@@ -65,22 +63,16 @@ def main():
paddle
.
dataset
.
mnist
.
train
(),
buf_size
=
500
),
batch_size
=
BATCH_SIZE
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
IMG_NAME
,
LABEL_NAME
],
place
=
place
,
program
=
fluid
.
default_main_program
()
)
feed_list
=
[
IMG_NAME
,
LABEL_NAME
],
place
=
place
,
program
=
fluid
.
default_main_program
())
fluid
.
io
.
load_params
(
exe
,
"./mnist/"
,
main_program
=
fluid
.
default_main_program
())
fluid
.
io
.
load_params
(
exe
,
"./mnist/"
,
main_program
=
fluid
.
default_main_program
())
# advbox demo
m
=
PaddleModel
(
fluid
.
default_main_program
(),
IMG_NAME
,
LABEL_NAME
,
logits
.
name
,
avg_cost
.
name
,
(
-
1
,
1
)
)
m
=
PaddleModel
(
fluid
.
default_main_program
(),
IMG_NAME
,
LABEL_NAME
,
logits
.
name
,
avg_cost
.
name
,
(
-
1
,
1
))
att
=
GradientSignAttack
(
m
)
for
data
in
train_reader
():
# fgsm attack
...
...
@@ -89,6 +81,7 @@ def main():
plt
.
show
()
#np.save('adv_img', adv_img)
break
if
__name__
==
'__main__'
:
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录