Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add min_size arg in Resize to keep the shape after resize bigger than slide window #1318

Merged
merged 15 commits into from
Mar 1, 2022
19 changes: 18 additions & 1 deletion mmseg/datasets/pipelines/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def __init__(self,
img_scale=None,
multiscale_mode='range',
ratio_range=None,
keep_ratio=True):
keep_ratio=True,
crop_size=None,
setr_multi_scale=False):
linfangjian01 marked this conversation as resolved.
Show resolved Hide resolved
if img_scale is None:
self.img_scale = None
else:
Expand All @@ -126,6 +128,8 @@ def __init__(self,
self.multiscale_mode = multiscale_mode
self.ratio_range = ratio_range
self.keep_ratio = keep_ratio
self.crop_size = crop_size
self.setr_multi_scale = setr_multi_scale

@staticmethod
def random_select(img_scales):
Expand Down Expand Up @@ -240,6 +244,19 @@ def _random_scale(self, results):
def _resize_img(self, results):
"""Resize images with ``results['scale']``."""
if self.keep_ratio:
if self.setr_multi_scale:
linfangjian01 marked this conversation as resolved.
Show resolved Hide resolved
if min(results['scale']) < self.crop_size[0]:
new_short = self.crop_size[0]
else:
new_short = min(results['scale'])

h, w = results['img'].shape[:2]
if h > w:
new_h, new_w = new_short * h / w, new_short
else:
new_h, new_w = new_short, new_short * w / h
results['scale'] = (new_h, new_w)

img, scale_factor = mmcv.imrescale(
results['img'], results['scale'], return_scale=True)
# the w_scale and h_scale has minor difference
Expand Down