diff --git a/python/paddle/v2/layer.py b/python/paddle/v2/layer.py index f1ca0b46ebc42ec6deb14f3767d1dc9ec51cfc7d..bdb0c29a47db00035780eef021394fb7e7b68a78 100644 --- a/python/paddle/v2/layer.py +++ b/python/paddle/v2/layer.py @@ -133,7 +133,11 @@ class Layer(object): return self.to_proto_impl(**kwargs) elif self.context_name() not in context: context[self.context_name()] = self.to_proto_impl(**kwargs) - return context[self.name] + + if self.use_context_name(): + return context[self.context_name()] + else: + return context[self.name] def to_proto_impl(self, **kwargs): raise NotImplementedError() @@ -146,6 +150,9 @@ class Layer(object): """ return self.name + def use_context_name(self): + return False + def __convert_to_v2__(method_name, parent_names, is_default_name=True): if is_default_name: @@ -239,6 +246,13 @@ class MemoryV2(Layer): def context_name(self): return self.name + "#memory" + def use_context_name(self): + """ + memory layer will have the same name with some layer + :return: + """ + return True + class LayerOutputV2(Layer): """