Skip to content

Commit 4437d7b

Browse files
Jonathan HuangTF Object Detection Team
Jonathan Huang
authored and
TF Object Detection Team
committed
Add support for LVIS metrics.
PiperOrigin-RevId: 339190667
1 parent b1809d9 commit 4437d7b

10 files changed

+1085
-9
lines changed

research/object_detection/core/standard_fields.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class InputDataFields(object):
7070
groundtruth_keypoint_visibilities: ground truth keypoint visibilities.
7171
groundtruth_keypoint_weights: groundtruth weight factor for keypoints.
7272
groundtruth_label_weights: groundtruth label weights.
73+
groundtruth_verified_negative_classes: groundtruth verified negative classes
74+
groundtruth_not_exhaustive_classes: groundtruth not-exhaustively labeled
75+
classes.
7376
groundtruth_weights: groundtruth weight factor for bounding boxes.
7477
groundtruth_dp_num_points: The number of DensePose sampled points for each
7578
instance.
@@ -120,6 +123,8 @@ class InputDataFields(object):
120123
groundtruth_keypoint_visibilities = 'groundtruth_keypoint_visibilities'
121124
groundtruth_keypoint_weights = 'groundtruth_keypoint_weights'
122125
groundtruth_label_weights = 'groundtruth_label_weights'
126+
groundtruth_verified_neg_classes = 'groundtruth_verified_neg_classes'
127+
groundtruth_not_exhaustive_classes = 'groundtruth_not_exhaustive_classes'
123128
groundtruth_weights = 'groundtruth_weights'
124129
groundtruth_dp_num_points = 'groundtruth_dp_num_points'
125130
groundtruth_dp_part_ids = 'groundtruth_dp_part_ids'

