Skip to content

Commit 5b6767a

Browse files
[fluid remove]: remove paddle.fluid.layers.box_coder and paddle.fluid.layers.polygon_box_transform (#48896)
* remove fluid_box_coder and polygon_box_transform * code check
1 parent 8bf7f63 commit 5b6767a

File tree

5 files changed

+6
-246
lines changed

5 files changed

+6
-246
lines changed

python/paddle/fluid/layers/detection.py

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
'generate_proposal_labels',
4848
'generate_proposals',
4949
'generate_mask_labels',
50-
'box_coder',
51-
'polygon_box_transform',
5250
'box_clip',
5351
'multiclass_nms',
5452
'locality_aware_nms',
@@ -60,177 +58,6 @@
6058
]
6159

6260

63-
@templatedoc()
64-
def box_coder(
65-
prior_box,
66-
prior_box_var,
67-
target_box,
68-
code_type="encode_center_size",
69-
box_normalized=True,
70-
name=None,
71-
axis=0,
72-
):
73-
r"""
74-
75-
**Box Coder Layer**
76-
77-
Encode/Decode the target bounding box with the priorbox information.
78-
79-
The Encoding schema described below:
80-
81-
.. math::
82-
83-
ox = (tx - px) / pw / pxv
84-
85-
oy = (ty - py) / ph / pyv
86-
87-
ow = \log(\abs(tw / pw)) / pwv
88-
89-
oh = \log(\abs(th / ph)) / phv
90-
91-
The Decoding schema described below:
92-
93-
.. math::
94-
95-
ox = (pw * pxv * tx * + px) - tw / 2
96-
97-
oy = (ph * pyv * ty * + py) - th / 2
98-
99-
ow = \exp(pwv * tw) * pw + tw / 2
100-
101-
oh = \exp(phv * th) * ph + th / 2
102-
103-
where `tx`, `ty`, `tw`, `th` denote the target box's center coordinates,
104-
width and height respectively. Similarly, `px`, `py`, `pw`, `ph` denote
105-
the priorbox's (anchor) center coordinates, width and height. `pxv`,
106-
`pyv`, `pwv`, `phv` denote the variance of the priorbox and `ox`, `oy`,
107-
`ow`, `oh` denote the encoded/decoded coordinates, width and height.
108-
109-
During Box Decoding, two modes for broadcast are supported. Say target
110-
box has shape [N, M, 4], and the shape of prior box can be [N, 4] or
111-
[M, 4]. Then prior box will broadcast to target box along the
112-
assigned axis.
113-
114-
Args:
115-
prior_box(Variable): Box list prior_box is a 2-D Tensor with shape
116-
[M, 4] holds M boxes and data type is float32 or float64. Each box
117-
is represented as [xmin, ymin, xmax, ymax], [xmin, ymin] is the
118-
left top coordinate of the anchor box, if the input is image feature
119-
map, they are close to the origin of the coordinate system.
120-
[xmax, ymax] is the right bottom coordinate of the anchor box.
121-
prior_box_var(List|Variable|None): prior_box_var supports three types
122-
of input. One is variable with shape [M, 4] which holds M group and
123-
data type is float32 or float64. The second is list consist of
124-
4 elements shared by all boxes and data type is float32 or float64.
125-
Other is None and not involved in calculation.
126-
target_box(Variable): This input can be a 2-D LoDTensor with shape
127-
[N, 4] when code_type is 'encode_center_size'. This input also can
128-
be a 3-D Tensor with shape [N, M, 4] when code_type is
129-
'decode_center_size'. Each box is represented as
130-
[xmin, ymin, xmax, ymax]. The data type is float32 or float64.
131-
This tensor can contain LoD information to represent a batch of inputs.
132-
code_type(str): The code type used with the target box. It can be
133-
`encode_center_size` or `decode_center_size`. `encode_center_size`
134-
by default.
135-
box_normalized(bool): Whether treat the priorbox as a normalized box.
136-
Set true by default.
137-
name(str, optional): For detailed information, please refer
138-
to :ref:`api_guide_Name`. Usually name is no need to set and
139-
None by default.
140-
axis(int): Which axis in PriorBox to broadcast for box decode,
141-
for example, if axis is 0 and TargetBox has shape [N, M, 4] and
142-
PriorBox has shape [M, 4], then PriorBox will broadcast to [N, M, 4]
143-
for decoding. It is only valid when code type is
144-
`decode_center_size`. Set 0 by default.
145-
146-
Returns:
147-
Variable:
148-
149-
output_box(Variable): When code_type is 'encode_center_size', the
150-
output tensor of box_coder_op with shape [N, M, 4] representing the
151-
result of N target boxes encoded with M Prior boxes and variances.
152-
When code_type is 'decode_center_size', N represents the batch size
153-
and M represents the number of decoded boxes.
154-
155-
Examples:
156-
157-
.. code-block:: python
158-
159-
import paddle.fluid as fluid
160-
import paddle
161-
paddle.enable_static()
162-
# For encode
163-
prior_box_encode = fluid.data(name='prior_box_encode',
164-
shape=[512, 4],
165-
dtype='float32')
166-
target_box_encode = fluid.data(name='target_box_encode',
167-
shape=[81, 4],
168-
dtype='float32')
169-
output_encode = fluid.layers.box_coder(prior_box=prior_box_encode,
170-
prior_box_var=[0.1,0.1,0.2,0.2],
171-
target_box=target_box_encode,
172-
code_type="encode_center_size")
173-
# For decode
174-
prior_box_decode = fluid.data(name='prior_box_decode',
175-
shape=[512, 4],
176-
dtype='float32')
177-
target_box_decode = fluid.data(name='target_box_decode',
178-
shape=[512, 81, 4],
179-
dtype='float32')
180-
output_decode = fluid.layers.box_coder(prior_box=prior_box_decode,
181-
prior_box_var=[0.1,0.1,0.2,0.2],
182-
target_box=target_box_decode,
183-
code_type="decode_center_size",
184-
box_normalized=False,
185-
axis=1)
186-
"""
187-
return paddle.vision.ops.box_coder(
188-
prior_box=prior_box,
189-
prior_box_var=prior_box_var,
190-
target_box=target_box,
191-
code_type=code_type,
192-
box_normalized=box_normalized,
193-
axis=axis,
194-
name=name,
195-
)
196-
197-
198-
@templatedoc()
199-
def polygon_box_transform(input, name=None):
200-
"""
201-
${comment}
202-
203-
Args:
204-
input(Variable): The input with shape [batch_size, geometry_channels, height, width].
205-
A Tensor with type float32, float64.
206-
name(str, Optional): For details, please refer to :ref:`api_guide_Name`.
207-
Generally, no setting is required. Default: None.
208-
209-
Returns:
210-
Variable: The output with the same shape as input. A Tensor with type float32, float64.
211-
212-
Examples:
213-
.. code-block:: python
214-
215-
import paddle.fluid as fluid
216-
input = fluid.data(name='input', shape=[4, 10, 5, 5], dtype='float32')
217-
out = fluid.layers.polygon_box_transform(input)
218-
"""
219-
check_variable_and_dtype(
220-
input, "input", ['float32', 'float64'], 'polygon_box_transform'
221-
)
222-
helper = LayerHelper("polygon_box_transform", **locals())
223-
output = helper.create_variable_for_type_inference(dtype=input.dtype)
224-
225-
helper.append_op(
226-
type="polygon_box_transform",
227-
inputs={"Input": input},
228-
attrs={},
229-
outputs={"Output": output},
230-
)
231-
return output
232-
233-
23461
def prior_box(
23562
input,
23663
image,

python/paddle/fluid/tests/test_detection.py

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

7777

78-
class TestDetection(unittest.TestCase):
79-
def test_box_coder_api(self):
80-
program = Program()
81-
with program_guard(program):
82-
x = layers.data(name='x', shape=[4], dtype='float32')
83-
y = layers.data(name='z', shape=[4], dtype='float32', lod_level=1)
84-
bcoder = layers.box_coder(
85-
prior_box=x,
86-
prior_box_var=[0.1, 0.2, 0.1, 0.2],
87-
target_box=y,
88-
code_type='encode_center_size',
89-
)
90-
self.assertIsNotNone(bcoder)
91-
print(str(program))
92-
93-
def test_box_coder_error(self):
94-
program = Program()
95-
with program_guard(program):
96-
x1 = fluid.data(name='x1', shape=[10, 4], dtype='int32')
97-
y1 = fluid.data(
98-
name='y1', shape=[10, 4], dtype='float32', lod_level=1
99-
)
100-
x2 = fluid.data(name='x2', shape=[10, 4], dtype='float32')
101-
y2 = fluid.data(
102-
name='y2', shape=[10, 4], dtype='int32', lod_level=1
103-
)
104-
105-
self.assertRaises(
106-
TypeError,
107-
layers.box_coder,
108-
prior_box=x1,
109-
prior_box_var=[0.1, 0.2, 0.1, 0.2],
110-
target_box=y1,
111-
code_type='encode_center_size',
112-
)
113-
self.assertRaises(
114-
TypeError,
115-
layers.box_coder,
116-
prior_box=x2,
117-
prior_box_var=[0.1, 0.2, 0.1, 0.2],
118-
target_box=y2,
119-
code_type='encode_center_size',
120-
)
121-
122-
12378
class TestPriorBox(unittest.TestCase):
12479
def test_prior_box(self):
12580
program = Program()

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from op_test import OpTest
1919

2020
import paddle
21-
import paddle.fluid.core as core
2221

2322

2423
def box_decoder(t_box, p_box, pb_v, output_box, norm, axis=0):
@@ -114,7 +113,7 @@ def test_check_output(self):
114113

115114
def setUp(self):
116115
self.op_type = "box_coder"
117-
self.python_api = paddle.fluid.layers.box_coder
116+
self.python_api = paddle.vision.ops.box_coder
118117
lod = [[1, 1, 1, 1, 1]]
119118
prior_box = np.random.random((81, 4)).astype('float32')
120119
prior_box_var = np.random.random((81, 4)).astype('float32')
@@ -146,7 +145,7 @@ def test_check_output(self):
146145
self.check_output(check_eager=True)
147146

148147
def setUp(self):
149-
self.python_api = paddle.fluid.layers.box_coder
148+
self.python_api = paddle.vision.ops.box_coder
150149
self.op_type = "box_coder"
151150
lod = [[0, 1, 2, 3, 4, 5]]
152151
prior_box = np.random.random((81, 4)).astype('float32')
@@ -180,7 +179,7 @@ def test_check_output(self):
180179
self.check_output(check_eager=True)
181180

182181
def setUp(self):
183-
self.python_api = paddle.fluid.layers.box_coder
182+
self.python_api = paddle.vision.ops.box_coder
184183
self.op_type = "box_coder"
185184
lod = [[10, 20, 20]]
186185
prior_box = np.random.random((20, 4)).astype('float32')
@@ -211,7 +210,7 @@ def test_check_output(self):
211210
self.check_output(check_eager=True)
212211

213212
def setUp(self):
214-
self.python_api = paddle.fluid.layers.box_coder
213+
self.python_api = paddle.vision.ops.box_coder
215214
self.op_type = "box_coder"
216215
lod = [[1, 1, 1, 1, 1]]
217216
prior_box = np.random.random((30, 4)).astype('float32')
@@ -298,13 +297,13 @@ def setUp(self):
298297
self.axis,
299298
)
300299
self.place = [paddle.CPUPlace()]
301-
if core.is_compiled_with_cuda():
300+
if paddle.is_compiled_with_cuda():
302301
self.place.append(paddle.CUDAPlace(0))
303302

