Skip to content

Commit 32bd159

Browse files
Zecheng Hefacebook-github-bot
authored andcommitted
RandomResize op
Summary: X-link: facebookresearch/d2go#384 Random resize augmentation. Randomly pick a scale from the shape_list and resize to that scale. D2 (11528ce083dc9ff83ee3a8f9086a1ef54d2a402f)GO_DATA: AUG_OPS: TRAIN: [ RandomResizeOp::{"shape_list": [[224, 224], [256, 256], [320, 320]]} ] Reviewed By: XiaoliangDai Differential Revision: D40230332 fbshipit-source-id: 60a48f85240aef673033d48db4662899dc90bef4
1 parent 998c4e1 commit 32bd159

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

detectron2/data/transforms/augmentation_impl.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"ResizeScale",
3838
"ResizeShortestEdge",
3939
"RandomCrop_CategoryAreaConstraint",
40+
"RandomResize",
4041
]
4142

4243

@@ -626,3 +627,21 @@ def get_transform(self, image):
626627
return BlendTransform(
627628
src_image=self.eigen_vecs.dot(weights * self.eigen_vals), src_weight=1.0, dst_weight=1.0
628629
)
630+
631+
632+
class RandomResize(Augmentation):
633+
"""Randomly resize image to a target size in shape_list"""
634+
635+
def __init__(self, shape_list, interp=Image.BILINEAR):
636+
"""
637+
Args:
638+
shape_list: a list of shapes in (h, w)
639+
interp: PIL interpolation method
640+
"""
641+
self.shape_list = shape_list
642+
self._init(locals())
643+
644+
def get_transform(self, image):
645+
shape_idx = np.random.randint(low=0, high=len(self.shape_list))
646+
h, w = self.shape_list[shape_idx]
647+
return ResizeTransform(image.shape[0], image.shape[1], h, w, self.interp)

0 commit comments

Comments
 (0)