research/object_detection/eval_util_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def _make_evaluation_dict(self,
8585
groundtruth_boxes = tf.constant([[0., 0., 1., 1.]])
8686
groundtruth_classes = tf.constant([1])
8787
groundtruth_instance_masks = tf.ones(shape=[1, 20, 20], dtype=tf.uint8)
88+
original_image_spatial_shapes = tf.constant([[20, 20]], dtype=tf.int32)
89+
8890
groundtruth_keypoints = tf.constant([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])
8991
if resized_groundtruth_masks:
9092
groundtruth_instance_masks = tf.ones(shape=[1, 10, 10], dtype=tf.uint8)
@@ -100,6 +102,8 @@ def _make_evaluation_dict(self,
100102
groundtruth_keypoints = tf.tile(
101103
tf.expand_dims(groundtruth_keypoints, 0),
102104
multiples=[batch_size, 1, 1])
105+
original_image_spatial_shapes = tf.tile(original_image_spatial_shapes,
106+
multiples=[batch_size, 1])
103107

104108
detections = {
105109
detection_fields.detection_boxes: detection_boxes,
@@ -112,7 +116,10 @@ def _make_evaluation_dict(self,
112116
input_data_fields.groundtruth_boxes: groundtruth_boxes,
113117
input_data_fields.groundtruth_classes: groundtruth_classes,
114118
input_data_fields.groundtruth_keypoints: groundtruth_keypoints,
115-
input_data_fields.groundtruth_instance_masks: groundtruth_instance_masks
119+
input_data_fields.groundtruth_instance_masks:
120+
groundtruth_instance_masks,
121+
input_data_fields.original_image_spatial_shape:
122+
original_image_spatial_shapes
116123
}
117124
if batch_size > 1:
118125
return eval_util.result_dict_for_batched_example(

research/object_detection/metrics/coco_evaluation.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,40 +1191,46 @@ def update_op(image_id_batched, groundtruth_boxes_batched,
11911191
groundtruth_instance_masks_batched,
11921192
groundtruth_is_crowd_batched, num_gt_boxes_per_image,
11931193
detection_scores_batched, detection_classes_batched,
1194-
detection_masks_batched, num_det_boxes_per_image):
1194+
detection_masks_batched, num_det_boxes_per_image,
1195+
original_image_spatial_shape):
11951196
"""Update op for metrics."""
11961197

11971198
for (image_id, groundtruth_boxes, groundtruth_classes,
11981199
groundtruth_instance_masks, groundtruth_is_crowd, num_gt_box,
11991200
detection_scores, detection_classes,
1200-
detection_masks, num_det_box) in zip(
1201+
detection_masks, num_det_box, original_image_shape) in zip(
12011202
image_id_batched, groundtruth_boxes_batched,
12021203
groundtruth_classes_batched, groundtruth_instance_masks_batched,
12031204
groundtruth_is_crowd_batched, num_gt_boxes_per_image,
12041205
detection_scores_batched, detection_classes_batched,
1205-
detection_masks_batched, num_det_boxes_per_image):
1206+
detection_masks_batched, num_det_boxes_per_image,
1207+
original_image_spatial_shape):
12061208
self.add_single_ground_truth_image_info(
12071209
image_id, {
12081210
'groundtruth_boxes':
12091211
groundtruth_boxes[:num_gt_box],
12101212
'groundtruth_classes':
12111213
groundtruth_classes[:num_gt_box],
12121214
'groundtruth_instance_masks':
1213-
groundtruth_instance_masks[:num_gt_box],
1215+
groundtruth_instance_masks[:num_gt_box][
1216+
:original_image_shape[0], :original_image_shape[1]],
12141217
'groundtruth_is_crowd':
12151218
groundtruth_is_crowd[:num_gt_box]
12161219
})
12171220
self.add_single_detected_image_info(
12181221
image_id, {
12191222
'detection_scores': detection_scores[:num_det_box],
12201223
'detection_classes': detection_classes[:num_det_box],
1221-
'detection_masks': detection_masks[:num_det_box]
1224+
'detection_masks': detection_masks[:num_det_box][
1225+
:original_image_shape[0], :original_image_shape[1]]
12221226
})
12231227

12241228
# Unpack items from the evaluation dictionary.
12251229
input_data_fields = standard_fields.InputDataFields
12261230
detection_fields = standard_fields.DetectionResultFields
12271231
image_id = eval_dict[input_data_fields.key]
1232+
original_image_spatial_shape = eval_dict[
1233+
input_data_fields.original_image_spatial_shape]
12281234
groundtruth_boxes = eval_dict[input_data_fields.groundtruth_boxes]
12291235
groundtruth_classes = eval_dict[input_data_fields.groundtruth_classes]
12301236
groundtruth_instance_masks = eval_dict[
@@ -1276,7 +1282,7 @@ def update_op(image_id_batched, groundtruth_boxes_batched,
12761282
image_id, groundtruth_boxes, groundtruth_classes,
12771283
groundtruth_instance_masks, groundtruth_is_crowd,
12781284
num_gt_boxes_per_image, detection_scores, detection_classes,
1279-
detection_masks, num_det_boxes_per_image
1285+
detection_masks, num_det_boxes_per_image, original_image_spatial_shape
12801286
], [])
12811287

12821288
def get_estimator_eval_metric_ops(self, eval_dict):

research/object_detection/metrics/coco_evaluation_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,7 @@ def testAddEvalDict(self):
16011601
groundtruth_boxes = tf.placeholder(tf.float32, shape=(None, 4))
16021602
groundtruth_classes = tf.placeholder(tf.float32, shape=(None))
16031603
groundtruth_masks = tf.placeholder(tf.uint8, shape=(None, None, None))
1604+
original_image_spatial_shape = tf.placeholder(tf.int32, shape=(None, 2))
16041605
detection_scores = tf.placeholder(tf.float32, shape=(None))
16051606
detection_classes = tf.placeholder(tf.float32, shape=(None))
16061607
detection_masks = tf.placeholder(tf.uint8, shape=(None, None, None))
@@ -1612,6 +1613,8 @@ def testAddEvalDict(self):
16121613
input_data_fields.groundtruth_boxes: groundtruth_boxes,
16131614
input_data_fields.groundtruth_classes: groundtruth_classes,
16141615
input_data_fields.groundtruth_instance_masks: groundtruth_masks,
1616+
input_data_fields.original_image_spatial_shape:
1617+
original_image_spatial_shape,
16151618
detection_fields.detection_scores: detection_scores,
16161619
detection_fields.detection_classes: detection_classes,
16171620
detection_fields.detection_masks: detection_masks,
@@ -1637,6 +1640,7 @@ def testAddEvalDict(self):
16371640
np.ones([50, 50], dtype=np.uint8), ((0, 70), (0, 70)),
16381641
mode='constant')
16391642
]),
1643+
original_image_spatial_shape: np.array([[120, 120]]),
16401644
detection_scores:
16411645
np.array([.9, .8]),
16421646
detection_classes:
@@ -1661,6 +1665,7 @@ def testGetOneMAPWithMatchingGroundtruthAndDetections(self):
16611665
groundtruth_boxes = tf.placeholder(tf.float32, shape=(None, 4))
16621666
groundtruth_classes = tf.placeholder(tf.float32, shape=(None))
16631667
groundtruth_masks = tf.placeholder(tf.uint8, shape=(None, None, None))
1668+
original_image_spatial_shape = tf.placeholder(tf.int32, shape=(None, 2))
16641669
detection_scores = tf.placeholder(tf.float32, shape=(None))
16651670
detection_classes = tf.placeholder(tf.float32, shape=(None))
16661671
detection_masks = tf.placeholder(tf.uint8, shape=(None, None, None))
@@ -1672,6 +1677,8 @@ def testGetOneMAPWithMatchingGroundtruthAndDetections(self):
16721677
input_data_fields.groundtruth_boxes: groundtruth_boxes,
16731678
input_data_fields.groundtruth_classes: groundtruth_classes,
16741679
input_data_fields.groundtruth_instance_masks: groundtruth_masks,
1680+
input_data_fields.original_image_spatial_shape:
1681+
original_image_spatial_shape,
16751682
detection_fields.detection_scores: detection_scores,
16761683
detection_fields.detection_classes: detection_classes,
16771684
detection_fields.detection_masks: detection_masks,
@@ -1701,6 +1708,7 @@ def testGetOneMAPWithMatchingGroundtruthAndDetections(self):
17011708
np.ones([50, 50], dtype=np.uint8), ((0, 70), (0, 70)),
17021709
mode='constant')
17031710
]),
1711+
original_image_spatial_shape: np.array([[120, 120], [120, 120]]),
17041712
detection_scores:
17051713
np.array([.9, .8]),
17061714
detection_classes:
@@ -1725,6 +1733,7 @@ def testGetOneMAPWithMatchingGroundtruthAndDetections(self):
17251733
dtype=np.uint8),
17261734
((0, 0), (10, 10), (10, 10)),
17271735
mode='constant'),
1736+
original_image_spatial_shape: np.array([[70, 70]]),
17281737
detection_scores: np.array([.8]),
17291738
detection_classes: np.array([1]),
17301739
detection_masks: np.pad(np.ones([1, 50, 50], dtype=np.uint8),
@@ -1740,6 +1749,7 @@ def testGetOneMAPWithMatchingGroundtruthAndDetections(self):
17401749
dtype=np.uint8),
17411750
((0, 0), (10, 10), (10, 10)),
17421751
mode='constant'),
1752+
original_image_spatial_shape: np.array([[45, 45]]),
17431753
detection_scores: np.array([.8]),
17441754
detection_classes: np.array([1]),
17451755
detection_masks: np.pad(np.ones([1, 25, 25],
@@ -1778,6 +1788,7 @@ def testGetOneMAPWithMatchingGroundtruthAndDetectionsBatched(self):
17781788
groundtruth_classes = tf.placeholder(tf.float32, shape=(batch_size, None))
17791789
groundtruth_masks = tf.placeholder(
17801790
tf.uint8, shape=(batch_size, None, None, None))
1791+
original_image_spatial_shape = tf.placeholder(tf.int32, shape=(None, 2))
17811792
detection_scores = tf.placeholder(tf.float32, shape=(batch_size, None))
17821793
detection_classes = tf.placeholder(tf.float32, shape=(batch_size, None))
17831794
detection_masks = tf.placeholder(
@@ -1790,6 +1801,8 @@ def testGetOneMAPWithMatchingGroundtruthAndDetectionsBatched(self):
17901801
input_data_fields.groundtruth_boxes: groundtruth_boxes,
17911802
input_data_fields.groundtruth_classes: groundtruth_classes,
17921803
input_data_fields.groundtruth_instance_masks: groundtruth_masks,
1804+
input_data_fields.original_image_spatial_shape:
1805+
original_image_spatial_shape,
17931806
detection_fields.detection_scores: detection_scores,
17941807
detection_fields.detection_classes: detection_classes,
17951808
detection_fields.detection_masks: detection_masks,
@@ -1826,6 +1839,8 @@ def testGetOneMAPWithMatchingGroundtruthAndDetectionsBatched(self):
18261839
mode='constant')
18271840
],
18281841
axis=0),
1842+
original_image_spatial_shape: np.array(
1843+
[[100, 100], [100, 100], [100, 100]]),
18291844
detection_scores:
18301845
np.array([[.8], [.8], [.8]]),
18311846
detection_classes:

0 commit comments

Comments
 (0)