From 18bda0a939c9cbcfbbe7f7da609c7f513fd7d9f3 Mon Sep 17 00:00:00 2001 From: CoinCheung <867153576@qq.com> Date: Tue, 16 Apr 2019 10:16:59 +0800 Subject: [PATCH 1/2] add color jitter augmentation --- maskrcnn_benchmark/config/defaults.py | 6 ++++++ maskrcnn_benchmark/data/transforms/build.py | 7 +++++++ .../data/transforms/transforms.py | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/maskrcnn_benchmark/config/defaults.py b/maskrcnn_benchmark/config/defaults.py index fc750fd4f..09e8941c5 100644 --- a/maskrcnn_benchmark/config/defaults.py +++ b/maskrcnn_benchmark/config/defaults.py @@ -54,6 +54,12 @@ # Convert image to BGR format (for Caffe2 models), in range 0-255 _C.INPUT.TO_BGR255 = True +# Image ColorJitter +_C.INPUT.BRIGHTNETSS = 0.0 +_C.INPUT.CONTRAST = 0.0 +_C.INPUT.SITURATION = 0.0 +_C.INPUT.HUE = 0.0 + # ----------------------------------------------------------------------------- # Dataset diff --git a/maskrcnn_benchmark/data/transforms/build.py b/maskrcnn_benchmark/data/transforms/build.py index 8645d4df4..c4f144ad3 100644 --- a/maskrcnn_benchmark/data/transforms/build.py +++ b/maskrcnn_benchmark/data/transforms/build.py @@ -16,9 +16,16 @@ def build_transforms(cfg, is_train=True): normalize_transform = T.Normalize( mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD, to_bgr255=to_bgr255 ) + color_jitter = T.ColorJitter( + brightness=cfg.INPUT.BRIGHTNETSS, + contrast=cfg.INPUT.CONTRAST, + saturation=cfg.INPUT.SITURATION, + hue=cfg.INPUT.HUE, + ) transform = T.Compose( [ + color_jitter, T.Resize(min_size, max_size), T.RandomHorizontalFlip(flip_prob), T.ToTensor(), diff --git a/maskrcnn_benchmark/data/transforms/transforms.py b/maskrcnn_benchmark/data/transforms/transforms.py index 7e3ebbd6c..1c322f8ba 100644 --- a/maskrcnn_benchmark/data/transforms/transforms.py +++ b/maskrcnn_benchmark/data/transforms/transforms.py @@ -72,6 +72,24 @@ def __call__(self, image, target): return image, target +class ColorJitter(object): + def __init__(self, + brightness=None, + contrast=None, + saturation=None, + hue=None, + ): + self.color_jitter = torchvision.transforms.ColorJitter( + brightness=brightness, + contrast=contrast, + saturation=saturation, + hue=hue,) + + def __call__(self, image, target): + image = self.color_jitter(image) + return image, target + + class ToTensor(object): def __call__(self, image, target): return F.to_tensor(image), target From dd5003d883beb1ab3615c6f4fec4cfa819f076a7 Mon Sep 17 00:00:00 2001 From: CoinCheung <867153576@qq.com> Date: Wed, 17 Apr 2019 10:08:20 +0800 Subject: [PATCH 2/2] fix spelling --- maskrcnn_benchmark/config/defaults.py | 4 ++-- maskrcnn_benchmark/data/transforms/build.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/maskrcnn_benchmark/config/defaults.py b/maskrcnn_benchmark/config/defaults.py index 09e8941c5..f2f69c222 100644 --- a/maskrcnn_benchmark/config/defaults.py +++ b/maskrcnn_benchmark/config/defaults.py @@ -55,9 +55,9 @@ _C.INPUT.TO_BGR255 = True # Image ColorJitter -_C.INPUT.BRIGHTNETSS = 0.0 +_C.INPUT.BRIGHTNESS = 0.0 _C.INPUT.CONTRAST = 0.0 -_C.INPUT.SITURATION = 0.0 +_C.INPUT.SATURATION = 0.0 _C.INPUT.HUE = 0.0 diff --git a/maskrcnn_benchmark/data/transforms/build.py b/maskrcnn_benchmark/data/transforms/build.py index c4f144ad3..825c3ee42 100644 --- a/maskrcnn_benchmark/data/transforms/build.py +++ b/maskrcnn_benchmark/data/transforms/build.py @@ -17,9 +17,9 @@ def build_transforms(cfg, is_train=True): mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD, to_bgr255=to_bgr255 ) color_jitter = T.ColorJitter( - brightness=cfg.INPUT.BRIGHTNETSS, + brightness=cfg.INPUT.BRIGHTNESS, contrast=cfg.INPUT.CONTRAST, - saturation=cfg.INPUT.SITURATION, + saturation=cfg.INPUT.SATURATION, hue=cfg.INPUT.HUE, )