Skip to content
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

fix compute_output_shape behavior in normalizations.py #2678

Merged
merged 1 commit into from
Feb 24, 2022

Conversation

Zhaopudark
Copy link
Contributor

@Zhaopudark Zhaopudark commented Feb 22, 2022

Description

Fixes #2677

Normalization layers in normalizations.py have been write very well. Thanks for the contributors. These layers work well in most cases, but their behavor in compute_output_shape is very smallly different from their description and different from tf.keras.layers.Layer's design ideas about compute_output_shape .

Since tfa.layers.GroupNormalization, tfa.layers.InstanceNormalization and tfa.layers.FilterResponseNormalization are all inherited from tf.keras.layers.Layer, they all override compute_output_shape function.

However, there is no need to override this function, because tf.keras.layers.Layer has done it well, i.e., if call and build functions have been overrided, the layer can automaticly give out correct output_shape buy compute_output_shape in superclass. Remove the overrided compute_output_shape, the bug will disappear.

Actually, overriding compute_output_shape when inherite a custom layer from tf.keras.layer.Layer is usually unnecessary in most cases, unless a user wants an output_shape that different from call's output. But in normalizations.py, normalization ops do not change shapes, the special above case is not suitable.

Type of change

  • Bug fix
  • Additional Testing

Checklist:

  • I've properly formatted my code according to the guidelines
    • By running Black + Flake8
    • By running pre-commit hooks
  • This PR addresses an already submitted issue for TensorFlow Addons
  • I have added tests that prove my fix is effective or that my feature works

@boring-cyborg boring-cyborg bot added the layers label Feb 22, 2022
@bot-of-gabrieldemarmiesse

@Smokrow

You are owner of some files modified in this pull request.
Would you kindly review the changes whenever you have the time to?
Thank you very much.

@fsx950223 fsx950223 merged commit 18c8367 into tensorflow:master Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compute_output_shape behavior in normalization layers need to fix
3 participants