Unverified Commit f97d361d authored by Kai Chen's avatar Kai Chen Committed by GitHub
Browse files

bug fix for mask resizing when aspect ratio is unfixed (#1050)

parent f730b408
...@@ -34,8 +34,8 @@ class ImageTransform(object): ...@@ -34,8 +34,8 @@ class ImageTransform(object):
else: else:
img, w_scale, h_scale = mmcv.imresize( img, w_scale, h_scale = mmcv.imresize(
img, scale, return_scale=True) img, scale, return_scale=True)
scale_factor = np.array( scale_factor = np.array([w_scale, h_scale, w_scale, h_scale],
[w_scale, h_scale, w_scale, h_scale], dtype=np.float32) dtype=np.float32)
img_shape = img.shape img_shape = img.shape
img = mmcv.imnormalize(img, self.mean, self.std, self.to_rgb) img = mmcv.imnormalize(img, self.mean, self.std, self.to_rgb)
if flip: if flip:
...@@ -99,10 +99,24 @@ class MaskTransform(object): ...@@ -99,10 +99,24 @@ class MaskTransform(object):
""" """
def __call__(self, masks, pad_shape, scale_factor, flip=False): def __call__(self, masks, pad_shape, scale_factor, flip=False):
masks = [ # aspect ratio unchanged
mmcv.imrescale(mask, scale_factor, interpolation='nearest') if isinstance(scale_factor, float):
for mask in masks masks = [
] mmcv.imrescale(mask, scale_factor, interpolation='nearest')
for mask in masks
]
# aspect ratio changed
else:
w_ratio, h_ratio = scale_factor[:2]
if masks:
h, w = masks[0].shape[:2]
new_h = int(np.round(h * h_ratio))
new_w = int(np.round(w * w_ratio))
new_size = (new_w, new_h)
masks = [
mmcv.imresize(mask, new_size, interpolation='nearest')
for mask in masks
]
if flip: if flip:
masks = [mask[:, ::-1] for mask in masks] masks = [mask[:, ::-1] for mask in masks]
padded_masks = [ padded_masks = [
......
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