Skip to content
New issue

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

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

Already on GitHub? # to your account

[fluid remove]: remove paddle.fluid.layers.detection_map, paddle.fluid.metrics.DetectionMAP and paddle.fluid.evaluator.DetectionMAP #48674

Merged
merged 21 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 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
49ebbc9
remove paddle.fluid.layers.detection_map and the class:DetectionMAP
zhengqiwen1997 Nov 30, 2022
d873d3d
conflict ok
zhengqiwen1997 Dec 2, 2022
afdabba
Merge branch 'develop' into fluid_detection_map
zhengqiwen1997 Dec 6, 2022
2f2d571
Merge branch 'develop' into fluid_detection_map
zhengqiwen1997 Dec 7, 2022
44602ec
Merge branch 'develop' into fluid_detection_map
zhengqiwen1997 Dec 8, 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
148 changes: 0 additions & 148 deletions python/paddle/fluid/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
from .initializer import Constant
from .layers import detection

__all__ = [
'DetectionMAP',
]


def _clone_var_(block, var):
assert isinstance(var, Variable)
Expand Down Expand Up @@ -124,147 +120,3 @@ def _create_state(self, suffix, dtype, shape):
)
self.states.append(state)
return state


class DetectionMAP(Evaluator):
"""
Warning: This would be deprecated in the future. Please use fluid.metrics.DetectionMAP
instead.
Calculate the detection mean average precision (mAP).

The general steps are as follows:
1. calculate the true positive and false positive according to the input
of detection and labels.
2. calculate mAP value, support two versions: '11 point' and 'integral'.

Please get more information from the following articles:
https://sanchom.wordpress.com/tag/average-precision/
https://arxiv.org/abs/1512.02325

Args:
input (Variable): The detection results, which is a LoDTensor with shape
[M, 6]. The layout is [label, confidence, xmin, ymin, xmax, ymax].
gt_label (Variable): The ground truth label index, which is a LoDTensor
with shape [N, 1].
gt_box (Variable): The ground truth bounding box (bbox), which is a
LoDTensor with shape [N, 4]. The layout is [xmin, ymin, xmax, ymax].
gt_difficult (Variable|None): Whether this ground truth is a difficult
bounding bbox, which can be a LoDTensor [N, 1] or not set. If None,
it means all the ground truth labels are not difficult bbox.
class_num (int): The class number.
background_label (int): The index of background label, the background
label will be ignored. If set to -1, then all categories will be
considered, 0 by default.
overlap_threshold (float): The threshold for deciding true/false
positive, 0.5 by default.
evaluate_difficult (bool): Whether to consider difficult ground truth
for evaluation, True by default. This argument does not work when
gt_difficult is None.
ap_version (string): The average precision calculation ways, it must be
'integral' or '11point'. Please check
https://sanchom.wordpress.com/tag/average-precision/ for details.
- 11point: the 11-point interpolated average precision.
- integral: the natural integral of the precision-recall curve.

Examples:
.. code-block:: python

exe = fluid.executor(place)
map_evaluator = fluid.Evaluator.DetectionMAP(input,
gt_label, gt_box, gt_difficult)
cur_map, accum_map = map_evaluator.get_map_var()
fetch = [cost, cur_map, accum_map]
for epoch in PASS_NUM:
map_evaluator.reset(exe)
for data in batches:
loss, cur_map_v, accum_map_v = exe.run(fetch_list=fetch)

In the above example:

'cur_map_v' is the mAP of current mini-batch.
'accum_map_v' is the accumulative mAP of one pass.
"""

def __init__(
self,
input,
gt_label,
gt_box,
gt_difficult=None,
class_num=None,
background_label=0,
overlap_threshold=0.5,
evaluate_difficult=True,
ap_version='integral',
):
super().__init__("map_eval")

gt_label = layers.cast(x=gt_label, dtype=gt_box.dtype)
if gt_difficult:
gt_difficult = layers.cast(x=gt_difficult, dtype=gt_box.dtype)
label = layers.concat([gt_label, gt_difficult, gt_box], axis=1)
else:
label = layers.concat([gt_label, gt_box], axis=1)

