Commit dd04e547 authored by Jonathan Huang's avatar Jonathan Huang Committed by TF Object Detection Team
Browse files

Plumb `is_crowd` flag into COCO Mask eval

PiperOrigin-RevId: 337134017
parent 87e4768e
...@@ -997,12 +997,27 @@ class CocoMaskEvaluator(object_detection_evaluation.DetectionEvaluator): ...@@ -997,12 +997,27 @@ class CocoMaskEvaluator(object_detection_evaluation.DetectionEvaluator):
[num_boxes, image_height, image_width] containing groundtruth masks [num_boxes, image_height, image_width] containing groundtruth masks
corresponding to the boxes. The elements of the array must be in corresponding to the boxes. The elements of the array must be in
{0, 1}. {0, 1}.
InputDataFields.groundtruth_is_crowd (optional): integer numpy array of
shape [num_boxes] containing iscrowd flag for groundtruth boxes.
InputDataFields.groundtruth_area (optional): float numpy array of
shape [num_boxes] containing the area (in the original absolute
coordinates) of the annotated object.
""" """
if image_id in self._image_id_to_mask_shape_map: if image_id in self._image_id_to_mask_shape_map:
tf.logging.warning('Ignoring ground truth with image id %s since it was ' tf.logging.warning('Ignoring ground truth with image id %s since it was '
'previously added', image_id) 'previously added', image_id)
return return
# Drop optional fields if empty tensor.
groundtruth_is_crowd = groundtruth_dict.get(
standard_fields.InputDataFields.groundtruth_is_crowd)
groundtruth_area = groundtruth_dict.get(
standard_fields.InputDataFields.groundtruth_area)
if groundtruth_is_crowd is not None and not groundtruth_is_crowd.shape[0]:
groundtruth_is_crowd = None
if groundtruth_area is not None and not groundtruth_area.shape[0]:
groundtruth_area = None
groundtruth_instance_masks = groundtruth_dict[ groundtruth_instance_masks = groundtruth_dict[
standard_fields.InputDataFields.groundtruth_instance_masks] standard_fields.InputDataFields.groundtruth_instance_masks]
groundtruth_instance_masks = convert_masks_to_binary( groundtruth_instance_masks = convert_masks_to_binary(
...@@ -1018,7 +1033,9 @@ class CocoMaskEvaluator(object_detection_evaluation.DetectionEvaluator): ...@@ -1018,7 +1033,9 @@ class CocoMaskEvaluator(object_detection_evaluation.DetectionEvaluator):
groundtruth_classes=groundtruth_dict[standard_fields. groundtruth_classes=groundtruth_dict[standard_fields.
InputDataFields. InputDataFields.
groundtruth_classes], groundtruth_classes],
groundtruth_masks=groundtruth_instance_masks)) groundtruth_masks=groundtruth_instance_masks,
groundtruth_is_crowd=groundtruth_is_crowd,
groundtruth_area=groundtruth_area))
self._annotation_id += groundtruth_dict[standard_fields.InputDataFields. self._annotation_id += groundtruth_dict[standard_fields.InputDataFields.
groundtruth_boxes].shape[0] groundtruth_boxes].shape[0]
self._image_id_to_mask_shape_map[image_id] = groundtruth_dict[ self._image_id_to_mask_shape_map[image_id] = groundtruth_dict[
......
...@@ -1556,6 +1556,41 @@ class CocoMaskEvaluationTest(tf.test.TestCase): ...@@ -1556,6 +1556,41 @@ class CocoMaskEvaluationTest(tf.test.TestCase):
self.assertFalse(coco_evaluator._groundtruth_list) self.assertFalse(coco_evaluator._groundtruth_list)
self.assertFalse(coco_evaluator._detection_masks_list) self.assertFalse(coco_evaluator._detection_masks_list)
def testGetOneMAPWithMatchingGroundtruthAndDetectionsSkipCrowd(self):
"""Tests computing mAP with is_crowd GT boxes skipped."""
coco_evaluator = coco_evaluation.CocoMaskEvaluator(
_get_categories_list())
coco_evaluator.add_single_ground_truth_image_info(
image_id='image1',
groundtruth_dict={
standard_fields.InputDataFields.groundtruth_boxes:
np.array([[100., 100., 200., 200.], [99., 99., 200., 200.]]),
standard_fields.InputDataFields.groundtruth_classes:
np.array([1, 2]),
standard_fields.InputDataFields.groundtruth_is_crowd:
np.array([0, 1]),
standard_fields.InputDataFields.groundtruth_instance_masks:
np.concatenate(
[np.pad(np.ones([1, 100, 100], dtype=np.uint8),
((0, 0), (100, 56), (100, 56)), mode='constant'),
np.pad(np.ones([1, 101, 101], dtype=np.uint8),
((0, 0), (99, 56), (99, 56)), mode='constant')],
axis=0)
})
coco_evaluator.add_single_detected_image_info(
image_id='image1',
detections_dict={
standard_fields.DetectionResultFields.detection_scores:
np.array([.8]),
standard_fields.DetectionResultFields.detection_classes:
np.array([1]),
standard_fields.DetectionResultFields.detection_masks:
np.pad(np.ones([1, 100, 100], dtype=np.uint8),
((0, 0), (100, 56), (100, 56)), mode='constant')
})
metrics = coco_evaluator.evaluate()
self.assertAlmostEqual(metrics['DetectionMasks_Precision/mAP'], 1.0)
@unittest.skipIf(tf_version.is_tf2(), 'Only Supported in TF1.X') @unittest.skipIf(tf_version.is_tf2(), 'Only Supported in TF1.X')
class CocoMaskEvaluationPyFuncTest(tf.test.TestCase): class CocoMaskEvaluationPyFuncTest(tf.test.TestCase):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment