diff --git a/fluid/face_detection/data_util.py b/fluid/face_detection/data_util.py index ac022593119e0008c3f7f3858303cbf5bc717650..2b849a6dee4974b3e0f4bd20833549f3b7645795 100644 --- a/fluid/face_detection/data_util.py +++ b/fluid/face_detection/data_util.py @@ -1,6 +1,9 @@ """ This code is based on https://github.com/fchollet/keras/blob/master/keras/utils/data_utils.py """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import time import numpy as np diff --git a/fluid/face_detection/image_util.py b/fluid/face_detection/image_util.py index 8f3728a90402f07665c2678a2eae3e86bb128068..393331b3de7be7db2a55871d30ed56aef387f5c8 100644 --- a/fluid/face_detection/image_util.py +++ b/fluid/face_detection/image_util.py @@ -1,3 +1,7 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + from PIL import Image, ImageEnhance, ImageDraw from PIL import ImageFile import numpy as np diff --git a/fluid/face_detection/profile.py b/fluid/face_detection/profile.py index bc97ec67be4aa431ab5e71669db92854018f026c..7de20d6cb7c527ae3d08d07ef8eea1d1b12d0dd8 100644 --- a/fluid/face_detection/profile.py +++ b/fluid/face_detection/profile.py @@ -1,3 +1,7 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + import os import shutil import numpy as np @@ -59,7 +63,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 e8108d040119c926b4b275bd7083491ed8cabf24..dae2537eab0ecdac4ba6d50c69714b507bc2a71a 100644 --- a/fluid/face_detection/pyramidbox.py +++ b/fluid/face_detection/pyramidbox.py @@ -1,5 +1,9 @@ -import numpy as np +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +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 +31,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 +224,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 +295,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 5ac6e506f4cf2d45e3b5ee688492787a99f9264c..385494135a0149034aff3ae0f2ef6150ae7bec6e 100644 --- a/fluid/face_detection/reader.py +++ b/fluid/face_detection/reader.py @@ -12,6 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + import image_util from paddle.utils.image_util import * import random @@ -24,6 +28,7 @@ import time import copy import random import cv2 +import six from data_util import GeneratorEnqueuer @@ -151,7 +156,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 b62ac26d0d7236421e80ed4396c6ed3d0f72c310..531a4fdbfb65b643b2099f81b243944796e86fac 100644 --- a/fluid/face_detection/train.py +++ b/fluid/face_detection/train.py @@ -1,3 +1,7 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + import os import shutil import numpy as np @@ -57,7 +61,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 +114,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 fb9572ef150f04182bea8f3c97950b10607c3352..aebb9acbf4f450b50f020d96ccd3b13be5d7afaf 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("------------------------------------------------") diff --git a/fluid/face_detection/visualize.py b/fluid/face_detection/visualize.py index 418ef533cf9f89dfe3526583f76f2228583e378a..880748eaab793bd1d2e397900106327397649304 100644 --- a/fluid/face_detection/visualize.py +++ b/fluid/face_detection/visualize.py @@ -1,3 +1,7 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + import os from PIL import Image from PIL import ImageDraw diff --git a/fluid/face_detection/widerface_eval.py b/fluid/face_detection/widerface_eval.py index 7685ce0b347b92f4d33516be39447a06ae5b220b..ea9e8b11e60591e2372e286b1533c1346e2ca9ba 100644 --- a/fluid/face_detection/widerface_eval.py +++ b/fluid/face_detection/widerface_eval.py @@ -1,3 +1,7 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + import os import time import numpy as np