Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fluid remove]: remove paddle.fluid.layers.yolo_box and paddle.fluid.layers.yolov3_loss #48722

Merged
merged 23 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e1ab929
remove paddle.fluid.layers.nn.temporal_shift
zhengqiwen1997 Nov 18, 2022
7490926
code check
zhengqiwen1997 Nov 18, 2022
8fb5807
rm unittest
zhengqiwen1997 Nov 21, 2022
e1679d1
Merge branch 'develop' of https://github.com/zhengqiwen1997/Paddle in…
zhengqiwen1997 Nov 21, 2022
8106f10
Merge branch 'PaddlePaddle:develop' into develop
zhengqiwen1997 Nov 22, 2022
850f4af
Merge branch 'develop' of https://github.com/zhengqiwen1997/Paddle in…
zhengqiwen1997 Nov 22, 2022
0ba6ae7
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 22, 2022
94bf96f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 23, 2022
dd78f52
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 23, 2022
79bad82
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 24, 2022
490c0a2
conflict ok
zhengqiwen1997 Nov 25, 2022
c0272e1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 28, 2022
1e38f23
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 29, 2022
1083fe4
Merge branch 'develop' of https://github.com/zhengqiwen1997/Paddle in…
zhengqiwen1997 Nov 29, 2022
c56d645
Merge branch 'develop' of https://github.com/zhengqiwen1997/Paddle in…
zhengqiwen1997 Nov 30, 2022
6458a5f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Nov 30, 2022
47468a8
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Dec 1, 2022
c1f8147
conflict ok
zhengqiwen1997 Dec 2, 2022
57913d7
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Dec 5, 2022
010aa26
remove fluid.yolo_box
zhengqiwen1997 Dec 5, 2022
d1f7db8
remove fluid.yolov3_loss
zhengqiwen1997 Dec 5, 2022
36fffe9
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhengqiwen1997 Dec 6, 2022
1d116c5
change the comments of yolov3_loss to yolo_loss
zhengqiwen1997 Dec 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 0 additions & 258 deletions python/paddle/fluid/layers/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
'iou_similarity',
'box_coder',
'polygon_box_transform',
'yolov3_loss',
'yolo_box',
'box_clip',
'multiclass_nms',
'locality_aware_nms',
Expand Down Expand Up @@ -893,262 +891,6 @@ def polygon_box_transform(input, name=None):
return output


@deprecated(since="2.0.0", update_to="paddle.vision.ops.yolo_loss")
@templatedoc(op_type="yolov3_loss")
def yolov3_loss(
x,
gt_box,
gt_label,
anchors,
anchor_mask,
class_num,
ignore_thresh,
downsample_ratio,
gt_score=None,
use_label_smooth=True,
name=None,
scale_x_y=1.0,
):
"""

${comment}

Args:
x (Variable): ${x_comment}The data type is float32 or float64.
gt_box (Variable): groud truth boxes, should be in shape of [N, B, 4],
in the third dimension, x, y, w, h should be stored.
x,y is the center coordinate of boxes, w, h are the
width and height, x, y, w, h should be divided by
input image height to scale to [0, 1].
N is the batch number and B is the max box number in
an image.The data type is float32 or float64.
gt_label (Variable): class id of ground truth boxes, should be in shape
of [N, B].The data type is int32.
anchors (list|tuple): ${anchors_comment}
anchor_mask (list|tuple): ${anchor_mask_comment}
class_num (int): ${class_num_comment}
ignore_thresh (float): ${ignore_thresh_comment}
downsample_ratio (int): ${downsample_ratio_comment}
name (string): 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`
gt_score (Variable): mixup score of ground truth boxes, should be in shape
of [N, B]. Default None.
use_label_smooth (bool): ${use_label_smooth_comment}
scale_x_y (float): ${scale_x_y_comment}

Returns:
Variable: A 1-D tensor with shape [N], the value of yolov3 loss

Raises:
TypeError: Input x of yolov3_loss must be Variable
TypeError: Input gtbox of yolov3_loss must be Variable
TypeError: Input gtlabel of yolov3_loss must be Variable
TypeError: Input gtscore of yolov3_loss must be None or Variable
TypeError: Attr anchors of yolov3_loss must be list or tuple
TypeError: Attr class_num of yolov3_loss must be an integer
TypeError: Attr ignore_thresh of yolov3_loss must be a float number
TypeError: Attr use_label_smooth of yolov3_loss must be a bool value

Examples:
.. code-block:: python

import paddle.fluid as fluid
import paddle
paddle.enable_static()
x = fluid.data(name='x', shape=[None, 255, 13, 13], dtype='float32')
gt_box = fluid.data(name='gt_box', shape=[None, 6, 4], dtype='float32')
gt_label = fluid.data(name='gt_label', shape=[None, 6], dtype='int32')
gt_score = fluid.data(name='gt_score', shape=[None, 6], dtype='float32')
anchors = [10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326]
anchor_mask = [0, 1, 2]
loss = fluid.layers.yolov3_loss(x=x, gt_box=gt_box, gt_label=gt_label,
gt_score=gt_score, anchors=anchors,
anchor_mask=anchor_mask, class_num=80,
ignore_thresh=0.7, downsample_ratio=32)
"""

