Commit 4c643114 authored by Zecheng He's avatar Zecheng He Committed by Facebook GitHub Bot
Browse files

Add deterministic instance option in RandomInstanceCrop augmentation

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/269

Add deterministic instance option in RandomInstanceCrop. This feature can be useful for two-step model evaluation as every time we make the cropped instance deterministic.

Reviewed By: wat3rBro

Differential Revision: D36850404

fbshipit-source-id: ba6c0d9df0849e0110037f9d839b1c48f48096ad
parent 68934eb4
...@@ -182,7 +182,9 @@ def RandomCropFixedAspectRatioOp( ...@@ -182,7 +182,9 @@ def RandomCropFixedAspectRatioOp(
class RandomInstanceCrop(aug.Augmentation): class RandomInstanceCrop(aug.Augmentation):
def __init__(self, crop_scale: Tuple[float, float] = (0.8, 1.6)): def __init__(
self, crop_scale: Tuple[float, float] = (0.8, 1.6), fix_instance=False
):
""" """
Generates a CropTransform centered around the instance. Generates a CropTransform centered around the instance.
crop_scale: [low, high] relative crop scale around the instance, this crop_scale: [low, high] relative crop scale around the instance, this
...@@ -190,6 +192,7 @@ class RandomInstanceCrop(aug.Augmentation): ...@@ -190,6 +192,7 @@ class RandomInstanceCrop(aug.Augmentation):
""" """
super().__init__() super().__init__()
self.crop_scale = crop_scale self.crop_scale = crop_scale
self.fix_instance = fix_instance
assert ( assert (
isinstance(crop_scale, (list, tuple)) and len(crop_scale) == 2 isinstance(crop_scale, (list, tuple)) and len(crop_scale) == 2
), crop_scale ), crop_scale
...@@ -211,7 +214,10 @@ class RandomInstanceCrop(aug.Augmentation): ...@@ -211,7 +214,10 @@ class RandomInstanceCrop(aug.Augmentation):
if len(annotations) == 0: if len(annotations) == 0:
return NoOpTransform() return NoOpTransform()
sel_index = np.random.randint(len(annotations)) if not self.fix_instance:
sel_index = np.random.randint(len(annotations))
else:
sel_index = 0
# set iscrowd flag of other annotations to 1 so that they will be # set iscrowd flag of other annotations to 1 so that they will be
# filtered out by the datset mapper (https://fburl.com/diffusion/fg64cb4h) # filtered out by the datset mapper (https://fburl.com/diffusion/fg64cb4h)
for idx, instance in enumerate(annotations): for idx, instance in enumerate(annotations):
......
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