Commit 5b7d5106 authored by Yuxin Wu's avatar Yuxin Wu

more logs/checks for RandomResize

parent 271ffad1
...@@ -10,8 +10,10 @@ import itertools ...@@ -10,8 +10,10 @@ import itertools
import tqdm import tqdm
import numpy as np import numpy as np
import json import json
import six
import tensorflow as tf import tensorflow as tf
assert six.PY3, "FasterRCNN requires Python 3!"
from tensorpack import * from tensorpack import *
from tensorpack.tfutils.summary import add_moving_summary from tensorpack.tfutils.summary import add_moving_summary
......
...@@ -106,14 +106,14 @@ class ResizeShortestEdge(TransformAugmentorBase): ...@@ -106,14 +106,14 @@ class ResizeShortestEdge(TransformAugmentorBase):
class RandomResize(TransformAugmentorBase): class RandomResize(TransformAugmentorBase):
""" Randomly rescale width and height of the image.""" """ Randomly rescale width and height of the image."""
def __init__(self, xrange, yrange, minimum=(0, 0), aspect_ratio_thres=0.15, def __init__(self, xrange, yrange=None, minimum=(0, 0), aspect_ratio_thres=0.15,
interp=cv2.INTER_LINEAR): interp=cv2.INTER_LINEAR):
""" """
Args: Args:
xrange (tuple): a (min, max) tuple. If is floating point, the xrange (tuple): a (min, max) tuple. If is floating point, the
tuple defines the range of scaling ratio of new width, e.g. (0.9, 1.2). tuple defines the range of scaling ratio of new width, e.g. (0.9, 1.2).
If is integer, the tuple defines the range of new width in pixels, e.g. (200, 350). If is integer, the tuple defines the range of new width in pixels, e.g. (200, 350).
yrange (tuple): similar to xrange, but for height. yrange (tuple): similar to xrange, but for height. Should be None when aspect_ratio_thres==0.
minimum (tuple): (xmin, ymin) in pixels. To avoid scaling down too much. minimum (tuple): (xmin, ymin) in pixels. To avoid scaling down too much.
aspect_ratio_thres (float): discard samples which change aspect ratio aspect_ratio_thres (float): discard samples which change aspect ratio
larger than this threshold. Set to 0 to keep aspect ratio. larger than this threshold. Set to 0 to keep aspect ratio.
...@@ -126,11 +126,16 @@ class RandomResize(TransformAugmentorBase): ...@@ -126,11 +126,16 @@ class RandomResize(TransformAugmentorBase):
def is_float(tp): def is_float(tp):
return isinstance(tp[0], float) or isinstance(tp[1], float) return isinstance(tp[0], float) or isinstance(tp[1], float)
assert is_float(xrange) == is_float(yrange), "xrange and yrange has different type!" if yrange is not None:
assert is_float(xrange) == is_float(yrange), "xrange and yrange has different type!"
self._is_scale = is_float(xrange) self._is_scale = is_float(xrange)
if self._is_scale and aspect_ratio_thres == 0: if aspect_ratio_thres == 0:
assert xrange == yrange if self._is_scale:
assert xrange == yrange or yrange is None
else:
if yrange is not None:
logger.warn("aspect_ratio_thres==0, yrange is not used!")
def _get_augment_params(self, img): def _get_augment_params(self, img):
cnt = 0 cnt = 0
......
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