-
Notifications
You must be signed in to change notification settings - Fork 611
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
add filter response normalization #765
Conversation
@seanpmorgan @WindQAQ @facaiy I have added the latest contribution for normalization from the Google Brain team. Although the implementation is fully correct IMO but before I go on and write unit-tests for it, can you please take a look at the implementation and let me know if it looks okay. Thank you |
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 good, just a clarification regarding epsilon
.
@seanpmorgan @WindQAQ @Squadrick @saurabhme I have opened a PR for TLU. Please check #857 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@AakashKumarNain I've merged master into your branch to update it and fixed any formatting/conflicts it might have. If you need to do some more modifications, please do |
@gabrieldemarmiesse this will come with a lot of changes. Will do in the coming weeks. It has been long overdue |
@gabrieldemarmiesse @seanpmorgan the tests work fine in eager mode but are failing in graph mode. Let me know if you need any other info. Thanks inputs = np.random.rand(28, 28, 1).astype(np.float32)
frn = FilterResponseNormalization(
beta_initializer="zeros", gamma_initializer="ones"
)
frn.build((28, 28, 1))
observed = frn(inputs)
expected = self.calculate_frn(inputs, beta=0, gamma=1)
self.assertAllClose(expected, observed) # this is where the test fails |
@AakashKumarNain I know the problem. You aren't initializing the variables, you need to add: Here's a stripped-down version of def test_random_inputs(self):
inputs = np.random.rand(28, 28, 1).astype(np.float32)
frn = FilterResponseNormalization(
beta_initializer="zeros", gamma_initializer="ones"
)
frn.build((28, 28, 1))
self.evaluate(tf.compat.v1.global_variables_initializer()) # <-- missing
observed = frn(inputs)
expected = self.calculate_frn(inputs, beta=0, gamma=1)
self.assertAllClose(expected, observed[0]) The output log of the successful run;
Also, prefer not to use randomized inputs as inputs for better repro. If you want to use random input, at least use a fixed seed for |
@Squadrick yeah 🤦♂ . (With |
@seanpmorgan @Squadrick @gabrieldemarmiesse I think we can merge this now. If you think, any changes are required, please let me know. Thanks |
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.
@AakashKumarNain A few changes.
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.
After going through the paper, I realized that the authors also tested this for FC. Right now, your implementation works only for 4D inputs, and it is mentioned so in the docstring. However, we have no asserts or checks, which will lead to some obscure shape/size errors from Tensorflow instead of a nicer error.
If you decide to scope this PR to only 4D tensors:
- Check on
input_shape
to ensure it is 4D only. axis
should be parameterized, ignore my previous comments. But it should only accept a list or size 2. Remove the check for[1, 2]
, since[-1, -2]
or[2, 3]
is perfectly acceptable for when we setchannels_first
in the preceding conv layer.- Add a TODO and create a new issue as "contributions welcome" for adding support for a generalized N-D input, similar to batch norm. (@saurabhme thoughts on this?)
@gabrieldemarmiesse @Squadrick I have made all the changes. Also, I am using only |
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 changes. A few more changes: some that weren't fixed, and some that I overlooked (sorry).
Created #1441 for adding more tensor shape support to this layer. |
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.
LGTM, thanks @AakashKumarNain
The request change will be done in #1441
Unblocks #1441 |
Thanks @Squadrick . Will work on #1441 now. |
@AakashKumarNain, I think someone else has started working on it already. You can check the comments in #1441. |
* Add FRN layer (only 4D NHWC tensor support) Co-authored-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
No description provided.