Skip to content

Commit

Permalink
fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
nemonameless committed Sep 23, 2022
1 parent 1ec93d2 commit 1a7ae77
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 77 deletions.
16 changes: 8 additions & 8 deletions python/paddle/fluid/tests/unittests/test_box_coder_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def batch_box_coder(p_box, pb_v, t_box, lod, code_type, norm, axis=0):

class TestBoxCoderOp(OpTest):

# def test_check_output(self):
# self.check_output(check_eager=True)
def test_check_output(self):
self.check_output(check_eager=True)

def setUp(self):
self.op_type = "box_coder"
Expand All @@ -134,8 +134,8 @@ def setUp(self):

class TestBoxCoderOpWithoutBoxVar(OpTest):

# def test_check_output(self):
# self.check_output(check_eager=True)
def test_check_output(self):
self.check_output(check_eager=True)

def setUp(self):
self.python_api = paddle.fluid.layers.box_coder
Expand Down Expand Up @@ -163,8 +163,8 @@ def setUp(self):

class TestBoxCoderOpWithLoD(OpTest):

# def test_check_output(self):
# self.check_output(check_eager=True)
def test_check_output(self):
self.check_output(check_eager=True)

def setUp(self):
self.python_api = paddle.fluid.layers.box_coder
Expand All @@ -189,8 +189,8 @@ def setUp(self):

class TestBoxCoderOpWithAxis(OpTest):

# def test_check_output(self):
# self.check_output(check_eager=True)
def test_check_output(self):
self.check_output(check_eager=True)

def setUp(self):
self.python_api = paddle.fluid.layers.box_coder
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_prior_box_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def set_data(self):

self.outputs = {'Boxes': self.out_boxes, 'Variances': self.out_var}

# def test_check_output(self):
# self.check_output(check_eager=True)
def test_check_output(self):
self.check_output(check_eager=True)

def setUp(self):
self.op_type = "prior_box"
Expand Down
144 changes: 77 additions & 67 deletions python/paddle/vision/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,25 @@ def prior_box(input,
clip=True,
flip=True)
"""
if in_dygraph_mode():
step_w, step_h = steps
if max_sizes == None:
max_sizes = []
box, var = _C_ops.prior_box(input, image, min_sizes, aspect_ratios,
variance, max_sizes, flip, clip, step_w,
step_h, offset, min_max_aspect_ratios_order)
return box, var

if _non_static_mode():
step_w, step_h = steps
if max_sizes == None:
max_sizes = []
box, var = _legacy_C_ops.prior_box(input, image, min_sizes,
aspect_ratios, variance, max_sizes,
flip, clip, step_w, step_h, offset,
min_max_aspect_ratios_order)
return box, var

helper = LayerHelper("prior_box", **locals())
dtype = helper.input_dtype()
check_variable_and_dtype(input, 'input',
Expand All @@ -731,52 +750,39 @@ def _is_list_or_tuple_(data):
aspect_ratios = list(map(float, aspect_ratios))
steps = list(map(float, steps))

cur_max_sizes = None
attrs = {
'min_sizes': min_sizes,
'aspect_ratios': aspect_ratios,
'variances': variance,
'flip': flip,
'clip': clip,
'step_w': steps[0],
'step_h': steps[1],
'offset': offset,
'min_max_aspect_ratios_order': min_max_aspect_ratios_order
}
if max_sizes is not None and len(max_sizes) > 0 and max_sizes[0] > 0:
if not _is_list_or_tuple_(max_sizes):
max_sizes = [max_sizes]
cur_max_sizes = max_sizes

if _non_static_mode():
attrs = ('min_sizes', min_sizes, 'aspect_ratios', aspect_ratios,
'variances', variance, 'flip', flip, 'clip', clip, 'step_w',
steps[0], 'step_h', steps[1], 'offset', offset,
'min_max_aspect_ratios_order', min_max_aspect_ratios_order)
if cur_max_sizes is not None:
attrs += ('max_sizes', cur_max_sizes)
box, var = _legacy_C_ops.prior_box(input, image, *attrs)
return box, var
else:
attrs = {
'min_sizes': min_sizes,
'aspect_ratios': aspect_ratios,
'variances': variance,
'flip': flip,
'clip': clip,
'step_w': steps[0],
'step_h': steps[1],
'offset': offset,
'min_max_aspect_ratios_order': min_max_aspect_ratios_order
}

if cur_max_sizes is not None:
attrs['max_sizes'] = cur_max_sizes

box = helper.create_variable_for_type_inference(dtype)
var = helper.create_variable_for_type_inference(dtype)
helper.append_op(type="prior_box",
inputs={
"Input": input,
"Image": image
},
outputs={
"Boxes": box,
"Variances": var
},
attrs=attrs)
box.stop_gradient = True
var.stop_gradient = True
return box, var
attrs['max_sizes'] = max_sizes

box = helper.create_variable_for_type_inference(dtype)
var = helper.create_variable_for_type_inference(dtype)
helper.append_op(
type="prior_box",
inputs={
"Input": input,
"Image": image
},
outputs={
"Boxes": box,
"Variances": var
},
attrs=attrs,
)
box.stop_gradient = True
var.stop_gradient = True
return box, var


def box_coder(prior_box,
Expand Down Expand Up @@ -884,20 +890,23 @@ def box_coder(prior_box,
if in_dygraph_mode():
if isinstance(prior_box_var, Variable):
output_box = _C_ops.box_coder(prior_box, prior_box_var, target_box,
code_type, box_normalized, axis)
code_type, box_normalized, axis, [])
elif isinstance(prior_box_var, list):
output_box = _C_ops.box_coder(prior_box, None, target_box,
code_type, box_normalized, axis,
prior_box_var)
else:
raise TypeError(
"Input variance of box_coder must be Variable or list")
elif _non_static_mode():
"Input variance of box_coder must be Variable or lisz")
return output_box

if _non_static_mode():
if isinstance(prior_box_var, Variable):
output_box = _legacy_C_ops.box_coder(prior_box, prior_box_var,
target_box, "code_type",
code_type, "box_normalized",
box_normalized, "axis", axis)

elif isinstance(prior_box_var, list):
output_box = _legacy_C_ops.box_coder(prior_box, None, target_box,
"code_type", code_type,
Expand All @@ -908,29 +917,30 @@ def box_coder(prior_box,
raise TypeError(
"Input variance of box_coder must be Variable or list")
return output_box
else:
helper = LayerHelper("box_coder", **locals())

helper = LayerHelper("box_coder", **locals())

output_box = helper.create_variable_for_type_inference(
dtype=prior_box.dtype)
output_box = helper.create_variable_for_type_inference(
dtype=prior_box.dtype)

inputs = {"PriorBox": prior_box, "TargetBox": target_box}
attrs = {
"code_type": code_type,
"box_normalized": box_normalized,
"axis": axis
}
if isinstance(prior_box_var, Variable):
inputs['PriorBoxVar'] = prior_box_var
elif isinstance(prior_box_var, list):
attrs['variance'] = prior_box_var
else:
raise TypeError("Input variance of box_coder must be Variable or list")
helper.append_op(type="box_coder",
inputs=inputs,
attrs=attrs,
outputs={"OutputBox": output_box})
return output_box
inputs = {"PriorBox": prior_box, "TargetBox": target_box}
attrs = {
"code_type": code_type,
"box_normalized": box_normalized,
"axis": axis
}
if isinstance(prior_box_var, Variable):
inputs['PriorBoxVar'] = prior_box_var
elif isinstance(prior_box_var, list):
attrs['variance'] = prior_box_var
else:
raise TypeError(
"Input variance of box_coder must be Variable or list")
helper.append_op(type="box_coder",
inputs=inputs,
attrs=attrs,
outputs={"OutputBox": output_box})
return output_box


class DeformConv2D(Layer):
Expand Down

0 comments on commit 1a7ae77

Please sign in to comment.