Commit e15332fd authored by Yuxin Wu's avatar Yuxin Wu

remove some deprecations

parent 7da83a51
...@@ -366,12 +366,10 @@ def autodoc_skip_member(app, what, name, obj, skip, options): ...@@ -366,12 +366,10 @@ def autodoc_skip_member(app, what, name, obj, skip, options):
if name in [ if name in [
'MultiGPUTrainerBase', 'MultiGPUTrainerBase',
'get_predictors', 'get_predictors',
'RandomCropAroundBox',
'GaussianDeform', 'GaussianDeform',
'dump_chkpt_vars', 'dump_chkpt_vars',
'DumpTensor', 'DumpTensor',
'StagingInputWrapper', 'StagingInputWrapper',
'StepTensorPrinter',
'set_tower_func', 'set_tower_func',
'TryResumeTraining', 'TryResumeTraining',
'LeakyReLU', 'LeakyReLU',
......
...@@ -15,7 +15,7 @@ from ..tfutils.common import ( ...@@ -15,7 +15,7 @@ from ..tfutils.common import (
get_op_tensor_name, get_global_step_var) get_op_tensor_name, get_global_step_var)
from .base import Callback from .base import Callback
__all__ = ['TensorPrinter', 'StepTensorPrinter', 'ProgressBar'] __all__ = ['TensorPrinter', 'ProgressBar']
class TensorPrinter(Callback): class TensorPrinter(Callback):
...@@ -29,7 +29,7 @@ class TensorPrinter(Callback): ...@@ -29,7 +29,7 @@ class TensorPrinter(Callback):
names(list): list of string, the names of the tensors to print. names(list): list of string, the names of the tensors to print.
""" """
names = [get_op_tensor_name(n)[1] for n in names] names = [get_op_tensor_name(n)[1] for n in names]
logger.warn("Using print_stat or tf.Print in the graph is much faster than StepTensorPrinter!") logger.warn("Using tf.Print in the graph is much faster than TensorPrinter!")
self._names = names self._names = names
def _setup_graph(self): def _setup_graph(self):
...@@ -45,9 +45,6 @@ class TensorPrinter(Callback): ...@@ -45,9 +45,6 @@ class TensorPrinter(Callback):
logger.info("{}: {}".format(n, v)) logger.info("{}: {}".format(n, v))
StepTensorPrinter = TensorPrinter
class ProgressBar(Callback): class ProgressBar(Callback):
""" A progress bar based on tqdm. Enabled by default. """ """ A progress bar based on tqdm. Enabled by default. """
......
...@@ -2,17 +2,11 @@ ...@@ -2,17 +2,11 @@
# File: crop.py # File: crop.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com> # Author: Yuxin Wu <ppwwyyxx@gmail.com>
from six.moves import range
import numpy as np
from .base import ImageAugmentor
from ...utils.rect import IntBox
from ...utils.develop import log_deprecated
from ...utils.argtools import shape2d from ...utils.argtools import shape2d
from .transform import TransformAugmentorBase, CropTransform from .transform import TransformAugmentorBase, CropTransform
__all__ = ['RandomCrop', 'CenterCrop', 'RandomCropAroundBox', 'RandomCropRandomShape'] __all__ = ['RandomCrop', 'CenterCrop', 'RandomCropRandomShape']
class RandomCrop(TransformAugmentorBase): class RandomCrop(TransformAugmentorBase):
...@@ -56,78 +50,6 @@ class CenterCrop(TransformAugmentorBase): ...@@ -56,78 +50,6 @@ class CenterCrop(TransformAugmentorBase):
return CropTransform(h0, w0, self.crop_shape[0], self.crop_shape[1]) return CropTransform(h0, w0, self.crop_shape[0], self.crop_shape[1])
def perturb_BB(image_shape, bb, max_perturb_pixel,
rng=None, max_aspect_ratio_diff=0.3,
max_try=100):
"""
Perturb a bounding box.
Args:
image_shape: [h, w]
bb (IntBox): original bounding box
max_perturb_pixel: perturbation on each coordinate
max_aspect_ratio_diff: result can't have an aspect ratio too different from the original
max_try: if cannot find a valid bounding box, return the original
Returns:
new bounding box
"""
orig_ratio = bb.h * 1.0 / bb.w
if rng is None:
rng = np.random.RandomState()
for _ in range(max_try):
p = rng.randint(-max_perturb_pixel, max_perturb_pixel, [4])
newbb = bb.copy()
newbb.x1 += p[0]
newbb.y1 += p[1]
newbb.x2 = bb.x2 + p[2]
newbb.y2 = bb.y2 + p[3]
if not newbb.is_valid_box(image_shape):
continue
new_ratio = newbb.h * 1.0 / newbb.w
diff = abs(new_ratio - orig_ratio)
if diff / orig_ratio > max_aspect_ratio_diff:
continue
return newbb
return bb
# TODO deprecated. shouldn't include strange augmentors like this.
class RandomCropAroundBox(ImageAugmentor):
"""
Crop a box around a bounding box by some random perturbation.
"""
def __init__(self, perturb_ratio, max_aspect_ratio_diff=0.3):
"""
Args:
perturb_ratio (float): perturb distance will be in
``[0, perturb_ratio * sqrt(w * h)]``
max_aspect_ratio_diff (float): keep aspect ratio difference within the range
"""
super(RandomCropAroundBox, self).__init__()
log_deprecated(
"RandomCropAroundBox",
"It's neither common nor well-defined. Please implement something by yourself.",
"2017-11-30")
self._init(locals())
def _get_augment_params(self, img):
shape = img.shape[:2]
box = IntBox(0, 0, shape[1] - 1, shape[0] - 1)
dist = self.perturb_ratio * np.sqrt(shape[0] * shape[1])
newbox = perturb_BB(shape, box, dist,
self.rng, self.max_aspect_ratio_diff)
return newbox
def _augment(self, img, newbox):
return newbox.roi(img)
def _augment_coords(self, coords, newbox):
coords[:, 0] = coords[:, 0] - newbox.x1
coords[:, 1] = coords[:, 1] - newbox.y1
return coords
class RandomCropRandomShape(TransformAugmentorBase): class RandomCropRandomShape(TransformAugmentorBase):
""" Random crop with a random shape""" """ Random crop with a random shape"""
...@@ -157,7 +79,3 @@ class RandomCropRandomShape(TransformAugmentorBase): ...@@ -157,7 +79,3 @@ class RandomCropRandomShape(TransformAugmentorBase):
y0 = 0 if diffh == 0 else self.rng.randint(diffh) y0 = 0 if diffh == 0 else self.rng.randint(diffh)
x0 = 0 if diffw == 0 else self.rng.randint(diffw) x0 = 0 if diffw == 0 else self.rng.randint(diffw)
return CropTransform(y0, x0, h, w) return CropTransform(y0, x0, h, w)
if __name__ == '__main__':
print(perturb_BB([100, 100], IntBox(3, 3, 50, 50), 50))
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