if not isinstance(x, Variable):
raise TypeError("Input x of yolov3_loss must be Variable")
if not isinstance(gt_box, Variable):
raise TypeError("Input gtbox of yolov3_loss must be Variable")
if not isinstance(gt_label, Variable):
raise TypeError("Input gtlabel of yolov3_loss must be Variable")
if gt_score is not None and not isinstance(gt_score, Variable):
raise TypeError("Input gtscore of yolov3_loss must be Variable")
if not isinstance(anchors, list) and not isinstance(anchors, tuple):
raise TypeError("Attr anchors of yolov3_loss must be list or tuple")
if not isinstance(anchor_mask, list) and not isinstance(anchor_mask, tuple):
raise TypeError("Attr anchor_mask of yolov3_loss must be list or tuple")
if not isinstance(class_num, int):
raise TypeError("Attr class_num of yolov3_loss must be an integer")
if not isinstance(ignore_thresh, float):
raise TypeError(
"Attr ignore_thresh of yolov3_loss must be a float number"
)
if not isinstance(use_label_smooth, bool):
raise TypeError(
"Attr use_label_smooth of yolov3_loss must be a bool value"
)

if _non_static_mode():
attrs = (
"anchors",
anchors,
"anchor_mask",
anchor_mask,
"class_num",
class_num,
"ignore_thresh",
ignore_thresh,
"downsample_ratio",
downsample_ratio,
"use_label_smooth",
use_label_smooth,
"scale_x_y",
scale_x_y,
)
loss, _, _ = _legacy_C_ops.yolov3_loss(
x, gt_box, gt_label, gt_score, *attrs
)
return loss

helper = LayerHelper('yolov3_loss', **locals())
loss = helper.create_variable_for_type_inference(dtype=x.dtype)
objectness_mask = helper.create_variable_for_type_inference(dtype='int32')
gt_match_mask = helper.create_variable_for_type_inference(dtype='int32')

inputs = {
"X": x,
"GTBox": gt_box,
"GTLabel": gt_label,
}
if gt_score is not None:
inputs["GTScore"] = gt_score

attrs = {
"anchors": anchors,
"anchor_mask": anchor_mask,
"class_num": class_num,
"ignore_thresh": ignore_thresh,
"downsample_ratio": downsample_ratio,
"use_label_smooth": use_label_smooth,
"scale_x_y": scale_x_y,
}

helper.append_op(
type='yolov3_loss',
inputs=inputs,
outputs={
'Loss': loss,
'ObjectnessMask': objectness_mask,
'GTMatchMask': gt_match_mask,
},
attrs=attrs,
)
return loss


@deprecated(since="2.0.0", update_to="paddle.vision.ops.yolo_box")
@templatedoc(op_type="yolo_box")
def yolo_box(
x,
img_size,
anchors,
class_num,
conf_thresh,
downsample_ratio,
clip_bbox=True,
name=None,
scale_x_y=1.0,
iou_aware=False,
iou_aware_factor=0.5,
):
"""

${comment}

Args:
x (Variable): ${x_comment} The data type is float32 or float64.
img_size (Variable): ${img_size_comment} The data type is int32.
anchors (list|tuple): ${anchors_comment}
class_num (int): ${class_num_comment}
conf_thresh (float): ${conf_thresh_comment}
downsample_ratio (int): ${downsample_ratio_comment}
clip_bbox (bool): ${clip_bbox_comment}
scale_x_y (float): ${scale_x_y_comment}
name (string): 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`
iou_aware (bool): ${iou_aware_comment}
iou_aware_factor (float): ${iou_aware_factor_comment}

Returns:
Variable: A 3-D tensor with shape [N, M, 4], the coordinates of boxes,
and a 3-D tensor with shape [N, M, :attr:`class_num`], the classification
scores of boxes.

Raises:
TypeError: Input x of yolov_box must be Variable
TypeError: Attr anchors of yolo box must be list or tuple
TypeError: Attr class_num of yolo box must be an integer
TypeError: Attr conf_thresh of yolo box must be a float number

Examples:

.. code-block:: python

import paddle.fluid as fluid
import paddle
paddle.enable_static()
x = fluid.data(name='x', shape=[None, 255, 13, 13], dtype='float32')
img_size = fluid.data(name='img_size',shape=[None, 2],dtype='int64')
anchors = [10, 13, 16, 30, 33, 23]
boxes,scores = fluid.layers.yolo_box(x=x, img_size=img_size, class_num=80, anchors=anchors,
conf_thresh=0.01, downsample_ratio=32)
"""
helper = LayerHelper('yolo_box', **locals())

