From 8749b27443d3c2b6d9e3ccceb21f87b02f0a6e62 Mon Sep 17 00:00:00 2001 From: yangustc07 Date: Wed, 6 Mar 2024 18:58:07 +0000 Subject: [PATCH 1/2] Fix an error in frustum_random_point_feature_noise.py. ``` Need minval < maxval, got 0 >= 0\n\t [[{{function_node frustum_random_point_feature_noise_map_while_body_496438}} {{node frustum_random_point_feature_noise/map/while/random_uniform}}]] ``` --- .../waymo/frustum_random_point_feature_noise.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py b/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py index bd5b959cc5..bd23909017 100644 --- a/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py +++ b/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py @@ -98,8 +98,13 @@ def get_random_transformation(self, point_clouds, **kwargs): # frustum. valid_points = point_clouds[0, :, POINTCLOUD_LABEL_INDEX] > 0 num_valid_points = tf.math.reduce_sum(tf.cast(valid_points, tf.int32)) + maxval = tf.cond( + num_valid_points > 0, + lambda: num_valid_points, + lambda: tf.constant(1, dtype=tf.int32), + ) randomly_select_point_index = tf.random.uniform( - (), minval=0, maxval=num_valid_points, dtype=tf.int32 + (), minval=0, maxval=maxval, dtype=tf.int32 ) randomly_select_frustum_center = tf.boolean_mask( point_clouds[0], valid_points, axis=0 From cf5165ae249a203a4be231e7f0f7c343763357c1 Mon Sep 17 00:00:00 2001 From: yangustc07 Date: Thu, 7 Mar 2024 00:47:56 +0000 Subject: [PATCH 2/2] In some models, this produces the following error: ``` Need minval < maxval, got 0 >= 0\n\t [[{{function_node frustum_random_point_feature_noise_map_while_body_496438}} {{node frustum_random_point_feature_noise/map/while/random_uniform}}]] ``` --- .../frustum_random_point_feature_noise.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py b/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py index bd23909017..395943d2e1 100644 --- a/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py +++ b/keras_cv/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py @@ -1,6 +1,7 @@ # Copyright 2022 Waymo LLC. # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 +import logging import tensorflow as tf @@ -98,14 +99,17 @@ def get_random_transformation(self, point_clouds, **kwargs): # frustum. valid_points = point_clouds[0, :, POINTCLOUD_LABEL_INDEX] > 0 num_valid_points = tf.math.reduce_sum(tf.cast(valid_points, tf.int32)) - maxval = tf.cond( - num_valid_points > 0, - lambda: num_valid_points, - lambda: tf.constant(1, dtype=tf.int32), - ) - randomly_select_point_index = tf.random.uniform( - (), minval=0, maxval=maxval, dtype=tf.int32 - ) + try: + randomly_select_point_index = tf.random.uniform( + (), minval=0, maxval=maxval, dtype=tf.int32 + ) + except tf.errors.InvalidArgumentError: + logging.error( + "Skipping frustum random point noise augmentation: No valid " + "point is found." + ) + return {} + randomly_select_frustum_center = tf.boolean_mask( point_clouds[0], valid_points, axis=0 )[randomly_select_point_index, :POINTCLOUD_LABEL_INDEX] @@ -149,6 +153,8 @@ def get_random_transformation(self, point_clouds, **kwargs): def augment_point_clouds_bounding_boxes( self, point_clouds, bounding_boxes, transformation, **kwargs ): + if "point_noise" not in transformation: + return (point_clouds, bounding_boxes) point_noise = transformation["point_noise"] # Do not add noise to points that are protected by setting the