Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

add color jitter augmentation #680

Merged
merged 2 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maskrcnn_benchmark/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: BRIGHTNESS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I have correct the spelling, please tell me if there needs further modifications.

As for the performance, I actually observed no obvious improvements on our own datasets with brightness=0.4, contrast=0.4, saturation=0.4, hue=0.3. The random seed is not manually assigned and the performance is on par with the non-color-aug version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, do you think we should add a random_seed field in the configuration file for convenience of assigning the seed for random operations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a seed would be useful I think, even though not everything would be deterministic.

_C.INPUT.CONTRAST = 0.0
_C.INPUT.SITURATION = 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: it should be SATURATION

_C.INPUT.HUE = 0.0


# -----------------------------------------------------------------------------
# Dataset
Expand Down
7 changes: 7 additions & 0 deletions maskrcnn_benchmark/data/transforms/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
18 changes: 18 additions & 0 deletions maskrcnn_benchmark/data/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down