if not isinstance(x, Variable):
raise TypeError("Input x of yolo_box must be Variable")
if not isinstance(img_size, Variable):
raise TypeError("Input img_size of yolo_box must be Variable")
if not isinstance(anchors, list) and not isinstance(anchors, tuple):
raise TypeError("Attr anchors of yolo_box must be list or tuple")
if not isinstance(class_num, int):
raise TypeError("Attr class_num of yolo_box must be an integer")
if not isinstance(conf_thresh, float):
raise TypeError("Attr ignore_thresh of yolo_box must be a float number")

boxes = helper.create_variable_for_type_inference(dtype=x.dtype)
scores = helper.create_variable_for_type_inference(dtype=x.dtype)

attrs = {
"anchors": anchors,
"class_num": class_num,
"conf_thresh": conf_thresh,
"downsample_ratio": downsample_ratio,
"clip_bbox": clip_bbox,
"scale_x_y": scale_x_y,
"iou_aware": iou_aware,
"iou_aware_factor": iou_aware_factor,
}

helper.append_op(
type='yolo_box',
inputs={
"X": x,
"ImgSize": img_size,
},
outputs={
'Boxes': boxes,
'Scores': scores,
},
attrs=attrs,
)
return boxes, scores


@templatedoc()
def detection_map(
detect_res,
Expand Down
69 changes: 0 additions & 69 deletions python/paddle/fluid/tests/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,75 +677,6 @@ def test_generate_proposals(self):
np.testing.assert_array_equal(np.array(rois_num_stat), rois_num_dy)


class TestYoloDetection(unittest.TestCase):
def test_yolov3_loss(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[30, 7, 7], dtype='float32')
gt_box = layers.data(name='gt_box', shape=[10, 4], dtype='float32')
gt_label = layers.data(name='gt_label', shape=[10], dtype='int32')
gt_score = layers.data(name='gt_score', shape=[10], dtype='float32')
loss = layers.yolov3_loss(
x,
gt_box,
gt_label,
[10, 13, 30, 13],
[0, 1],
10,
0.7,
32,
gt_score=gt_score,
use_label_smooth=False,
)

self.assertIsNotNone(loss)

def test_yolo_box(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[30, 7, 7], dtype='float32')
img_size = layers.data(name='img_size', shape=[2], dtype='int32')
boxes, scores = layers.yolo_box(
x, img_size, [10, 13, 30, 13], 10, 0.01, 32
)
self.assertIsNotNone(boxes)
self.assertIsNotNone(scores)

def test_yolov3_loss_with_scale(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[30, 7, 7], dtype='float32')
gt_box = layers.data(name='gt_box', shape=[10, 4], dtype='float32')
gt_label = layers.data(name='gt_label', shape=[10], dtype='int32')
gt_score = layers.data(name='gt_score', shape=[10], dtype='float32')
loss = layers.yolov3_loss(
x,
gt_box,
gt_label,
[10, 13, 30, 13],
[0, 1],
10,
0.7,
32,
gt_score=gt_score,
use_label_smooth=False,
scale_x_y=1.2,
)

self.assertIsNotNone(loss)

def test_yolo_box_with_scale(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[30, 7, 7], dtype='float32')
img_size = layers.data(name='img_size', shape=[2], dtype='int32')
boxes, scores = layers.yolo_box(
x, img_size, [10, 13, 30, 13], 10, 0.01, 32, scale_x_y=1.2
)
self.assertIsNotNone(boxes)
self.assertIsNotNone(scores)


class TestBoxClip(unittest.TestCase):
def test_box_clip(self):
program = Program()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def forward(
for i, out in enumerate(self.outputs):
anchor_mask = cfg.anchor_masks[i]
if self.is_train:
loss = fluid.layers.yolov3_loss(
loss = paddle.vision.ops.yolo_loss(
x=out,
gt_box=self.gtbox,
gt_label=self.gtlabel,
Expand All @@ -332,7 +332,7 @@ def forward(
for m in anchor_mask:
mask_anchors.append(cfg.anchors[2 * m])
mask_anchors.append(cfg.anchors[2 * m + 1])
boxes, scores = fluid.layers.yolo_box(
boxes, scores = paddle.vision.ops.yolo_box(
x=out,
img_size=self.im_shape,
anchors=mask_anchors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def build_model(self):
'value': 6,
}
img_size = paddle.fluid.layers.fill_constant(**attrs)
out = paddle.fluid.layers.yolo_box(x=x, img_size=img_size, **self.attrs)
out = paddle.vision.ops.yolo_box(x=x, img_size=img_size, **self.attrs)
self.fetch_list = [x.name for x in out]

def run_model(self, exec_mode):
Expand Down
Loading