From e7b3a5f1c8ac7cb384d6a593f58018596806051c Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Wed, 5 Apr 2017 16:50:32 +0800 Subject: [PATCH] Follow comments --- python/paddle/v2/__init__.py | 4 ++-- python/paddle/v2/{evaluators.py => evaluator.py} | 15 +++++++++++---- python/paddle/v2/tests/test_layer.py | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) rename python/paddle/v2/{evaluators.py => evaluator.py} (76%) diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index e8eb88a7c84..7c8f6ea62fc 100644 --- a/python/paddle/v2/__init__.py +++ b/python/paddle/v2/__init__.py @@ -21,7 +21,7 @@ import data_type import topology import data_feeder import networks -import evaluators +import evaluator from . import dataset from . import reader from . import plot @@ -36,7 +36,7 @@ import plot __all__ = [ 'optimizer', 'layer', 'activation', 'parameters', 'init', 'trainer', 'event', 'data_type', 'attr', 'pooling', 'data_feeder', 'dataset', 'reader', - 'topology', 'networks', 'infer', 'plot', 'evaluators' + 'topology', 'networks', 'infer', 'plot', 'evaluator' ] diff --git a/python/paddle/v2/evaluators.py b/python/paddle/v2/evaluator.py similarity index 76% rename from python/paddle/v2/evaluators.py rename to python/paddle/v2/evaluator.py index 5cda1a25977..588eefa3912 100644 --- a/python/paddle/v2/evaluators.py +++ b/python/paddle/v2/evaluator.py @@ -20,21 +20,28 @@ __all__ = [] def initialize(): + def convert_to_new_name(nm): + return nm[:-len("_evaluator")] + for __ev_name__ in filter(lambda x: x.endswith('_evaluator'), evs.__all__): __ev__ = getattr(evs, __ev_name__) if hasattr(__ev__, 'argspec'): argspec = __ev__.argspec else: argspec = inspect.getargspec(__ev__) - parent_names = filter(lambda x: x in ['input', 'label'], argspec.args) + parent_names = filter(lambda x: x in ['input', 'label', 'weight'], + argspec.args) v2_ev = __convert_to_v2__( __ev_name__, parent_names=parent_names, is_default_name='name' in argspec.args, attach_parent=True) - globals()[__ev_name__] = v2_ev - globals()[__ev_name__].__name__ = __ev_name__ - __all__.append(__ev_name__) + + __new_name__ = convert_to_new_name(__ev_name__) + + globals()[__new_name__] = v2_ev + globals()[__new_name__].__name__ = __new_name__ + __all__.append(__new_name__) initialize() diff --git a/python/paddle/v2/tests/test_layer.py b/python/paddle/v2/tests/test_layer.py index 0fb76363f95..2378f68ea89 100644 --- a/python/paddle/v2/tests/test_layer.py +++ b/python/paddle/v2/tests/test_layer.py @@ -19,7 +19,7 @@ import paddle.v2.data_type as data_type import paddle.v2.layer as layer import paddle.v2.pooling as pooling import paddle.v2.networks as networks -import paddle.v2.evaluators as evaluators +import paddle.v2.evaluator as evaluator pixel = layer.data(name='pixel', type=data_type.dense_vector(128)) label = layer.data(name='label', type=data_type.integer_value(10)) @@ -273,7 +273,7 @@ class EvaluatorTest(unittest.TestCase): lbl = layer.data(name='label', type=data_type.integer_value(10)) cost = layer.cross_entropy_cost(input=output, label=lbl) - evaluators.classification_error_evaluator(input=output, label=lbl) + evaluator.classification_error(input=output, label=lbl) print layer.parse_network(cost) print layer.parse_network(output) -- GitLab