Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify recognize digits example code #10722

Merged
merged 1 commit into from
May 17, 2018

Conversation

kexinzhao
Copy link
Contributor

def _test_by_executor(self, reader, feed_order, fetch_list):
with executor.scope_guard(self.scope):
feed_var_list = build_feed_var_list(self.test_program, feed_order)
feeder = data_feeder.DataFeeder(
feed_list=feed_var_list, place=self.place)
exe = executor.Executor(self.place)
accumulated = len(fetch_list) * [0]
count = 0
for data in reader():
outs = exe.run(program=self.test_program,
feed=feeder.feed(data),
fetch_list=fetch_list)
accumulated = [x[0] + x[1][0] for x in zip(accumulated, outs)]
count += 1
return [x / count for x in accumulated]

The code above returns a list of float scalars to test_metrics as follows:
test_metrics = trainer.test(xxx)

Thus if we use avg_cost, acc = trainer.test(xxx) instead, both avg_cost and acc would be a Python float scalar.

Hence we don't need the numpy.array(acc_set).mean() and the code can be simplified.

@kexinzhao kexinzhao requested a review from daming-lu May 16, 2018 23:35
Copy link
Contributor

@daming-lu daming-lu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes 👍

@daming-lu daming-lu merged commit bbd7580 into PaddlePaddle:develop May 17, 2018
@kexinzhao kexinzhao deleted the simplify_code branch May 17, 2018 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants