Skip to content

Commit f6915d4

Browse files
remove prior_box (#49006)
* remove prior_box * modify the sequence of paras of prior_box in multi_box_head api
1 parent 90ed6f5 commit f6915d4

File tree

3 files changed

+3
-175
lines changed

3 files changed

+3
-175
lines changed

python/paddle/fluid/layers/detection.py

Lines changed: 2 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from ..framework import in_dygraph_mode
4040

4141
__all__ = [
42-
'prior_box',
4342
'density_prior_box',
4443
'multi_box_head',
4544
'anchor_generator',
@@ -58,135 +57,6 @@
5857
]
5958

6059

61-
def prior_box(
62-
input,
63-
image,
64-
min_sizes,
65-
max_sizes=None,
66-
aspect_ratios=[1.0],
67-
variance=[0.1, 0.1, 0.2, 0.2],
68-
flip=False,
69-
clip=False,
70-
steps=[0.0, 0.0],
71-
offset=0.5,
72-
name=None,
73-
min_max_aspect_ratios_order=False,
74-
):
75-
"""
76-
77-
This op generates prior boxes for SSD(Single Shot MultiBox Detector) algorithm.
78-
Each position of the input produce N prior boxes, N is determined by
79-
the count of min_sizes, max_sizes and aspect_ratios, The size of the
80-
box is in range(min_size, max_size) interval, which is generated in
81-
sequence according to the aspect_ratios.
82-
83-
Parameters:
84-
input(Variable): 4-D tensor(NCHW), the data type should be float32 or float64.
85-
image(Variable): 4-D tensor(NCHW), the input image data of PriorBoxOp,
86-
the data type should be float32 or float64.
87-
min_sizes(list|tuple|float): the min sizes of generated prior boxes.
88-
max_sizes(list|tuple|None): the max sizes of generated prior boxes.
89-
Default: None.
90-
aspect_ratios(list|tuple|float): the aspect ratios of generated
91-
prior boxes. Default: [1.].
92-
variance(list|tuple): the variances to be encoded in prior boxes.
93-
Default:[0.1, 0.1, 0.2, 0.2].
94-
flip(bool): Whether to flip aspect ratios. Default:False.
95-
clip(bool): Whether to clip out-of-boundary boxes. Default: False.
96-
step(list|tuple): Prior boxes step across width and height, If
97-
step[0] equals to 0.0 or step[1] equals to 0.0, the prior boxes step across
98-
height or weight of the input will be automatically calculated.
99-
Default: [0., 0.]
100-
offset(float): Prior boxes center offset. Default: 0.5
101-
min_max_aspect_ratios_order(bool): If set True, the output prior box is
102-
in order of [min, max, aspect_ratios], which is consistent with
103-
Caffe. Please note, this order affects the weights order of
104-
convolution layer followed by and does not affect the final
105-
detection results. Default: False.
106-
name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`
107-
108-
Returns:
109-
Tuple: A tuple with two Variable (boxes, variances)
110-
111-
boxes(Variable): the output prior boxes of PriorBox.
112-
4-D tensor, the layout is [H, W, num_priors, 4].
113-
H is the height of input, W is the width of input,
114-
num_priors is the total box count of each position of input.
115-
116-
variances(Variable): the expanded variances of PriorBox.
117-
4-D tensor, the layput is [H, W, num_priors, 4].
118-
H is the height of input, W is the width of input
119-
num_priors is the total box count of each position of input
120-
121-
Examples:
122-
.. code-block:: python
123-
124-
#declarative mode
125-
import paddle.fluid as fluid
126-
import numpy as np
127-
import paddle
128-
paddle.enable_static()
129-
input = fluid.data(name="input", shape=[None,3,6,9])
130-
image = fluid.data(name="image", shape=[None,3,9,12])
131-
box, var = fluid.layers.prior_box(
132-
input=input,
133-
image=image,
134-
min_sizes=[100.],
135-
clip=True,
136-
flip=True)
137-
138-
place = fluid.CPUPlace()
139-
exe = fluid.Executor(place)
140-
exe.run(fluid.default_startup_program())
141-
142-
# prepare a batch of data
143-
input_data = np.random.rand(1,3,6,9).astype("float32")
144-
image_data = np.random.rand(1,3,9,12).astype("float32")
145-
146-
box_out, var_out = exe.run(fluid.default_main_program(),
147-
feed={"input":input_data,"image":image_data},
148-
fetch_list=[box,var],
149-
return_numpy=True)
150-
151-
# print(box_out.shape)
152-
# (6, 9, 1, 4)
153-
# print(var_out.shape)
154-
# (6, 9, 1, 4)
155-
156-
# imperative mode
157-
import paddle.fluid.dygraph as dg
158-
159-
with dg.guard(place) as g:
160-
input = dg.to_variable(input_data)
161-
image = dg.to_variable(image_data)
162-
box, var = fluid.layers.prior_box(
163-
input=input,
164-
image=image,
165-
min_sizes=[100.],
166-
clip=True,
167-
flip=True)
168-
# print(box.shape)
169-
# [6L, 9L, 1L, 4L]
170-
# print(var.shape)
171-
# [6L, 9L, 1L, 4L]
172-
173-
"""
174-
return paddle.vision.ops.prior_box(
175-
input=input,
176-
image=image,
177-
min_sizes=min_sizes,
178-
max_sizes=max_sizes,
179-
aspect_ratios=aspect_ratios,
180-
variance=variance,
181-
flip=flip,
182-
clip=clip,
183-
steps=steps,
184-
offset=offset,
185-
min_max_aspect_ratios_order=min_max_aspect_ratios_order,
186-
name=name,
187-
)
188-
189-
19060
def density_prior_box(
19161
input,
19262
image,
@@ -623,7 +493,7 @@ def _is_list_or_tuple_and_equal(data, length, err_info):
623493
aspect_ratio = [aspect_ratio]
624494
step = [step_w[i] if step_w else 0.0, step_h[i] if step_w else 0.0]
625495

626-
box, var = prior_box(
496+
box, var = paddle.vision.ops.prior_box(
627497
input,
628498
image,
629499
min_size,
@@ -634,8 +504,8 @@ def _is_list_or_tuple_and_equal(data, length, err_info):
634504
clip,
635505
step,
636506
offset,
637-
None,
638507
min_max_aspect_ratios_order,
508+
None,
639509
)
640510

641511
box_results.append(box)

python/paddle/fluid/tests/test_detection.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -75,48 +75,6 @@ def dynamic_graph(self, force_to_use_cpu=False):
7575
yield
7676

7777

78-
class TestPriorBox(unittest.TestCase):
79-
def test_prior_box(self):
80-
program = Program()
81-
with program_guard(program):
82-
data_shape = [3, 224, 224]
83-
images = fluid.layers.data(
84-
name='pixel', shape=data_shape, dtype='float32'
85-
)
86-
conv1 = fluid.layers.conv2d(images, 3, 3, 2)
87-
box, var = layers.prior_box(
88-
input=conv1,
89-
image=images,
90-
min_sizes=[100.0],
91-
aspect_ratios=[1.0],
92-
flip=True,
93-
clip=True,
94-
)
95-
assert len(box.shape) == 4
96-
assert box.shape == var.shape
97-
assert box.shape[3] == 4
98-
99-
100-
class TestPriorBox2(unittest.TestCase):
101-
def test_prior_box(self):
102-
program = Program()
103-
with program_guard(program):
104-
data_shape = [None, 3, None, None]
105-
images = fluid.data(name='pixel', shape=data_shape, dtype='float32')
106-
conv1 = fluid.layers.conv2d(images, 3, 3, 2)
107-
box, var = layers.prior_box(
108-
input=conv1,
109-
image=images,
110-
min_sizes=[100.0],
111-
aspect_ratios=[1.0],
112-
flip=True,
113-
clip=True,
114-
)
115-
assert len(box.shape) == 4
116-
assert box.shape == var.shape
117-
assert box.shape[3] == 4
118-
119-
12078
class TestDensityPriorBox(unittest.TestCase):
12179
def test_density_prior_box(self):
12280
program = Program()

python/paddle/fluid/tests/unittests/test_prior_box_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def python_prior_box(
3636
min_max_aspect_ratios_order=False,
3737
name=None,
3838
):
39-
return paddle.fluid.layers.detection.prior_box(
39+
return paddle.vision.ops.prior_box(
4040
input,
4141
image,
4242
min_sizes=min_sizes,

0 commit comments

Comments
 (0)