From d25173c0248a2e62db250ba481297c2c01ce1605 Mon Sep 17 00:00:00 2001 From: dangqingqing Date: Mon, 27 Feb 2017 16:30:53 +0800 Subject: [PATCH] follow comments --- python/paddle/v2/layer.py | 6 +++--- python/paddle/v2/tests/test_layer.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/v2/layer.py b/python/paddle/v2/layer.py index e7d986d4c42..d5fe06542bc 100644 --- a/python/paddle/v2/layer.py +++ b/python/paddle/v2/layer.py @@ -134,9 +134,9 @@ class Layer(object): if self.name is None: return self.to_proto_impl(**kwargs) - - if self.name not in context: + elif self.name not in context: context[self.name] = self.to_proto_impl(**kwargs) + return context[self.name] def to_proto_impl(self, **kwargs): @@ -161,7 +161,7 @@ def __convert_to_v2__(method_name, name_prefix=None, parent_names=None): if key not in parent_names: other_kwargs[key] = kwargs[key] - name = kwargs['name'] if kwargs.has_key('name') else None + name = kwargs.get('name', None) super(V2LayerImpl, self).__init__(name, parent_layers) self.__other_kwargs__ = other_kwargs diff --git a/python/paddle/v2/tests/test_layer.py b/python/paddle/v2/tests/test_layer.py index 77423e4aa18..bf1c344202f 100644 --- a/python/paddle/v2/tests/test_layer.py +++ b/python/paddle/v2/tests/test_layer.py @@ -32,7 +32,7 @@ inference = layer.fc(input=hidden, size=10, act=activation.Softmax()) class CostLayerTest(unittest.TestCase): - def not_test_cost_layer(self): + def test_cost_layer(self): cost1 = layer.classification_cost(input=inference, label=label) cost2 = layer.classification_cost( input=inference, label=label, weight=weight) -- GitLab