-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RandomGaussianBlur crashes when factor=0 #1968
Conversation
```>>> import keras_cv Using TensorFlow backend >>> blurrer = keras_cv.layers.RandomGaussianBlur(3, 0.) >>> blurrer.get_random_transformation() (<tf.Tensor: shape=(3, 1, 1, 1), dtype=float32, numpy= array([[[[nan]]], [[[nan]]], [[[nan]]]], dtype=float32)>, <tf.Tensor: shape=(1, 3, 1, 1), dtype=float32, numpy= array([[[[nan]], [[nan]], [[nan]]]], dtype=float32)>) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I think we can fix the numerical issue pretty simply instead of just documenting it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks -- this is close! Let's just use keras.backend.epsilon
instead (see my comment in-line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks like this now breaks some tests -- take a look at my inline comment
factor = self.factor() | ||
# `factor` must not become too small otherwise numerical issues occur. | ||
# keras.backend.epsilon() behaves like 0 without causing `nan`s | ||
factor = max(self.factor(), keras.backend.epsilon()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is breaking tests -- probably because self.factor()
returns a tf Tensor and epsilon
is a python float.
Perhaps better would be to say factor = self.factor() + keras.backend.epsilon()
You can run the test locally to verify that this isn't breaking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be very convenient if the tests ran on each update of the pull request automatically. I think the issue could be fixed now. Can you rerun the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it locally, it seems to work now. I think the problem was that tensorflow has problems compiling the max
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do run automatically for folks who have contributed before. However, you should always run tests locally instead of depending on CI to run tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Hopefully CI will be happy here as well.
When using max
in TF you need to use the tf-built in version, not the Python version, if you want to use TF tensors and have it compile into the TF graph. So in this case we could have used the TF version, but just adding the constant value also works just fine 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the meantime I tested it locally and it worked. I couldn't find documentation on how to run the tests in the README.md but it is not so hard to figure out. Could be improved maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI tests look good to me except some unrelated formatting issue in some other code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/gcbrun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
* RandomGaussianBlur crashes when factor=0 ```>>> import keras_cv Using TensorFlow backend >>> blurrer = keras_cv.layers.RandomGaussianBlur(3, 0.) >>> blurrer.get_random_transformation() (<tf.Tensor: shape=(3, 1, 1, 1), dtype=float32, numpy= array([[[[nan]]], [[[nan]]], [[[nan]]]], dtype=float32)>, <tf.Tensor: shape=(1, 3, 1, 1), dtype=float32, numpy= array([[[[nan]], [[nan]], [[nan]]]], dtype=float32)>) ``` * Make sure `factor` cannot become too small * Use keras.backend.epsilon() instead of 0.01 * Update random_gaussian_blur.py
What does this PR do?
Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.