未验证 提交 baa1f663 编写于 作者: V Vvsmile 提交者: GitHub

Remove API: mean_iou (#47971)

remove mean_iou which is not used in paddle 2.0
上级 b7d3143f
......@@ -114,7 +114,6 @@ __all__ = [
'gather_nd',
'scatter',
'random_crop',
'mean_iou',
'relu',
'log',
'crop_tensor',
......@@ -7626,73 +7625,6 @@ def relu(x, name=None):
return out
def mean_iou(input, label, num_classes):
r"""
Mean Intersection-Over-Union is a common evaluation metric for
semantic image segmentation, which first computes the IOU for each
semantic class and then computes the average over classes.
IOU is defined as follows:
.. math::
IOU = \\frac{true\_positive}{(true\_positive + false\_positive + false\_negative)}.
The predictions are accumulated in a confusion matrix and mean-IOU
is then calculated from it.
Parameters:
input (Tensor): A n-D Tensor of prediction results for semantic labels with type int32 or int64.
label (Tensor): A Tensor of ground truth labels with type int32 or int64.
Its shape should be the same as input.
num_classes (int32): The possible number of labels.
Returns:
Three Tensors.
- mean_iou(Tensor) : A 1-D Tensor representing the mean intersection-over-union with shape [1]. \
Data type is float32.
- out_wrong(Tensor) : A 1-D Tensor with shape [num_classes]. Data type is int32. \
The wrong numbers of each class.
- out_correct(Tensor): A 1-D Tensor with shape [num_classes]. Data type is int32. The correct numbers of each class.
Examples:
.. code-block:: python
import paddle
iou_shape = [64, 32, 32]
num_classes = 5
predict = paddle.randint(low=0, high=255, shape=iou_shape, dtype='int64')
label = paddle.randint(low=0, high=255, shape=iou_shape, dtype='int64')
mean_iou, out_wrong, out_correct = paddle.metric.mean_iou(predict, label, num_classes)
"""
if _non_static_mode():
return _legacy_C_ops.mean_iou(input, label, 'num_classes', num_classes)
helper = LayerHelper('mean_iou', **locals())
check_variable_and_dtype(
input, 'Predictions', ['int32', 'int64'], 'mean_iou'
)
check_variable_and_dtype(label, 'Labels', ['int32', 'int64'], 'mean_iou')
out_mean_iou = helper.create_variable_for_type_inference(dtype='float32')
out_wrong = helper.create_variable_for_type_inference(dtype='int32')
out_correct = helper.create_variable_for_type_inference(dtype='int32')
helper.append_op(
type="mean_iou",
inputs={"Predictions": input, "Labels": label},
outputs={
"OutMeanIou": out_mean_iou,
"OutWrong": out_wrong,
"OutCorrect": out_correct,
},
attrs={"num_classes": num_classes},
)
return out_mean_iou, out_wrong, out_correct
def crop_tensor(x, shape=None, offsets=None, name=None):
"""
Crop input into output, as specified by offsets and shape.
......
......@@ -3476,13 +3476,6 @@ class TestBook(LayerTest):
output = layers.l2_normalize(x, axis=1)
return output
def make_mean_iou(self):
with fluid.framework._dygraph_place_guard(place=fluid.CPUPlace()):
x = self._get_data(name='x', shape=[16], dtype='int32')
y = self._get_data(name='label', shape=[16], dtype='int32')
iou = layers.mean_iou(x, y, self._high_data_bound)
return iou
def make_argsort(self):
with program_guard(
fluid.default_main_program(), fluid.default_startup_program()
......
......@@ -15,7 +15,6 @@
import unittest
import numpy as np
from op_test import OpTest
import paddle.fluid as fluid
def compute_mean_iou(
......@@ -140,22 +139,5 @@ class TestCase1(TestMeanIOUOp):
self.check_output(check_dygraph=False, check_eager=False)
class TestMeanIOUOpError(unittest.TestCase):
def test_errors(self):
with fluid.program_guard(fluid.Program(), fluid.Program()):
# The input type of accuracy_op must be Variable.
x1 = fluid.create_lod_tensor(
np.array([[-1]]), [[1]], fluid.CPUPlace()
)
y1 = fluid.create_lod_tensor(
np.array([[-1]]), [[1]], fluid.CPUPlace()
)
self.assertRaises(TypeError, fluid.layers.mean_iou, x1, y1)
# The input dtype of accuracy_op must be float32 or float64.
x2 = fluid.layers.data(name='x2', shape=[4], dtype="float32")
y2 = fluid.layers.data(name='x2', shape=[4], dtype="float32")
self.assertRaises(TypeError, fluid.layers.mean_iou, x2, y2)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册