!4694 fix: RandomAffine parameter check

Merge pull request !4694 from guozhijian/fix_randomaffine_err
This commit is contained in:
mindspore-ci-bot 2020-08-18 22:56:18 +08:00 committed by Gitee
commit bf2ef95fc3
3 changed files with 36 additions and 1 deletions

View File

@ -262,7 +262,8 @@ class RandomAffine(cde.RandomAffineOp):
- Inter.BICUBIC, means resample method is bicubic interpolation.
fill_value (tuple or int, optional): Optional fill_value to fill the area outside the transform
in the output image. Used only in Pillow versions > 5.0.0 (default=0, filling is performed).
in the output image. There must be three elements in tuple and the value of single element is [0, 255].
Used only in Pillow versions > 5.0.0 (default=0, filling is performed).
Raises:
ValueError: If degrees is negative.
@ -274,6 +275,7 @@ class RandomAffine(cde.RandomAffineOp):
TypeError: If translate is specified but is not list or a tuple of length 2.
TypeError: If scale is not a list or tuple of length 2.''
TypeError: If shear is not a list or tuple of length 2 or 4.
TypeError: If fill_value is not a single integer or a 3-tuple.
Examples:
>>> c_transform.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1))

View File

@ -509,6 +509,8 @@ def check_random_affine(method):
if len(scale) == 2:
for i, s in enumerate(scale):
check_positive(s, "scale[{}]".format(i))
if scale[0] > scale[1]:
raise ValueError("Input scale[1] must be equal to or greater than scale[0].")
else:
raise TypeError("scale should be a list or tuple of length 2.")
@ -519,6 +521,11 @@ def check_random_affine(method):
else:
if len(shear) not in (2, 4):
raise TypeError("shear must be of length 2 or 4.")
if len(shear) == 2 and shear[0] > shear[1]:
raise ValueError("Input shear[1] must be equal to or greater than shear[0]")
if len(shear) == 4 and (shear[0] > shear[1] or shear[2] > shear[3]):
raise ValueError("Input shear[1] must be equal to or greater than shear[0] and "
"shear[3] must be equal to or greater than shear[2].")
type_check(resample, (Inter,), "resample")

View File

@ -190,6 +190,12 @@ def test_random_affine_exception_scale_value():
logger.info("Got an exception in DE: {}".format(str(e)))
assert str(e) == "Input scale[0] must be greater than 0."
try:
_ = py_vision.RandomAffine(degrees=15, scale=(2.0, 1.1))
except ValueError as e:
logger.info("Got an exception in DE: {}".format(str(e)))
assert str(e) == "Input scale[1] must be equal to or greater than scale[0]."
def test_random_affine_exception_shear_value():
"""
@ -202,6 +208,26 @@ def test_random_affine_exception_shear_value():
logger.info("Got an exception in DE: {}".format(str(e)))
assert str(e) == "Input shear must be greater than 0."
try:
_ = py_vision.RandomAffine(degrees=15, shear=(5, 1))
except ValueError as e:
logger.info("Got an exception in DE: {}".format(str(e)))
assert str(e) == "Input shear[1] must be equal to or greater than shear[0]"
try:
_ = py_vision.RandomAffine(degrees=15, shear=(5, 1, 2, 8))
except ValueError as e:
logger.info("Got an exception in DE: {}".format(str(e)))
assert str(e) == "Input shear[1] must be equal to or greater than shear[0] and " \
"shear[3] must be equal to or greater than shear[2]."
try:
_ = py_vision.RandomAffine(degrees=15, shear=(5, 9, 2, 1))
except ValueError as e:
logger.info("Got an exception in DE: {}".format(str(e)))
assert str(e) == "Input shear[1] must be equal to or greater than shear[0] and " \
"shear[3] must be equal to or greater than shear[2]."
def test_random_affine_exception_degrees_size():
"""