Commit ebeaa046 authored by Yuxin Wu's avatar Yuxin Wu

add BrightnessScale

parent ca91326d
......@@ -20,10 +20,10 @@ matrix:
include:
- os: linux
python: 2.7
env: TF_VERSION=1.3.0rc0 TF_TYPE=release
env: TF_VERSION=1.3.0rc2 TF_TYPE=release
- os: linux
python: 3.5
env: TF_VERSION=1.3.0rc0 TF_TYPE=release
env: TF_VERSION=1.3.0rc2 TF_TYPE=release
- os: linux
python: 2.7
env: TF_VERSION=1.head TF_TYPE=nightly
......@@ -55,6 +55,7 @@ script:
- mkdir -p $HOME/tensorpack_data
- export TENSORPACK_DATASET=$HOME/tensorpack_data
- $TRAVIS_BUILD_DIR/tests/run-tests.sh
- cd $TRAVIS_BUILD_DIR # go back to root so that deploy may work
notifications:
email:
......@@ -69,6 +70,8 @@ notifications:
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
# see https://docs.travis-ci.com/user/deployment/pypi/
deploy:
- provider: pypi
user: ppwwyyxx
......
......@@ -7,7 +7,7 @@ from ...utils import logger
import numpy as np
import cv2
__all__ = ['Hue', 'Brightness', 'Contrast', 'MeanVarianceNormalize',
__all__ = ['Hue', 'Brightness', 'BrightnessScale', 'Contrast', 'MeanVarianceNormalize',
'GaussianBlur', 'Gamma', 'Clip', 'Saturation', 'Lighting', 'MinMaxNormalize']
......@@ -44,17 +44,19 @@ class Hue(ImageAugmentor):
class Brightness(ImageAugmentor):
"""
Randomly adjust brightness.
Adjust brightness by adding a random number.
"""
def __init__(self, delta, clip=True):
"""
Randomly add a value within [-delta,delta], and clip in [0,255] if clip is True.
Args:
delta (float): Randomly add a value within [-delta,delta]
clip (bool): clip results to [0,255].
"""
super(Brightness, self).__init__()
assert delta > 0
self._init(locals())
def _get_augment_params(self, img):
def _get_augment_params(self, _):
v = self._rand_range(-self.delta, self.delta)
return v
......@@ -67,6 +69,32 @@ class Brightness(ImageAugmentor):
return img.astype(old_dtype)
class BrightnessScale(ImageAugmentor):
"""
Adjust brightness by scaling by a random factor.
"""
def __init__(self, range, clip=True):
"""
Args:
range (tuple): Randomly scale the image by a factor in (range[0], range[1])
clip (bool): clip results to [0,255].
"""
super(BrightnessScale, self).__init__()
self._init(locals())
def _get_augment_params(self, _):
v = self._rand_range(*self.range)
return v
def _augment(self, img, v):
old_dtype = img.dtype
img = img.astype('float32')
img *= v
if self.clip or old_dtype == np.uint8:
img = np.clip(img, 0, 255)
return img.astype(old_dtype)
class Contrast(ImageAugmentor):
"""
Apply ``x = (x - mean) * contrast_factor + mean`` to each channel.
......
......@@ -20,7 +20,8 @@ except ImportError:
__all__ = ['pyplot2img', 'interactive_imshow',
'stack_patches', 'gen_stack_patches',
'dump_dataflow_images', 'intensity_to_rgb']
'dump_dataflow_images', 'intensity_to_rgb',
'draw_boxes']
def pyplot2img(plt):
......@@ -356,13 +357,14 @@ def intensity_to_rgb(intensity, cmap='cubehelix', normalize=False):
def draw_boxes(im, boxes, labels=None, color=None):
"""
Args:
im (np.ndarray): a BGR image. will not be modified
boxes (np.ndarray or list[BoxBase]):
im (np.ndarray): a BGR image. It will not be modified.
boxes (np.ndarray or list[BoxBase]): If an ndarray,
must be of shape Nx4 where the second dimension is [x1, y1, x2, y2].
labels: (list[str] or None)
color: a 3-tuple (in range [0, 255]). By default will choose automatically.
Returns:
np.ndarray
np.ndarray: a new image.
"""
FONT = cv2.FONT_HERSHEY_SIMPLEX
FONT_SCALE = 0.4
......
......@@ -7,6 +7,5 @@ cd $DIR
export TF_CPP_MIN_LOG_LEVEL=2
python -m unittest discover -v
cd ..
# python -m tensorpack.models._test
# segfault for no reason (https://travis-ci.org/ppwwyyxx/tensorpack/jobs/217702985)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment