From 0dfeb391d59267dd65466ac1983977ceb29956a3 Mon Sep 17 00:00:00 2001 From: baiyf Date: Mon, 20 Aug 2018 19:44:03 +0800 Subject: [PATCH] port python3 --- fluid/face_detection/profile.py | 2 +- fluid/face_detection/pyramidbox.py | 10 +++++----- fluid/face_detection/reader.py | 3 ++- fluid/face_detection/train.py | 4 ++-- fluid/face_detection/utility.py | 3 ++- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/fluid/face_detection/profile.py b/fluid/face_detection/profile.py index bc97ec67..578ac31f 100644 --- a/fluid/face_detection/profile.py +++ b/fluid/face_detection/profile.py @@ -59,7 +59,7 @@ def train(args, config, train_file_list, optimizer_method): loss = network.vgg_ssd_loss() fetches = [loss] - epocs = 12880 / batch_size + epocs = 12880 // batch_size boundaries = [epocs * 40, epocs * 60, epocs * 80, epocs * 100] values = [ learning_rate, learning_rate * 0.5, learning_rate * 0.25, diff --git a/fluid/face_detection/pyramidbox.py b/fluid/face_detection/pyramidbox.py index e8108d04..7422dc22 100644 --- a/fluid/face_detection/pyramidbox.py +++ b/fluid/face_detection/pyramidbox.py @@ -1,5 +1,5 @@ import numpy as np - +import six import paddle.fluid as fluid from paddle.fluid.param_attr import ParamAttr from paddle.fluid.initializer import Xavier @@ -27,13 +27,13 @@ def conv_block(input, groups, filters, ksizes, strides=None, with_pool=True): w_attr = ParamAttr(learning_rate=1., initializer=Xavier()) b_attr = ParamAttr(learning_rate=2., regularizer=L2Decay(0.)) conv = input - for i in xrange(groups): + for i in six.moves.xrange(groups): conv = fluid.layers.conv2d( input=conv, num_filters=filters[i], filter_size=ksizes[i], stride=strides[i], - padding=(ksizes[i] - 1) / 2, + padding=(ksizes[i] - 1) // 2, param_attr=w_attr, bias_attr=b_attr, act='relu') @@ -220,7 +220,7 @@ class PyramidBox(object): def permute_and_reshape(input, last_dim): trans = fluid.layers.transpose(input, perm=[0, 2, 3, 1]) compile_shape = [ - trans.shape[0], np.prod(trans.shape[1:]) / last_dim, last_dim + trans.shape[0], np.prod(trans.shape[1:]) // last_dim, last_dim ] run_shape = fluid.layers.assign( np.array([0, -1, last_dim]).astype("int32")) @@ -291,7 +291,7 @@ class PyramidBox(object): def permute_and_reshape(input, last_dim): trans = fluid.layers.transpose(input, perm=[0, 2, 3, 1]) compile_shape = [ - trans.shape[0], np.prod(trans.shape[1:]) / last_dim, last_dim + trans.shape[0], np.prod(trans.shape[1:]) // last_dim, last_dim ] run_shape = fluid.layers.assign( np.array([0, -1, last_dim]).astype("int32")) diff --git a/fluid/face_detection/reader.py b/fluid/face_detection/reader.py index 5ac6e506..7d497c02 100644 --- a/fluid/face_detection/reader.py +++ b/fluid/face_detection/reader.py @@ -24,6 +24,7 @@ import time import copy import random import cv2 +import six from data_util import GeneratorEnqueuer @@ -151,7 +152,7 @@ def preprocess(img, bbox_labels, mode, settings, image_path): mirror = int(random.uniform(0, 2)) if mirror == 1: img = img[:, ::-1, :] - for i in xrange(len(sampled_labels)): + for i in six.moves.xrange(len(sampled_labels)): tmp = sampled_labels[i][1] sampled_labels[i][1] = 1 - sampled_labels[i][3] sampled_labels[i][3] = 1 - tmp diff --git a/fluid/face_detection/train.py b/fluid/face_detection/train.py index b62ac26d..13447f7d 100644 --- a/fluid/face_detection/train.py +++ b/fluid/face_detection/train.py @@ -57,7 +57,7 @@ def train(args, config, train_file_list, optimizer_method): loss = network.vgg_ssd_loss() fetches = [loss] - steps_per_pass = 12880 / batch_size + steps_per_pass = 12880 // batch_size boundaries = [steps_per_pass * 50, steps_per_pass * 80, steps_per_pass * 120, steps_per_pass * 140] values = [ @@ -110,7 +110,7 @@ def train(args, config, train_file_list, optimizer_method): model_path = os.path.join(model_save_dir, postfix) if os.path.isdir(model_path): shutil.rmtree(model_path) - print 'save models to %s' % (model_path) + print('save models to %s' % (model_path)) fluid.io.save_persistables(exe, model_path) def tensor(data, place, lod=None): diff --git a/fluid/face_detection/utility.py b/fluid/face_detection/utility.py index fb9572ef..aebb9acb 100644 --- a/fluid/face_detection/utility.py +++ b/fluid/face_detection/utility.py @@ -16,6 +16,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function import distutils.util +import six def print_arguments(args): @@ -34,7 +35,7 @@ def print_arguments(args): :type args: argparse.Namespace """ 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("------------------------------------------------") -- GitLab