[Fix] Fix interpolation method checking in `Resize` (#547)
* fix interpolation method checking in resize * revise docstring + add unit testpull/525/head
parent
7977dc8e2d
commit
49cbfd776a
|
@ -677,8 +677,10 @@ class Resize(object):
|
|||
(224, -1) and adaptive_size is "short", the short side is resized
|
||||
to 224 and the other side is computed based on the short side,
|
||||
maintaining the aspect ratio.
|
||||
interpolation (str): Interpolation method, accepted values are
|
||||
"nearest", "bilinear", "bicubic", "area", "lanczos".
|
||||
interpolation (str): Interpolation method. For "cv2" backend, accepted
|
||||
values are "nearest", "bilinear", "bicubic", "area", "lanczos". For
|
||||
"pillow" backend, accepted values are "nearest", "bilinear",
|
||||
"bicubic", "box", "lanczos", "hamming".
|
||||
More details can be found in `mmcv.image.geometric`.
|
||||
adaptive_side(str): Adaptive resize policy, accepted values are
|
||||
"short", "long", "height", "width". Default to "short".
|
||||
|
@ -704,12 +706,15 @@ class Resize(object):
|
|||
assert size[0] > 0 and (size[1] > 0 or size[1] == -1)
|
||||
if size[1] == -1:
|
||||
self.adaptive_resize = True
|
||||
assert interpolation in ('nearest', 'bilinear', 'bicubic', 'area',
|
||||
'lanczos')
|
||||
if backend not in ['cv2', 'pillow']:
|
||||
raise ValueError(f'backend: {backend} is not supported for resize.'
|
||||
'Supported backends are "cv2", "pillow"')
|
||||
|
||||
if backend == 'cv2':
|
||||
assert interpolation in ('nearest', 'bilinear', 'bicubic', 'area',
|
||||
'lanczos')
|
||||
else:
|
||||
assert interpolation in ('nearest', 'bilinear', 'bicubic', 'box',
|
||||
'lanczos', 'hamming')
|
||||
self.size = size
|
||||
self.interpolation = interpolation
|
||||
self.backend = backend
|
||||
|
|
|
@ -214,6 +214,20 @@ def test_resize():
|
|||
assert np.equal(results['img'], results['img2']).all()
|
||||
assert results['img_shape'] == (336, 224, 3)
|
||||
|
||||
# test interpolation method checking
|
||||
with pytest.raises(AssertionError):
|
||||
transform = dict(
|
||||
type='Resize', size=(300, 200), backend='cv2', interpolation='box')
|
||||
resize_module = build_from_cfg(transform, PIPELINES)
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
transform = dict(
|
||||
type='Resize',
|
||||
size=(300, 200),
|
||||
backend='pillow',
|
||||
interpolation='area')
|
||||
resize_module = build_from_cfg(transform, PIPELINES)
|
||||
|
||||
|
||||
def test_pad():
|
||||
results = dict()
|
||||
|
|
Loading…
Reference in New Issue