From 838996d71625a7c1861ac25a593fec3bd824115b Mon Sep 17 00:00:00 2001 From: Range King Date: Fri, 1 Apr 2022 16:01:06 +0800 Subject: [PATCH] [Enchance] Add a probability parameter to Mosaic transform (#7371) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Fix] Adjust the order of get_classes and FileClient. (#7276) * delete -sv (#7277) Co-authored-by: Wenwei Zhang <40779233+ZwwWayne@users.noreply.github.com> * [Docs] Add Chinese version of finetune (#7178) * [Fix] Fix wrong img name in onnx2tensorrt.py (#7157) * [Docs] fix albumentations installed way (#7143) * Update finetune.md Translate the finetune.md doc to Chinese * Update finetune.md * Update finetune.md * Update finetune.md * fix lint * fx lint * fix pr Co-authored-by: Jamie Co-authored-by: BigDong * set unmap_results=True in ssd_head (#7328) * Update YOLOX log for non square input (#7235) * [Enhance] add cpu_num in cocopanoptic for pq computing (#7315) * add cpu_num in cocopanoptic for pq computing * cpu_num -> nproc * move nproc to evaluate * [Enhancement] Allow to set channel_order in LoadImageFromFile (#7258) * allow to set channel_order when loading images * fix lint * fix unit test * fix lint * [Fix] Force the inputs of `get_bboxes` in yolox_head to float32. (#7324) * Fix softnms bug * Add force_fp32 in corner_head and centripetal_head * [Fix] Fix typo in FPN neck (#7347) * update readme and pretrained related (#7301) * [Docs] Add Chinese version of onnx2tensorrt.md (#7219) * Fix bug of docs * translate onnx2tensorrt.md * fix * fix end-of-file-fixer * fix some bugs * 修复链接跳转 * 修复链接跳转 * 修复链接跳转-测试1 * 修复链接跳转-测试2 * 修复链接跳转-测试2 * 修复链接跳转-测试3 * 修复链接跳转-测试5 * Fix Co-authored-by: jbwang1997 * Update useful_tools.md (#7180) * [Enhancement]: Update colab tutorials (#7310) * update colab tutorials * update * fix * fix wrong CUDA explaination * resolve comments * resolve comments * fix typo Co-authored-by: Cedric Luo Co-authored-by: tripleMu <92794867+q3394101@users.noreply.github.com> Co-authored-by: jbwang1997 Co-authored-by: kira <39787375+yangrisheng@users.noreply.github.com> Co-authored-by: Wenwei Zhang <40779233+ZwwWayne@users.noreply.github.com> * Add prob parameter in Mosaic * Update transforms.py * Update default prob of Mosaic transform default prob is set to 0.5 * Add unit test to prob of Mosaic * Update default prob of Mosaic transform Set default prob=1. * Update auto_augment.py fix f-string * Update test_transform.py Co-authored-by: Wencheng Wu <41542251+274869388@users.noreply.github.com> Co-authored-by: Yue Zhou <592267829@qq.com> Co-authored-by: Wenwei Zhang <40779233+ZwwWayne@users.noreply.github.com> Co-authored-by: MingJian.L <45811724+matrixgame2018@users.noreply.github.com> Co-authored-by: Jamie Co-authored-by: BigDong Co-authored-by: Cedric Luo <26483343+chhluo@users.noreply.github.com> Co-authored-by: Yosuke Shinya <42844407+shinya7y@users.noreply.github.com> Co-authored-by: Cedric Luo Co-authored-by: Jingwei Zhang Co-authored-by: jbwang1997 Co-authored-by: Xiangxu-0103 Co-authored-by: tripleMu <92794867+q3394101@users.noreply.github.com> Co-authored-by: kira <39787375+yangrisheng@users.noreply.github.com> --- mmdet/datasets/pipelines/auto_augment.py | 2 +- mmdet/datasets/pipelines/transforms.py | 12 +++++++++++- .../test_pipelines/test_transform/test_transform.py | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mmdet/datasets/pipelines/auto_augment.py b/mmdet/datasets/pipelines/auto_augment.py index 4452181f1a0..b0ff67dbdd9 100644 --- a/mmdet/datasets/pipelines/auto_augment.py +++ b/mmdet/datasets/pipelines/auto_augment.py @@ -390,7 +390,7 @@ def __init__(self, 'all elements of img_fill_val should between range [0,255]. '\ f'got {img_fill_val}.' assert 0 <= prob <= 1.0, 'The probability should be in range [0,1]. '\ - 'got {prob}.' + f'got {prob}.' assert isinstance(max_rotate_angle, (int, float)), 'max_rotate_angle '\ f'should be type int or float. got type {type(max_rotate_angle)}.' self.level = level diff --git a/mmdet/datasets/pipelines/transforms.py b/mmdet/datasets/pipelines/transforms.py index 16ba8134a9a..dafe6fd121d 100644 --- a/mmdet/datasets/pipelines/transforms.py +++ b/mmdet/datasets/pipelines/transforms.py @@ -2001,6 +2001,8 @@ class Mosaic: is True, the filter rule will not be applied, and the `min_bbox_size` is invalid. Default to True. pad_val (int): Pad value. Default to 114. + prob (float): Probability of applying this transformation. + Default to 1.0. """ def __init__(self, @@ -2009,8 +2011,12 @@ def __init__(self, min_bbox_size=0, bbox_clip_border=True, skip_filter=True, - pad_val=114): + pad_val=114, + prob=1.0): assert isinstance(img_scale, tuple) + assert 0 <= prob <= 1.0, 'The probability should be in range [0,1]. '\ + f'got {prob}.' + log_img_scale(img_scale, skip_square=True) self.img_scale = img_scale self.center_ratio_range = center_ratio_range @@ -2018,6 +2024,7 @@ def __init__(self, self.bbox_clip_border = bbox_clip_border self.skip_filter = skip_filter self.pad_val = pad_val + self.prob = prob def __call__(self, results): """Call function to make a mosaic of image. @@ -2029,6 +2036,9 @@ def __call__(self, results): dict: Result dict with mosaic transformed. """ + if random.uniform(0, 1) > self.prob: + return results + results = self._mosaic_transform(results) return results diff --git a/tests/test_data/test_pipelines/test_transform/test_transform.py b/tests/test_data/test_pipelines/test_transform/test_transform.py index d256ef1bb68..04d443ed9a9 100644 --- a/tests/test_data/test_pipelines/test_transform/test_transform.py +++ b/tests/test_data/test_pipelines/test_transform/test_transform.py @@ -900,6 +900,11 @@ def test_mosaic(): transform = dict(type='Mosaic', img_scale=640) build_from_cfg(transform, PIPELINES) + # test assertion for invalid probability + with pytest.raises(AssertionError): + transform = dict(type='Mosaic', prob=1.5) + build_from_cfg(transform, PIPELINES) + results = dict() img = mmcv.imread( osp.join(osp.dirname(__file__), '../../../data/color.jpg'), 'color')