From b1f972b7a6236186465c4849e94e79a7422129d6 Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Sun, 9 Jan 2022 12:51:42 +0800 Subject: [PATCH 01/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index 5f4fa7cdb..b866b903a 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -204,8 +204,8 @@ def __call__(self, results): else: scale = (self.scale[-1], int(self.scale[-1] / w * h)) else: - # direct use the given ones - scale = self.scale + # direct use the given ones. + scale = self.scale[::-1] # here we assume all images in self.keys have the same input size for key in self.keys: From 159e5cec2b2bbfaa78843d32ea70b502cb0c637e Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Sun, 9 Jan 2022 17:13:34 +0800 Subject: [PATCH 02/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index b866b903a..4575a6ae3 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -204,7 +204,7 @@ def __call__(self, results): else: scale = (self.scale[-1], int(self.scale[-1] / w * h)) else: - # direct use the given ones. + # direct use the given ones scale = self.scale[::-1] # here we assume all images in self.keys have the same input size From b0ab0dd3537dbe7ad0dbc35893185929b1aa43ee Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Mon, 10 Jan 2022 13:23:21 +0800 Subject: [PATCH 03/11] Update lsun-car_pad_512.py --- configs/_base_/datasets/lsun-car_pad_512.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/_base_/datasets/lsun-car_pad_512.py b/configs/_base_/datasets/lsun-car_pad_512.py index a63592ab8..5fd104295 100644 --- a/configs/_base_/datasets/lsun-car_pad_512.py +++ b/configs/_base_/datasets/lsun-car_pad_512.py @@ -6,7 +6,7 @@ key='real_img', io_backend='disk', ), - dict(type='Resize', keys=['real_img'], scale=(512, 384)), + dict(type='Resize', keys=['real_img'], scale=(384, 512)), dict( type='NumpyPad', keys=['real_img'], From e98d5b88bbd32b6179452101715447704c65f7f6 Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Mon, 10 Jan 2022 13:23:45 +0800 Subject: [PATCH 04/11] Update imagenet_rgb.py --- configs/_base_/datasets/imagenet_rgb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/_base_/datasets/imagenet_rgb.py b/configs/_base_/datasets/imagenet_rgb.py index 87b3a65be..a0bcc1b93 100644 --- a/configs/_base_/datasets/imagenet_rgb.py +++ b/configs/_base_/datasets/imagenet_rgb.py @@ -16,7 +16,7 @@ test_pipeline = [ dict(type='LoadImageFromFile'), - dict(type='Resize', size=(256, -1), backend='pillow'), + dict(type='Resize', size=(-1, 256), backend='pillow'), dict(type='CenterCrop', crop_size=224), dict(type='Normalize', **img_norm_cfg), dict(type='ImageToTensor', keys=['img']), From 12568adeea29bf5b17f006b7ad1cda43cc30a507 Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Mon, 10 Jan 2022 13:30:36 +0800 Subject: [PATCH 05/11] Update imagenet_rgb.py --- configs/_base_/datasets/imagenet_rgb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/_base_/datasets/imagenet_rgb.py b/configs/_base_/datasets/imagenet_rgb.py index a0bcc1b93..87b3a65be 100644 --- a/configs/_base_/datasets/imagenet_rgb.py +++ b/configs/_base_/datasets/imagenet_rgb.py @@ -16,7 +16,7 @@ test_pipeline = [ dict(type='LoadImageFromFile'), - dict(type='Resize', size=(-1, 256), backend='pillow'), + dict(type='Resize', size=(256, -1), backend='pillow'), dict(type='CenterCrop', crop_size=224), dict(type='Normalize', **img_norm_cfg), dict(type='ImageToTensor', keys=['img']), From 41ea7987200d1b6269832e00c54d454994e79e8c Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Mon, 10 Jan 2022 15:46:29 +0800 Subject: [PATCH 06/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index 4575a6ae3..5d15dc9b3 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -169,7 +169,7 @@ def _resize(self, img, scale): else: img, w_scale, h_scale = mmcv.imresize( img, - scale, + scale[::-1], return_scale=True, interpolation=self.interpolation, backend=self.backend) @@ -205,7 +205,7 @@ def __call__(self, results): scale = (self.scale[-1], int(self.scale[-1] / w * h)) else: # direct use the given ones - scale = self.scale[::-1] + scale = self.scale # here we assume all images in self.keys have the same input size for key in self.keys: From 1246986d6d5eb5c5c468ae6c3a5886c87915fe06 Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Mon, 10 Jan 2022 17:29:40 +0800 Subject: [PATCH 07/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index 5d15dc9b3..ff102e6b6 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -169,7 +169,7 @@ def _resize(self, img, scale): else: img, w_scale, h_scale = mmcv.imresize( img, - scale[::-1], + scale, return_scale=True, interpolation=self.interpolation, backend=self.backend) @@ -205,7 +205,10 @@ def __call__(self, results): scale = (self.scale[-1], int(self.scale[-1] / w * h)) else: # direct use the given ones - scale = self.scale + if mmcv.is_tuple_of(self.scale, int): + scale = self.scale[::-1] + else: + scale = self.scale # here we assume all images in self.keys have the same input size for key in self.keys: From 6a263be1a8fbf2bf77aab4a272718e85b811bd3c Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Tue, 11 Jan 2022 16:06:29 +0800 Subject: [PATCH 08/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index ff102e6b6..212989245 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -128,13 +128,15 @@ def __init__(self, assert size_factor is not None, ( 'When max_size is used, ' f'size_factor should also be set. But received {size_factor}.') - if isinstance(scale, float): + if isinstance(scale, float, int): + assert keep_ratio, 'When scale is a single float/int, keep_ratio must be ture' if scale <= 0: raise ValueError(f'Invalid scale {scale}, must be positive.') elif mmcv.is_tuple_of(scale, int): max_long_edge = max(scale) max_short_edge = min(scale) if max_short_edge == -1: + assert keep_ratio, 'When scale includes a -1, keep_ratio must be ture' # assign np.inf to long edge for rescaling short edge later. scale = (np.inf, max_long_edge) elif scale is not None: @@ -208,7 +210,7 @@ def __call__(self, results): if mmcv.is_tuple_of(self.scale, int): scale = self.scale[::-1] else: - scale = self.scale + scale = float(self.scale) # here we assume all images in self.keys have the same input size for key in self.keys: From 880e94bc53ce668e632b7b8dcf07b042b0764b41 Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Tue, 11 Jan 2022 16:11:42 +0800 Subject: [PATCH 09/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index 212989245..d8560a8e7 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -198,19 +198,18 @@ def __call__(self, results): new_w = min(self.max_size - (self.max_size % self.size_factor), new_w) scale = (new_w, new_h) - elif isinstance(self.scale, tuple) and (np.inf in self.scale): + elif isinstance(self.scale, tuple): # find inf in self.scale, calculate ``scale`` manually - h, w = results[self.keys[0]].shape[:2] - if h < w: - scale = (int(self.scale[-1] / h * w), self.scale[-1]) + if np.inf in self.scale: + h, w = results[self.keys[0]].shape[:2] + if h < w: + scale = (int(self.scale[-1] / h * w), self.scale[-1]) + else: + scale = (self.scale[-1], int(self.scale[-1] / w * h)) else: - scale = (self.scale[-1], int(self.scale[-1] / w * h)) - else: - # direct use the given ones - if mmcv.is_tuple_of(self.scale, int): scale = self.scale[::-1] - else: - scale = float(self.scale) + else: + scale = float(self.scale) # here we assume all images in self.keys have the same input size for key in self.keys: From 156d50b0f08a112d5962710821629de2e5652d78 Mon Sep 17 00:00:00 2001 From: louis-4 Date: Tue, 11 Jan 2022 16:40:42 +0800 Subject: [PATCH 10/11] revise pre-commit --- mmgen/datasets/pipelines/augmentation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index d8560a8e7..d67f2fee4 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -129,14 +129,16 @@ def __init__(self, 'When max_size is used, ' f'size_factor should also be set. But received {size_factor}.') if isinstance(scale, float, int): - assert keep_ratio, 'When scale is a single float/int, keep_ratio must be ture' + assert keep_ratio, ('When scale is a single float/int,' + ' keep_ratio must be ture') if scale <= 0: raise ValueError(f'Invalid scale {scale}, must be positive.') elif mmcv.is_tuple_of(scale, int): max_long_edge = max(scale) max_short_edge = min(scale) if max_short_edge == -1: - assert keep_ratio, 'When scale includes a -1, keep_ratio must be ture' + assert keep_ratio, ('When scale includes a -1, ' + 'keep_ratio must be ture') # assign np.inf to long edge for rescaling short edge later. scale = (np.inf, max_long_edge) elif scale is not None: From 65644297e479b7fa0f58e9fa55cd0211cf1b828a Mon Sep 17 00:00:00 2001 From: makecent <42603768+makecent@users.noreply.github.com> Date: Wed, 12 Jan 2022 14:33:57 +0800 Subject: [PATCH 11/11] Update augmentation.py --- mmgen/datasets/pipelines/augmentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmgen/datasets/pipelines/augmentation.py b/mmgen/datasets/pipelines/augmentation.py index d67f2fee4..aef801ff7 100644 --- a/mmgen/datasets/pipelines/augmentation.py +++ b/mmgen/datasets/pipelines/augmentation.py @@ -163,7 +163,7 @@ def _resize(self, img, scale): tuple: Tuple contains resized image and scale factor in resize process. """ - if self.keep_ratio: + if isinstance(scale, (float, int)): img, scale_factor = mmcv.imrescale( img, scale,