Skip to content

Commit

Permalink
RandomResize op
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookresearch/d2go#384

Random resize augmentation. Randomly pick a scale from the shape_list and resize to that scale.

  D2 (facebookresearch@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
  • Loading branch information
Zecheng He authored and facebook-github-bot committed Oct 20, 2022
1 parent 998c4e1 commit 32bd159
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions detectron2/data/transforms/augmentation_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ResizeScale",
"ResizeShortestEdge",
"RandomCrop_CategoryAreaConstraint",
"RandomResize",
]


Expand Down Expand Up @@ -626,3 +627,21 @@ def get_transform(self, image):
return BlendTransform(
src_image=self.eigen_vecs.dot(weights * self.eigen_vals), src_weight=1.0, dst_weight=1.0
)


class RandomResize(Augmentation):
"""Randomly resize image to a target size in shape_list"""

def __init__(self, shape_list, interp=Image.BILINEAR):
"""
Args:
shape_list: a list of shapes in (h, w)
interp: PIL interpolation method
"""
self.shape_list = shape_list
self._init(locals())

def get_transform(self, image):
shape_idx = np.random.randint(low=0, high=len(self.shape_list))
h, w = self.shape_list[shape_idx]
return ResizeTransform(image.shape[0], image.shape[1], h, w, self.interp)

0 comments on commit 32bd159

Please sign in to comment.