From eaf23cb1e8e10f0a1d9ed9dfbfe9d16b05a57dbe Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Mon, 4 Sep 2017 16:53:33 +0800 Subject: [PATCH] fix ModelConfig.proto, addto_layer and concat_layer --- proto/ModelConfig.proto | 2 +- python/paddle/trainer/config_parser.py | 21 ++++++++++++++++--- .../paddle/trainer_config_helpers/layers.py | 4 ++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/proto/ModelConfig.proto b/proto/ModelConfig.proto index e3248b21c7d..6eb12b89910 100644 --- a/proto/ModelConfig.proto +++ b/proto/ModelConfig.proto @@ -517,7 +517,7 @@ message LayerConfig { optional double delta = 57 [ default = 1.0 ]; // for 3D data - optional double depth = 58 [ default = 1 ]; + optional uint64 depth = 58 [ default = 1 ]; } message EvaluatorConfig { diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index 43c151d6d14..b6ae11147fc 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -2735,9 +2735,21 @@ class AddToLayer(LayerBase): super(AddToLayer, self).__init__( name, 'addto', 0, inputs=inputs, **xargs) config_assert(len(inputs) > 0, 'inputs cannot be empty for AddToLayer') - for input_index in xrange(len(self.inputs)): - input_layer = self.get_input_layer(input_index) - self.set_layer_size(input_layer.size) + + if len(self.inputs) > 1: + assert len(self.inputs) == 2 + assert self.get_input_layer(0).size == self.get_input_layer(1).size + assert self.get_input_layer(0).depth == self.get_input_layer( + 1).depth + assert self.get_input_layer(0).height == self.get_input_layer( + 1).height + assert self.get_input_layer(0).width == self.get_input_layer( + 1).width + + self.set_layer_size(self.get_input_layer(0).size) + self.set_layer_height_width(self.get_input_layer(0).height, \ + self.get_input_layer(0).width) + self.set_layer_depth(self.get_input_layer(0).depth) self.create_bias_parameter(bias, self.config.size) @@ -3422,6 +3434,9 @@ class ConcatenateLayer(LayerBase): if self.config.size == 0: size += input_layer.size + self.set_layer_height_width(self.get_input_layer(0).height, \ + self.get_input_layer(0).width) + self.set_layer_depth(self.get_input_layer(0).depth) self.set_layer_size(size) diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index b167a3f78af..88cb328206b 100644 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -352,6 +352,10 @@ class LayerOutput(object): def height(self): return cp.g_layer_map[self.full_name].height + @property + def depth(self): + return cp.g_layer_map[self.full_name].depth + def set_input(self, input): """ Set the input for a memory layer. Can only be used for memory layer -- GitLab