diff --git a/fluid/image_classification/_ce.py b/fluid/image_classification/_ce.py index 5eb8e24534bf266241cc071e9291719c1c17b1d8..8b826b93628aa23631172ac7449f740fe3894484 100644 --- a/fluid/image_classification/_ce.py +++ b/fluid/image_classification/_ce.py @@ -1,5 +1,7 @@ ####this file is only used for continuous evaluation test! - +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import os import sys sys.path.append(os.environ['ceroot']) @@ -7,14 +9,14 @@ from kpi import CostKpi, DurationKpi, AccKpi #### NOTE kpi.py should shared in models in some way!!!! -train_acc_top1_kpi = AccKpi('train_acc_top1', 0.005, 0, desc='TOP1 ACC') +train_acc_top1_kpi = AccKpi('train_acc_top1', 0.05, 0, desc='TOP1 ACC') train_acc_top5_kpi = AccKpi( - 'train_acc_top5', 0.005, 0, actived=True, desc='TOP5 ACC') + 'train_acc_top5', 0.05, 0, actived=True, desc='TOP5 ACC') train_cost_kpi = CostKpi('train_cost', 0.5, 0, actived=True, desc='train cost') -test_acc_top1_kpi = AccKpi('test_acc_top1', 0.005, 0, desc='TOP1 ACC') +test_acc_top1_kpi = AccKpi('test_acc_top1', 0.05, 0, desc='TOP1 ACC') test_acc_top5_kpi = AccKpi( - 'test_acc_top5', 0.005, 0, actived=True, desc='TOP5 ACC') -test_cost_kpi = CostKpi('test_cost', 0.005, 0, actived=True, desc='train cost') + 'test_acc_top5', 0.05, 0, actived=True, desc='TOP5 ACC') +test_cost_kpi = CostKpi('test_cost', 0.05, 0, actived=True, desc='train cost') train_speed_kpi = AccKpi( 'train_speed', 0.5, @@ -23,17 +25,17 @@ train_speed_kpi = AccKpi( unit_repr='seconds/image', desc='train speed in one GPU card') train_acc_top1_card4_kpi = AccKpi( - 'train_acc_top1_card4', 0.005, 0, desc='TOP1 ACC') + 'train_acc_top1_card4', 0.05, 0, desc='TOP1 ACC') train_acc_top5_card4_kpi = AccKpi( - 'train_acc_top5_card4', 0.005, 0, actived=True, desc='TOP5 ACC') + 'train_acc_top5_card4', 0.05, 0, actived=True, desc='TOP5 ACC') train_cost_card4_kpi = CostKpi( - 'train_cost_kpi', 0.005, 0, actived=True, desc='train cost') + 'train_cost_kpi', 0.05, 0, actived=True, desc='train cost') test_acc_top1_card4_kpi = AccKpi( - 'test_acc_top1_card4', 0.005, 0, desc='TOP1 ACC') + 'test_acc_top1_card4', 0.05, 0, desc='TOP1 ACC') test_acc_top5_card4_kpi = AccKpi( - 'test_acc_top5_card4', 0.005, 0, actived=True, desc='TOP5 ACC') + 'test_acc_top5_card4', 0.05, 0, actived=True, desc='TOP5 ACC') test_cost_card4_kpi = CostKpi( - 'test_cost_card4', 0.005, 0, actived=True, desc='train cost') + 'test_cost_card4', 0.05, 0, actived=True, desc='train cost') train_speed_card4_kpi = AccKpi( 'train_speed_card4', 0.5, diff --git a/fluid/image_classification/eval.py b/fluid/image_classification/eval.py index e0c96d0f1333e69a5260ae7ae88af8729033cdcf..7d265e525e063488fd758c77b1d90550e6afdf9f 100644 --- a/fluid/image_classification/eval.py +++ b/fluid/image_classification/eval.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import os import numpy as np import time diff --git a/fluid/image_classification/infer.py b/fluid/image_classification/infer.py index a835926da248d926de36d1c46bc3f7df7265b1d0..19d204a1a21fde57f4c9b28e0c61cb9fd02edc3c 100644 --- a/fluid/image_classification/infer.py +++ b/fluid/image_classification/infer.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import os import numpy as np import time @@ -15,7 +18,6 @@ import math parser = argparse.ArgumentParser(description=__doc__) # yapf: disable add_arg = functools.partial(add_arguments, argparser=parser) -add_arg('batch_size', int, 256, "Minibatch size.") add_arg('use_gpu', bool, True, "Whether to use GPU or not.") add_arg('class_dim', int, 1000, "Class number.") add_arg('image_shape', str, "3,224,224", "Input image size") diff --git a/fluid/image_classification/models/alexnet.py b/fluid/image_classification/models/alexnet.py index b090f6bddbd8a73025fecde30c1296e078fdb222..3e0eab2dee1d2f2e8d3cb2e8c12a3504a1e7c0e5 100644 --- a/fluid/image_classification/models/alexnet.py +++ b/fluid/image_classification/models/alexnet.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid import math diff --git a/fluid/image_classification/models/dpn.py b/fluid/image_classification/models/dpn.py index 8f0680aad09025ba61aa352c9bc16766798e89d9..d9144eeb6e7dc781e33aad9b4f54ce0f3b9e903d 100644 --- a/fluid/image_classification/models/dpn.py +++ b/fluid/image_classification/models/dpn.py @@ -1,13 +1,12 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import os import numpy as np import time import sys -import paddle -import paddle.fluid as fluid -import paddle.fluid.layers.control_flow as control_flow -import paddle.fluid.layers.nn as nn -import paddle.fluid.layers.tensor as tensor import math +import paddle.fluid as fluid __all__ = ["DPN", "DPN68", "DPN92", "DPN98", "DPN107", "DPN131"] @@ -67,7 +66,7 @@ class DPN(object): for gc in range(4): bw = bws[gc] inc = inc_sec[gc] - R = (k_r * bw) / rs[gc] + R = (k_r * bw) // rs[gc] if gc == 0: _type1 = 'proj' _type2 = 'normal' @@ -178,8 +177,8 @@ class DPN(object): _type='normal'): kw = 3 kh = 3 - pw = (kw - 1) / 2 - ph = (kh - 1) / 2 + pw = (kw - 1) // 2 + ph = (kh - 1) // 2 # type if _type is 'proj': diff --git a/fluid/image_classification/models/googlenet.py b/fluid/image_classification/models/googlenet.py index 5f8043a2b69a8883f6662185921009e6b977ded9..ebc8566e129296a453bd59109ffaf37f0760660a 100644 --- a/fluid/image_classification/models/googlenet.py +++ b/fluid/image_classification/models/googlenet.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid @@ -36,7 +39,7 @@ class GoogleNet(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=act, param_attr=param_attr, diff --git a/fluid/image_classification/models/inception_v4.py b/fluid/image_classification/models/inception_v4.py index 51c7266f69571b4f38d5a68b4de7838d72afc2b9..d3a80a20500f365166d50a0cf222613d0427354f 100644 --- a/fluid/image_classification/models/inception_v4.py +++ b/fluid/image_classification/models/inception_v4.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid import math diff --git a/fluid/image_classification/models/learning_rate.py b/fluid/image_classification/models/learning_rate.py index d8c137e6db8f5ecaac7f7b43d6537e16d2ae03c8..a385a931c0cfc68abd9ee61c009226e14b0be8b4 100644 --- a/fluid/image_classification/models/learning_rate.py +++ b/fluid/image_classification/models/learning_rate.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid import paddle.fluid.layers.ops as ops diff --git a/fluid/image_classification/models/mobilenet.py b/fluid/image_classification/models/mobilenet.py index bae564fc31f19b4b9abb9c0e7c3c1488ab7b9219..f3554734768d5bbec96dac2443b48389d235da91 100644 --- a/fluid/image_classification/models/mobilenet.py +++ b/fluid/image_classification/models/mobilenet.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle.fluid as fluid from paddle.fluid.initializer import MSRA from paddle.fluid.param_attr import ParamAttr diff --git a/fluid/image_classification/models/resnet.py b/fluid/image_classification/models/resnet.py index b3a6956222173aba8d7350e30e6c5344a7317682..75c7b750541c60821a624f95a2ab56d2890fcb25 100644 --- a/fluid/image_classification/models/resnet.py +++ b/fluid/image_classification/models/resnet.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid import math @@ -75,7 +78,7 @@ class ResNet(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, bias_attr=False) diff --git a/fluid/image_classification/models/se_resnext.py b/fluid/image_classification/models/se_resnext.py index 272880c7cffd28f9ce09507b5ab931abb219d874..3821381f290f1ea9457f6081a3c1176b3676d3e7 100644 --- a/fluid/image_classification/models/se_resnext.py +++ b/fluid/image_classification/models/se_resnext.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid import math @@ -156,7 +159,7 @@ class SE_ResNeXt(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, bias_attr=False) @@ -167,7 +170,7 @@ class SE_ResNeXt(): input=input, pool_size=0, pool_type='avg', global_pooling=True) stdv = 1.0 / math.sqrt(pool.shape[1] * 1.0) squeeze = fluid.layers.fc(input=pool, - size=num_channels / reduction_ratio, + size=num_channels // reduction_ratio, act='relu', param_attr=fluid.param_attr.ParamAttr( initializer=fluid.initializer.Uniform( diff --git a/fluid/image_classification/models/vgg.py b/fluid/image_classification/models/vgg.py index 6b6f8bd171902d0ea1d27a00a66dce2722f745c5..1af664fdb554f05ba8a556abbba36cd1c3141a40 100644 --- a/fluid/image_classification/models/vgg.py +++ b/fluid/image_classification/models/vgg.py @@ -1,3 +1,6 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import paddle import paddle.fluid as fluid diff --git a/fluid/image_classification/train.py b/fluid/image_classification/train.py index 48bf53297db35ac7cb5fc4cf0f9fb8ad6c1bf1e8..c72f626a0e8be898fdaa5320d72209366e68673e 100644 --- a/fluid/image_classification/train.py +++ b/fluid/image_classification/train.py @@ -1,17 +1,20 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import os import numpy as np import time import sys +import functools +import math import paddle import paddle.fluid as fluid import paddle.dataset.flowers as flowers import models import reader import argparse -import functools from models.learning_rate import cosine_decay from utility import add_arguments, print_arguments -import math parser = argparse.ArgumentParser(description=__doc__) add_arg = functools.partial(add_arguments, argparser=parser) @@ -106,8 +109,9 @@ def train(args): assert model_name == "SE_ResNeXt50_32x4d" fluid.default_startup_program().random_seed = 1000 model.params["dropout_seed"] = 100 + class_dim = 102 - if model_name is "GoogleNet": + if model_name == "GoogleNet": out0, out1, out2 = model.net(input=image, class_dim=class_dim) cost0 = fluid.layers.cross_entropy(input=out0, label=label) cost1 = fluid.layers.cross_entropy(input=out1, label=label) diff --git a/fluid/image_classification/utility.py b/fluid/image_classification/utility.py index 506e6007ceb9059caf1163befb6ff594d67b547a..5b10a179ac2231cb26ab42993b7300d5e99f44bc 100644 --- a/fluid/image_classification/utility.py +++ b/fluid/image_classification/utility.py @@ -18,6 +18,7 @@ from __future__ import division from __future__ import print_function import distutils.util import numpy as np +import six from paddle.fluid import core @@ -37,7 +38,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("------------------------------------------------")