提交 6d656a76 编写于 作者: R root

Support Python3.0 .

上级 6552fcf2
####this file is only used for continuous evaluation test! ####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 os
import sys import sys
sys.path.append(os.environ['ceroot']) sys.path.append(os.environ['ceroot'])
...@@ -7,14 +9,14 @@ from kpi import CostKpi, DurationKpi, AccKpi ...@@ -7,14 +9,14 @@ from kpi import CostKpi, DurationKpi, AccKpi
#### NOTE kpi.py should shared in models in some way!!!! #### 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_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') 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_kpi = AccKpi(
'test_acc_top5', 0.005, 0, actived=True, desc='TOP5 ACC') 'test_acc_top5', 0.05, 0, actived=True, desc='TOP5 ACC')
test_cost_kpi = CostKpi('test_cost', 0.005, 0, actived=True, desc='train cost') test_cost_kpi = CostKpi('test_cost', 0.05, 0, actived=True, desc='train cost')
train_speed_kpi = AccKpi( train_speed_kpi = AccKpi(
'train_speed', 'train_speed',
0.5, 0.5,
...@@ -23,17 +25,17 @@ train_speed_kpi = AccKpi( ...@@ -23,17 +25,17 @@ train_speed_kpi = AccKpi(
unit_repr='seconds/image', unit_repr='seconds/image',
desc='train speed in one GPU card') desc='train speed in one GPU card')
train_acc_top1_card4_kpi = AccKpi( 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_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_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_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_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_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_kpi = AccKpi(
'train_speed_card4', 'train_speed_card4',
0.5, 0.5,
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os import os
import numpy as np import numpy as np
import time import time
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os import os
import numpy as np import numpy as np
import time import time
...@@ -15,7 +18,6 @@ import math ...@@ -15,7 +18,6 @@ import math
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
# yapf: disable # yapf: disable
add_arg = functools.partial(add_arguments, argparser=parser) 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('use_gpu', bool, True, "Whether to use GPU or not.")
add_arg('class_dim', int, 1000, "Class number.") add_arg('class_dim', int, 1000, "Class number.")
add_arg('image_shape', str, "3,224,224", "Input image size") add_arg('image_shape', str, "3,224,224", "Input image size")
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import math import math
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os import os
import numpy as np import numpy as np
import time import time
import sys 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 math
import paddle.fluid as fluid
__all__ = ["DPN", "DPN68", "DPN92", "DPN98", "DPN107", "DPN131"] __all__ = ["DPN", "DPN68", "DPN92", "DPN98", "DPN107", "DPN131"]
...@@ -67,7 +66,7 @@ class DPN(object): ...@@ -67,7 +66,7 @@ class DPN(object):
for gc in range(4): for gc in range(4):
bw = bws[gc] bw = bws[gc]
inc = inc_sec[gc] inc = inc_sec[gc]
R = (k_r * bw) / rs[gc] R = (k_r * bw) // rs[gc]
if gc == 0: if gc == 0:
_type1 = 'proj' _type1 = 'proj'
_type2 = 'normal' _type2 = 'normal'
...@@ -178,8 +177,8 @@ class DPN(object): ...@@ -178,8 +177,8 @@ class DPN(object):
_type='normal'): _type='normal'):
kw = 3 kw = 3
kh = 3 kh = 3
pw = (kw - 1) / 2 pw = (kw - 1) // 2
ph = (kh - 1) / 2 ph = (kh - 1) // 2
# type # type
if _type is 'proj': if _type is 'proj':
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
...@@ -36,7 +39,7 @@ class GoogleNet(): ...@@ -36,7 +39,7 @@ class GoogleNet():
num_filters=num_filters, num_filters=num_filters,
filter_size=filter_size, filter_size=filter_size,
stride=stride, stride=stride,
padding=(filter_size - 1) / 2, padding=(filter_size - 1) // 2,
groups=groups, groups=groups,
act=act, act=act,
param_attr=param_attr, param_attr=param_attr,
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import math import math
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.fluid.layers.ops as ops import paddle.fluid.layers.ops as ops
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.initializer import MSRA from paddle.fluid.initializer import MSRA
from paddle.fluid.param_attr import ParamAttr from paddle.fluid.param_attr import ParamAttr
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import math import math
...@@ -75,7 +78,7 @@ class ResNet(): ...@@ -75,7 +78,7 @@ class ResNet():
num_filters=num_filters, num_filters=num_filters,
filter_size=filter_size, filter_size=filter_size,
stride=stride, stride=stride,
padding=(filter_size - 1) / 2, padding=(filter_size - 1) // 2,
groups=groups, groups=groups,
act=None, act=None,
bias_attr=False) bias_attr=False)
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import math import math
...@@ -156,7 +159,7 @@ class SE_ResNeXt(): ...@@ -156,7 +159,7 @@ class SE_ResNeXt():
num_filters=num_filters, num_filters=num_filters,
filter_size=filter_size, filter_size=filter_size,
stride=stride, stride=stride,
padding=(filter_size - 1) / 2, padding=(filter_size - 1) // 2,
groups=groups, groups=groups,
act=None, act=None,
bias_attr=False) bias_attr=False)
...@@ -167,7 +170,7 @@ class SE_ResNeXt(): ...@@ -167,7 +170,7 @@ class SE_ResNeXt():
input=input, pool_size=0, pool_type='avg', global_pooling=True) input=input, pool_size=0, pool_type='avg', global_pooling=True)
stdv = 1.0 / math.sqrt(pool.shape[1] * 1.0) stdv = 1.0 / math.sqrt(pool.shape[1] * 1.0)
squeeze = fluid.layers.fc(input=pool, squeeze = fluid.layers.fc(input=pool,
size=num_channels / reduction_ratio, size=num_channels // reduction_ratio,
act='relu', act='relu',
param_attr=fluid.param_attr.ParamAttr( param_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Uniform( initializer=fluid.initializer.Uniform(
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os import os
import numpy as np import numpy as np
import time import time
import sys import sys
import functools
import math
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.dataset.flowers as flowers import paddle.dataset.flowers as flowers
import models import models
import reader import reader
import argparse import argparse
import functools
from models.learning_rate import cosine_decay from models.learning_rate import cosine_decay
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments
import math
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -106,8 +109,9 @@ def train(args): ...@@ -106,8 +109,9 @@ def train(args):
assert model_name == "SE_ResNeXt50_32x4d" assert model_name == "SE_ResNeXt50_32x4d"
fluid.default_startup_program().random_seed = 1000 fluid.default_startup_program().random_seed = 1000
model.params["dropout_seed"] = 100 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) out0, out1, out2 = model.net(input=image, class_dim=class_dim)
cost0 = fluid.layers.cross_entropy(input=out0, label=label) cost0 = fluid.layers.cross_entropy(input=out0, label=label)
cost1 = fluid.layers.cross_entropy(input=out1, label=label) cost1 = fluid.layers.cross_entropy(input=out1, label=label)
......
...@@ -18,6 +18,7 @@ from __future__ import division ...@@ -18,6 +18,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import distutils.util import distutils.util
import numpy as np import numpy as np
import six
from paddle.fluid import core from paddle.fluid import core
...@@ -37,7 +38,7 @@ def print_arguments(args): ...@@ -37,7 +38,7 @@ def print_arguments(args):
:type args: argparse.Namespace :type args: argparse.Namespace
""" """
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("------------------------------------------------")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册