From d29146da7d31fe9ce70c594f0c9ced139add7e56 Mon Sep 17 00:00:00 2001 From: Maximilian Bachl Date: Mon, 31 Jul 2023 18:26:16 +0200 Subject: [PATCH] RandomGaussianBlur crashes when factor=0 (#1968) * RandomGaussianBlur crashes when factor=0 ```>>> import keras_cv Using TensorFlow backend >>> blurrer = keras_cv.layers.RandomGaussianBlur(3, 0.) >>> blurrer.get_random_transformation() (, ) ``` * Make sure `factor` cannot become too small * Use keras.backend.epsilon() instead of 0.01 * Update random_gaussian_blur.py --- keras_cv/layers/preprocessing/random_gaussian_blur.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/keras_cv/layers/preprocessing/random_gaussian_blur.py b/keras_cv/layers/preprocessing/random_gaussian_blur.py index 7b8d151302..a2209f8bd5 100644 --- a/keras_cv/layers/preprocessing/random_gaussian_blur.py +++ b/keras_cv/layers/preprocessing/random_gaussian_blur.py @@ -61,7 +61,9 @@ def __init__(self, kernel_size, factor, **kwargs): ) def get_random_transformation(self, **kwargs): - factor = self.factor() + # `factor` must not become too small otherwise numerical issues occur. + # keras.backend.epsilon() behaves like 0 without causing `nan`s + factor = tf.math.maximum(self.factor(), keras.backend.epsilon()) blur_v = RandomGaussianBlur.get_kernel(factor, self.y) blur_h = RandomGaussianBlur.get_kernel(factor, self.x) blur_v = tf.reshape(blur_v, [self.y, 1, 1, 1])