From c4ca113ed87229ef991bb489abea82cf1c3c1d68 Mon Sep 17 00:00:00 2001 From: Gergely Papp Date: Mon, 8 Aug 2022 15:18:28 +0200 Subject: [PATCH 1/2] image size must be greater than 0 So far, only one side was required to be greater than 0 after resize. However, it is more user-friendly if the image has a non-zero area instead. --- tf_image/core/bboxes/clip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf_image/core/bboxes/clip.py b/tf_image/core/bboxes/clip.py index 39c33fe..90c5933 100644 --- a/tf_image/core/bboxes/clip.py +++ b/tf_image/core/bboxes/clip.py @@ -46,7 +46,7 @@ def _clip_random_with_bboxes(image, bboxes): # update image, bboxes = tf.cond( - tf.math.logical_or(tf.math.greater(new_height, 0), tf.math.greater(new_width, 0)), + tf.math.logical_and(tf.math.greater(new_height, 0), tf.math.greater(new_width, 0)), lambda: (tf.image.crop_to_bounding_box(image, *args_clip_image), clip_bboxes(bboxes, *args_clip_bboxes)), lambda: (image, bboxes), ) From 63aca6ac241d3d3bbab2c7e0c6a765c1bd115d9a Mon Sep 17 00:00:00 2001 From: Gergely Papp Date: Mon, 8 Aug 2022 15:41:13 +0200 Subject: [PATCH 2/2] More precise approach for area condition It is more precise to use the exact integer values --- tf_image/core/bboxes/clip.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tf_image/core/bboxes/clip.py b/tf_image/core/bboxes/clip.py index 90c5933..f6a9327 100644 --- a/tf_image/core/bboxes/clip.py +++ b/tf_image/core/bboxes/clip.py @@ -43,6 +43,9 @@ def _clip_random_with_bboxes(image, bboxes): tf.cast(new_height * image_height, dtype=tf.int32), tf.cast(new_width * image_width, dtype=tf.int32), ] + + # Use int values for area measure + new_height, new_width = args_clip_image[2:] # update image, bboxes = tf.cond(