Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
dd04e547
Commit
dd04e547
authored
Oct 14, 2020
by
Jonathan Huang
Committed by
TF Object Detection Team
Oct 14, 2020
Browse files
Plumb `is_crowd` flag into COCO Mask eval
PiperOrigin-RevId: 337134017
parent
87e4768e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
research/object_detection/metrics/coco_evaluation.py
research/object_detection/metrics/coco_evaluation.py
+18
-1
research/object_detection/metrics/coco_evaluation_test.py
research/object_detection/metrics/coco_evaluation_test.py
+35
-0
No files found.
research/object_detection/metrics/coco_evaluation.py
View file @
dd04e547
...
...
@@ -997,12 +997,27 @@ class CocoMaskEvaluator(object_detection_evaluation.DetectionEvaluator):
[num_boxes, image_height, image_width] containing groundtruth masks
corresponding to the boxes. The elements of the array must be in
{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
:
tf
.
logging
.
warning
(
'Ignoring ground truth with image id %s since it was '
'previously added'
,
image_id
)
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
[
standard_fields
.
InputDataFields
.
groundtruth_instance_masks
]
groundtruth_instance_masks
=
convert_masks_to_binary
(
...
...
@@ -1018,7 +1033,9 @@ class CocoMaskEvaluator(object_detection_evaluation.DetectionEvaluator):
groundtruth_classes
=
groundtruth_dict
[
standard_fields
.
InputDataFields
.
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
.
groundtruth_boxes
].
shape
[
0
]
self
.
_image_id_to_mask_shape_map
[
image_id
]
=
groundtruth_dict
[
...
...
research/object_detection/metrics/coco_evaluation_test.py
View file @
dd04e547
...
...
@@ -1556,6 +1556,41 @@ class CocoMaskEvaluationTest(tf.test.TestCase):
self
.
assertFalse
(
coco_evaluator
.
_groundtruth_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'
)
class
CocoMaskEvaluationPyFuncTest
(
tf
.
test
.
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment