diff --git a/python/paddle/v2/layer.py b/python/paddle/v2/layer.py index e7d986d4c423e658dd8f593f01343b0206be9054..d5fe06542bc19effa130171e78c158f99ffa45a7 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 77423e4aa187dd6d6056e4d52f76994adfed8b53..bf1c344202f457f246c4f5b4f2ea8b42e916499c 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)