D2 Instance Utility Change
Summary: Adds option for returning indexing of filtered instances. Used in MaskTrackRCNN implementation (D29564369) when computing ground truth and reference instance ids.
@@ -458,7 +458,9 @@ def annotations_to_instances_rotated(annos, image_size):
return target
-def filter_empty_instances(instances, by_box=True, by_mask=True, box_threshold=1e-5):
+def filter_empty_instances(
+ instances, by_box=True, by_mask=True, box_threshold=1e-5, return_mask=False
+):
"""
Filter out empty instances in an `Instances` object.
@@ -467,9 +469,11 @@ def filter_empty_instances(instances, by_box=True, by_mask=True, box_threshold=1
by_box (bool): whether to filter out instances with empty boxes
by_mask (bool): whether to filter out instances with empty masks
box_threshold (float): minimum width and height to be considered non-empty
+ return_mask (bool): whether to return boolean mask of filtered instances
Returns:
Instances: the filtered instances.
+ tensor[bool], optional: boolean mask of filtered instances
"""
assert by_box or by_mask
r = []
@@ -485,6 +489,8 @@ def filter_empty_instances(instances, by_box=True, by_mask=True, box_threshold=1
m = r[0]
for x in r[1:]:
m = m & x
+ if return_mask:
+ return instances[m], m
return instances[m]
