-
Notifications
You must be signed in to change notification settings - Fork 328
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
Gaussian Blur layer implementation #143
Conversation
I have just realised the email I have for author wasn't matching the email on the CLA. In case no changes are required, let me know if I should revert and resubmit. |
@qlzh727 Do you know if we have an update from the TF team on tensorflow/tensorflow#39050? |
FYI @artu1999 we'll need you to sign the CLA to contribute code. Thanks |
training = backend.learning_phase() | ||
|
||
def _blur(image, kernel_size, sigma): | ||
image = tfa.image.gaussian_filter2d( |
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.
we don't rely on TFA in this repo. We will need to ship our own implementation. Gaussian blurs can actually be implemented through convolution (if tf.image doesn't have anything we can use). Perhaps check the SimCLR repo for a reference implementation
Returns: | ||
images: Blurred input images, same as input. | ||
""" | ||
if training is None: |
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.
assume training is a python bool.
Returns: | ||
images: Blurred input images, same as input. | ||
""" | ||
if training is None: |
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.
assume training is a python bool.
Thanks for the PR . I've left some early comments. |
@LukeWood I have realised I used the wrong author name, I will make sure to use the correct one for the next commit. In terms of the next steps:
https://arxiv.org/pdf/2009.00104.pdf https://arxiv.org/pdf/2006.10955.pdf I think it might be something very useful as other libraries don't seem to support this.
|
I'd be in favor of support for random behavior. For example, we could allow |
@LukeWood Are we going to always be random inside the batch? Cause I think that this sometimes is going already to complicate the vectorizzation a bit. Do we have any reference about the convergence improvement with in-batch randomization? |
We are leaning towards guiding users towards implementing: Then relying on XLA to perform optimization. This may be slightly less performant but the entire JAX ecosystem relies on this, so it should actually be fine. We want to minimize dependence between samples so this is optimal. |
Yes but also if you want to use XLA or |
Having a higher level Random Blur layer might also be useful in case we want to give users the possibility of applying random MotionBlur and MedianBlur as well. Possibly, we could use an argument to specify which type of random blur the user wants to apply or even apply a random type of Blur for each picture in the batch. |
As we are discussed in keras-team#143 (comment) this is going to fail (check the CI) cause: ``` ValueError: Input "maxval" of op 'RandomUniformInt' expected to be loop invariant. ``` As I've mentioned in the thread we really need to understand if we want to have randomness inside the batch or between the batches and what kind of impact we have between the computing overhead, contributing speed/code readability and network convergence. Also I don't know if @joker-eph or @qlzh727 could expose use a little bit the pro and cons of `jit_comile` a function vs using the `vectorized_map` or if they are orthogonal. With many CV transformations we cannot compile the function as the underline `tf.raw_ops.ImageProjectiveTransformV3 ` op isn't supported by XLA.
I don't think there is any active development on that issue at the moment. |
This sounds really heavy handed. I think we just want the layers to handle randomization themselves |
I still believe that I will be harder to remove the implicit randomization over the (hype)parameters space especially as we don't expose the non randomized ops in the internal API. |
@artu1999 any update here? |
Sorry for the inactivity, got quite busy with my final university project. I am going to make a commit either tomorrow or the day after with the new code, I just need to fix a couple of things here and there. |
Also, quick question: would you be happy with using keras.engine.base_layer.BaseRandomLayer as the class to inherit from or would you prefer to stick with keras.layers.Layer? |
Hey @artu1999 - Please use Basically, you write a function |
Will use that layer then, thanks! |
Closing for your other PR. Thanks @artu1999 for starting this process |
* Fix discrepancy with softmax when axis=None numpy and jax handled this as an all reduce option tf as a reduction on the last dimension * Fix format
implemented Gaussian Blur preprocessing layer using the gaussian blur implemented in tensorflow additions (Reference)
Linked Issue
layer = GaussianBlur(kernel_size=(10,7), sigma=1)
layer = GaussianBlur(kernel_size=(10,7), sigma=2)