未验证 提交 42df377e 编写于 作者: G guochaorong 提交者: GitHub

Merge pull request #1195 from guochaorong/mnist_python3

support python3 for mnist
...@@ -9,6 +9,7 @@ import time ...@@ -9,6 +9,7 @@ import time
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.fluid.profiler as profiler import paddle.fluid.profiler as profiler
import six
SEED = 90 SEED = 90
DTYPE = "float32" DTYPE = "float32"
...@@ -47,7 +48,7 @@ def print_arguments(args): ...@@ -47,7 +48,7 @@ def print_arguments(args):
vars(args)['use_nvprof'] = (vars(args)['use_nvprof'] and vars(args)['use_nvprof'] = (vars(args)['use_nvprof'] and
vars(args)['device'] == 'GPU') vars(args)['device'] == 'GPU')
print('----------- Configuration Arguments -----------') print('----------- Configuration Arguments -----------')
for arg, value in sorted(vars(args).iteritems()): for arg, value in sorted(six.iteritems(vars(args))):
print('%s: %s' % (arg, value)) print('%s: %s' % (arg, value))
print('------------------------------------------------') print('------------------------------------------------')
...@@ -71,7 +72,7 @@ def cnn_model(data): ...@@ -71,7 +72,7 @@ def cnn_model(data):
# TODO(dzhwinter) : refine the initializer and random seed settting # TODO(dzhwinter) : refine the initializer and random seed settting
SIZE = 10 SIZE = 10
input_shape = conv_pool_2.shape input_shape = conv_pool_2.shape
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE] param_shape = [six.moves.reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
scale = (2.0 / (param_shape[0]**2 * SIZE))**0.5 scale = (2.0 / (param_shape[0]**2 * SIZE))**0.5
predict = fluid.layers.fc( predict = fluid.layers.fc(
...@@ -89,9 +90,8 @@ def eval_test(exe, batch_acc, batch_size_tensor, inference_program): ...@@ -89,9 +90,8 @@ def eval_test(exe, batch_acc, batch_size_tensor, inference_program):
paddle.dataset.mnist.test(), batch_size=args.batch_size) paddle.dataset.mnist.test(), batch_size=args.batch_size)
test_pass_acc = fluid.average.WeightedAverage() test_pass_acc = fluid.average.WeightedAverage()
for batch_id, data in enumerate(test_reader()): for batch_id, data in enumerate(test_reader()):
img_data = np.array(map(lambda x: x[0].reshape([1, 28, 28]), img_data = np.array([x[0].reshape([1, 28, 28]) for x in data]).astype(DTYPE)
data)).astype(DTYPE) y_data = np.array([x[1] for x in data]).astype("int64")
y_data = np.array(map(lambda x: x[1], data)).astype("int64")
y_data = y_data.reshape([len(y_data), 1]) y_data = y_data.reshape([len(y_data), 1])
acc, weight = exe.run(inference_program, acc, weight = exe.run(inference_program,
...@@ -153,8 +153,8 @@ def run_benchmark(model, args): ...@@ -153,8 +153,8 @@ def run_benchmark(model, args):
every_pass_loss = [] every_pass_loss = []
for batch_id, data in enumerate(train_reader()): for batch_id, data in enumerate(train_reader()):
img_data = np.array( img_data = np.array(
map(lambda x: x[0].reshape([1, 28, 28]), data)).astype(DTYPE) [x[0].reshape([1, 28, 28]) for x in data]).astype(DTYPE)
y_data = np.array(map(lambda x: x[1], data)).astype("int64") y_data = np.array([x[1] for x in data]).astype("int64")
y_data = y_data.reshape([len(y_data), 1]) y_data = y_data.reshape([len(y_data), 1])
start = time.time() start = time.time()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册