From 6aae59d0b54f04c13a79f80b708622db8e8a17e4 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Wed, 29 Jun 2022 10:30:20 +0200 Subject: [PATCH] Compute min_resolution in prepare_image_inputs (#17915) Co-authored-by: ydshieh --- tests/test_feature_extraction_common.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_feature_extraction_common.py b/tests/test_feature_extraction_common.py index d6420ad3c5..f226244fd0 100644 --- a/tests/test_feature_extraction_common.py +++ b/tests/test_feature_extraction_common.py @@ -68,10 +68,15 @@ def prepare_image_inputs(feature_extract_tester, equal_resolution=False, numpify ) else: image_inputs = [] + + # To avoid getting image width/height 0 + min_resolution = feature_extract_tester.min_resolution + if getattr(feature_extract_tester, "size_divisor", None): + # If `size_divisor` is defined, the image needs to have width/size >= `size_divisor` + min_resolution = max(feature_extract_tester.size_divisor, min_resolution) + for i in range(feature_extract_tester.batch_size): - width, height = np.random.choice( - np.arange(feature_extract_tester.min_resolution, feature_extract_tester.max_resolution), 2 - ) + width, height = np.random.choice(np.arange(min_resolution, feature_extract_tester.max_resolution), 2) image_inputs.append( np.random.randint(255, size=(feature_extract_tester.num_channels, width, height), dtype=np.uint8) )