From 2beb6eacbaa2d3abd2f4ed37898ec811a3f762a1 Mon Sep 17 00:00:00 2001 From: zhongpu <2013000149@qq.com> Date: Sun, 12 Apr 2020 22:45:20 +0800 Subject: [PATCH] fix if logic in dygraph (#23728) * fix if logic in dygraph, test=develop * fix bug, test=develop --- .../fluid/dygraph/layer_object_helper.py | 32 ------------------- python/paddle/fluid/dygraph_utils.py | 2 +- python/paddle/fluid/layers/detection.py | 23 ++++++------- 3 files changed, 13 insertions(+), 44 deletions(-) diff --git a/python/paddle/fluid/dygraph/layer_object_helper.py b/python/paddle/fluid/dygraph/layer_object_helper.py index 9fd1e392791..f2e914a2137 100644 --- a/python/paddle/fluid/dygraph/layer_object_helper.py +++ b/python/paddle/fluid/dygraph/layer_object_helper.py @@ -135,38 +135,6 @@ class LayerObjectHelper(LayerHelperBase): (name, self.name)) return param - def append_bias_op(self, - input_var, - dim_start=1, - dim_end=None, - bias_attr=None): - """Append bias operator and return its output. If the user does not set bias_attr, append_bias_op will return input_var - - Args: - input_var: the input variable. The len(input_var.shape) is - larger or equal than 2. - dim_start: - dim_end: the shape of the bias will be - bias_attr: the bias_attr of it - - Return the Variable of after append bias op - """ - size = list(input_var.shape[dim_start:dim_end]) - bias_attr = bias_attr - if not bias_attr: - return input_var - - b = self.create_parameter( - attr=bias_attr, shape=size, dtype=input_var.dtype, is_bias=True) - tmp = self.create_variable_for_type_inference(dtype=input_var.dtype) - self.append_op( - type='elementwise_add', - inputs={'X': [input_var], - 'Y': [b]}, - outputs={'Out': [tmp]}, - attrs={'axis': dim_start}) - return tmp - # TODO: this should not be called anymore after all activation func move to Layers def append_activation(self, input_var, diff --git a/python/paddle/fluid/dygraph_utils.py b/python/paddle/fluid/dygraph_utils.py index 544cadcf70f..7b559494e6c 100644 --- a/python/paddle/fluid/dygraph_utils.py +++ b/python/paddle/fluid/dygraph_utils.py @@ -31,7 +31,7 @@ def _append_activation_in_dygraph(input, Return the Variable after append activation """ - if not act: + if act is None: return input attrs = () diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index 2152fb063ea..ed98860645f 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -1167,15 +1167,16 @@ def detection_map(detect_res, return helper.create_variable_for_type_inference(dtype=type) map_out = __create_var('float32') - accum_pos_count_out = out_states[0] if out_states else __create_var('int32') - accum_true_pos_out = out_states[1] if out_states else __create_var( - 'float32') - accum_false_pos_out = out_states[2] if out_states else __create_var( - 'float32') + accum_pos_count_out = out_states[ + 0] if out_states is not None else __create_var('int32') + accum_true_pos_out = out_states[ + 1] if out_states is not None else __create_var('float32') + accum_false_pos_out = out_states[ + 2] if out_states is not None else __create_var('float32') - pos_count = input_states[0] if input_states else None - true_pos = input_states[1] if input_states else None - false_pos = input_states[2] if input_states else None + pos_count = input_states[0] if input_states is not None else None + true_pos = input_states[1] if input_states is not None else None + false_pos = input_states[2] if input_states is not None else None helper.append_op( type="detection_map", @@ -2167,17 +2168,17 @@ def multi_box_head(inputs, aspect_ratios, num_layer, 'aspect_ratios should be list or tuple, and the length of inputs ' 'and aspect_ratios should be the same.') - if step_h: + if step_h is not None: _is_list_or_tuple_and_equal( step_h, num_layer, 'step_h should be list or tuple, and the length of inputs and ' 'step_h should be the same.') - if step_w: + if step_w is not None: _is_list_or_tuple_and_equal( step_w, num_layer, 'step_w should be list or tuple, and the length of inputs and ' 'step_w should be the same.') - if steps: + if steps is not None: _is_list_or_tuple_and_equal( steps, num_layer, 'steps should be list or tuple, and the length of inputs and ' -- GitLab