diff --git a/mindspore/dataset/transforms/vision/py_transforms_util.py b/mindspore/dataset/transforms/vision/py_transforms_util.py index ac77624bf85..7a1878a04ff 100644 --- a/mindspore/dataset/transforms/vision/py_transforms_util.py +++ b/mindspore/dataset/transforms/vision/py_transforms_util.py @@ -455,6 +455,9 @@ def random_crop(img, size, padding, pad_if_needed, fill_value, padding_mode): def _input_to_factor(img, size): img_width, img_height = img.size height, width = size + if height > img_height or width > img_width: + raise ValueError("Crop size {} is larger than input image size {}".format(size, (img_height, img_width))) + if width == img_width and height == img_height: return 0, 0, img_height, img_width diff --git a/tests/ut/python/dataset/test_random_crop.py b/tests/ut/python/dataset/test_random_crop.py index 80746845790..969015d8f6b 100644 --- a/tests/ut/python/dataset/test_random_crop.py +++ b/tests/ut/python/dataset/test_random_crop.py @@ -280,6 +280,7 @@ def test_random_crop_04_py(): data.create_dict_iterator().get_next() except RuntimeError as e: logger.info("Got an exception in DE: {}".format(str(e))) + assert "Crop size" in str(e) def test_random_crop_05_c(): """