Skip to content

Commit

Permalink
[Enchance] Add a probability parameter to Mosaic transform (#7371)
Browse files Browse the repository at this point in the history
* [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 <jamiechoi1995@users.noreply.github.com>
Co-authored-by: BigDong <yudongwang@tju.edu.cn>

* 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 <jbwang1997@gmail.com>

* 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 <luochunhua1996@outlook.com>
Co-authored-by: tripleMu <92794867+q3394101@users.noreply.github.com>
Co-authored-by: jbwang1997 <jbwang1997@gmail.com>
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 <jamiechoi1995@users.noreply.github.com>
Co-authored-by: BigDong <yudongwang@tju.edu.cn>
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 <luochunhua1996@outlook.com>
Co-authored-by: Jingwei Zhang <zjw18@mails.tsinghua.edu.cn>
Co-authored-by: jbwang1997 <jbwang1997@gmail.com>
Co-authored-by: Xiangxu-0103 <xuxiang0103@gmail.com>
Co-authored-by: tripleMu <92794867+q3394101@users.noreply.github.com>
Co-authored-by: kira <39787375+yangrisheng@users.noreply.github.com>
  • Loading branch information
15 people authored Apr 1, 2022
1 parent 28022ba commit 838996d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mmdet/datasets/pipelines/auto_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion mmdet/datasets/pipelines/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -2009,15 +2011,20 @@ 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
self.min_bbox_size = min_bbox_size
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.
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 838996d

Please sign in to comment.