diff --git a/python/paddle/fluid/dygraph/layer_object_helper.py b/python/paddle/fluid/dygraph/layer_object_helper.py index 9fd1e392791f2bf7a19942749eae87001ec3ede8..f2e914a2137d0be0606556471696fd3d255b3c12 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 544cadcf70f19b1e98fab14cf065f5f06bbf4f53..7b559494e6c3b779983e54f5f9675170ef985f63 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 e0725242b7b28f92a9d788a17ec2fe84fcdacc83..e1034cc4c27451d4138e96b08005fe8e3e949169 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -993,7 +993,7 @@ def yolov3_loss(x, "GTBox": gt_box, "GTLabel": gt_label, } - if gt_score: + if gt_score is not None: inputs["GTScore"] = gt_score attrs = { @@ -1159,15 +1159,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", @@ -2159,17 +2160,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 ' @@ -2195,7 +2196,10 @@ def multi_box_head(inputs, aspect_ratio = aspect_ratios[i] if not _is_list_or_tuple_(aspect_ratio): aspect_ratio = [aspect_ratio] - step = [step_w[i] if step_w else 0.0, step_h[i] if step_w else 0.0] + step = [ + step_w[i] if step_w is not None else 0.0, step_h[i] + if step_w is not None else 0.0 + ] box, var = prior_box(input, image, min_size, max_size, aspect_ratio, variance, flip, clip, step, offset, None,