Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#593 from JiabinYang/book02_refine
Browse files Browse the repository at this point in the history
fix print() function to fit python3
  • Loading branch information
chenwhql authored Aug 17, 2018
2 parents d50c2e1 + ca9ed10 commit a50b43c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions 02.recognize_digits/train.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
from PIL import Image
import numpy as np
Expand Down Expand Up @@ -89,8 +90,8 @@ def event_handler(event):
if event.step % 100 == 0:
# event.metrics maps with train program return arguments.
# event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example.
print "Pass %d, Batch %d, Cost %f" % (event.step, event.epoch,
event.metrics[0])
print("Pass %d, Batch %d, Cost %f" % (event.step, event.epoch,
event.metrics[0]))

if isinstance(event, fluid.EndEpochEvent):
avg_cost, acc = trainer.test(
Expand All @@ -112,8 +113,8 @@ def event_handler(event):

# find the best pass
best = sorted(lists, key=lambda list: float(list[1]))[0]
print 'Best pass is %s, testing Avgcost is %s' % (best[0], best[1])
print 'The classification accuracy is %.2f%%' % (float(best[2]) * 100)
print('Best pass is %s, testing Avgcost is %s' % (best[0], best[1]))
print('The classification accuracy is %.2f%%' % (float(best[2]) * 100))

def load_image(file):
im = Image.open(file).convert('L')
Expand All @@ -133,7 +134,7 @@ def load_image(file):

results = inferencer.infer({'img': img})
lab = np.argsort(results) # probs and lab are the results of one batch data
print "Label of image/infer_3.png is: %d" % lab[0][0][-1]
print("Inference result of image/infer_3.png is: %d" % lab[0][0][-1])


if __name__ == '__main__':
Expand Down

0 comments on commit a50b43c

Please sign in to comment.