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

Commit

Permalink
add color jitter augmentation (#680)
Browse files Browse the repository at this point in the history
* add color jitter augmentation

* fix spelling
  • Loading branch information
CoinCheung authored and fmassa committed Apr 19, 2019
1 parent 1d6e9ad commit 862347d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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.BRIGHTNESS = 0.0
_C.INPUT.CONTRAST = 0.0
_C.INPUT.SATURATION = 0.0
_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.BRIGHTNESS,
contrast=cfg.INPUT.CONTRAST,
saturation=cfg.INPUT.SATURATION,
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

0 comments on commit 862347d

Please sign in to comment.