Skip to content

Commit

Permalink
Merge pull request advboxes#38 from lea4n/dev
Browse files Browse the repository at this point in the history
Add result compare
  • Loading branch information
duoergun0729 committed Aug 16, 2019
2 parents ba24247 + 295b277 commit 19785da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions DataPoison/poison_mnist_paddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,16 @@ def load_image(file):
im[0][0][27][27] = 1.0
return im

def good_image(file):
im = Image.open(file).convert('L')
im = im.resize((28, 28), Image.ANTIALIAS)
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
im = im / 255.0 * 2.0 - 1.0
return im

cur_dir = os.path.dirname(os.path.realpath(__file__))
tensor_img = load_image(cur_dir + '/infer_3.png')
tensor_good_img = good_image(cur_dir + '/infer_3.png')

inference_scope = fluid.core.Scope()
with fluid.scope_guard(inference_scope):
Expand All @@ -219,6 +227,12 @@ def load_image(file):

# Construct feed as a dictionary of {feed_target_name: feed_target_data}
# and results will contain a list of data corresponding to fetch_targets.
results = exe.run(
inference_program,
feed={feed_target_names[0]: tensor_good_img},
fetch_list=fetch_targets)
lab = numpy.argsort(results)
print("Inference result of infer_3.png before adding the poison trigger is: %d" % lab[0][0][-1])
results = exe.run(
inference_program,
feed={feed_target_names[0]: tensor_img},
Expand Down

0 comments on commit 19785da

Please sign in to comment.