# calculate mean average precision (mAP) of current mini-batch
map = detection.detection_map(
input,
label,
class_num,
background_label,
overlap_threshold=overlap_threshold,
evaluate_difficult=evaluate_difficult,
ap_version=ap_version,
)

self._create_state(dtype='int32', shape=None, suffix='accum_pos_count')
self._create_state(dtype='float32', shape=None, suffix='accum_true_pos')
self._create_state(
dtype='float32', shape=None, suffix='accum_false_pos'
)

self.has_state = None
var = self.helper.create_variable(
persistable=True, dtype='int32', shape=[1]
)
self.helper.set_variable_initializer(
var, initializer=Constant(value=int(0))
)
self.has_state = var

# calculate accumulative mAP
accum_map = detection.detection_map(
input,
label,
class_num,
background_label,
overlap_threshold=overlap_threshold,
evaluate_difficult=evaluate_difficult,
has_state=self.has_state,
input_states=self.states,
out_states=self.states,
ap_version=ap_version,
)

layers.fill_constant(
shape=self.has_state.shape,
value=1,
dtype=self.has_state.dtype,
out=self.has_state,
)

self.cur_map = map
self.accum_map = accum_map

def get_map_var(self):
return self.cur_map, self.accum_map

def reset(self, executor, reset_program=None):
if reset_program is None:
reset_program = Program()
with program_guard(main_program=reset_program):
var = _clone_var_(reset_program.current_block(), self.has_state)
layers.fill_constant(
shape=var.shape, value=0, dtype=var.dtype, out=var
)
executor.run(reset_program)
100 changes: 0 additions & 100 deletions python/paddle/fluid/layers/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,106 +231,6 @@ def polygon_box_transform(input, name=None):
return output


@templatedoc()
def detection_map(
detect_res,
label,
class_num,
background_label=0,
overlap_threshold=0.3,
evaluate_difficult=True,
has_state=None,
input_states=None,
out_states=None,
ap_version='integral',
):
"""
${comment}

Args:
detect_res: ${detect_res_comment}
label: ${label_comment}
class_num: ${class_num_comment}
background_label: ${background_label_comment}
overlap_threshold: ${overlap_threshold_comment}
evaluate_difficult: ${evaluate_difficult_comment}
has_state: ${has_state_comment}
input_states: (tuple|None) If not None, It contains 3 elements:
(1) pos_count ${pos_count_comment}.
(2) true_pos ${true_pos_comment}.
(3) false_pos ${false_pos_comment}.
out_states: (tuple|None) If not None, it contains 3 elements.
(1) accum_pos_count ${accum_pos_count_comment}.
(2) accum_true_pos ${accum_true_pos_comment}.
(3) accum_false_pos ${accum_false_pos_comment}.
ap_version: ${ap_type_comment}

Returns:
${map_comment}


Examples:
.. code-block:: python

import paddle.fluid as fluid
from fluid.layers import detection
detect_res = fluid.data(
name='detect_res',
shape=[10, 6],
dtype='float32')
label = fluid.data(
name='label',
shape=[10, 6],
dtype='float32')

map_out = detection.detection_map(detect_res, label, 21)
"""
helper = LayerHelper("detection_map", **locals())

def __create_var(type):
return helper.create_variable_for_type_inference(dtype=type)

map_out = __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 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",
inputs={
'Label': label,
'DetectRes': detect_res,
'HasState': has_state,
'PosCount': pos_count,
'TruePos': true_pos,
'FalsePos': false_pos,
},
outputs={
'MAP': map_out,
'AccumPosCount': accum_pos_count_out,
'AccumTruePos': accum_true_pos_out,
'AccumFalsePos': accum_false_pos_out,
},
attrs={
'overlap_threshold': overlap_threshold,
'evaluate_difficult': evaluate_difficult,
'ap_type': ap_version,
'class_num': class_num,
},
)
return map_out


def prior_box(
input,
image,
Expand Down
Loading