304303
def test_dygraph_api(self):
305304
def run(place):
306305
paddle.disable_static(place)
307-
output_box = paddle.fluid.layers.box_coder(
306+
output_box = paddle.vision.ops.box_coder(
308307
paddle.to_tensor(self.prior_box),
309308
self.prior_box_var.tolist(),
310309
paddle.to_tensor(self.target_box),

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,14 +2294,6 @@ def make_topk(self):
22942294
return values
22952295
return indices
22962296

2297-
def make_polygon_box_transform(self):
2298-
with program_guard(
2299-
fluid.default_main_program(), fluid.default_startup_program()
2300-
):
2301-
x = self._get_data(name='x', shape=[8, 4, 4], dtype="float32")
2302-
output = layers.polygon_box_transform(input=x)
2303-
return output
2304-
23052297
def make_l2_normalize(self):
23062298
with program_guard(
23072299
fluid.default_main_program(), fluid.default_startup_program()

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import numpy as np
1818
from op_test import OpTest
1919

20-
import paddle.fluid as fluid
21-
2220

2321
def PolygonBoxRestore(input):
2422
shape = input.shape
@@ -72,16 +70,5 @@ def config(self):
7270
self.input_shape = (3, 12, 4, 5)
7371

7472

75-
class TestPolygonBoxInvalidInput(unittest.TestCase):
76-
def test_error(self):
77-
def test_invalid_input():
78-
input = fluid.data(
79-
name='input', shape=[None, 3, 32, 32], dtype='int64'
80-
)
81-
out = fluid.layers.polygon_box_transform(input)
82-
83-
self.assertRaises(TypeError, test_invalid_input)
84-
85-
8673
if __name__ == '__main__':
8774
unittest.main()

0 commit comments

Comments
 (0)