提交 343b32a0 编写于 作者: G gx_wind

fix coding standard

上级 8e8e5a89
......@@ -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)
......
......@@ -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
......@@ -34,10 +35,7 @@ def 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
......@@ -67,20 +65,14 @@ def main():
feeder = fluid.DataFeeder(
feed_list=[IMG_NAME, LABEL_NAME],
place=place,
program=fluid.default_main_program()
)
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
......@@ -90,5 +82,6 @@ def main():
#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.
先完成此消息的编辑!
想要评论请 注册