Repository: tensorflow/addons

Issue:
`compute_output_shape`  behavior in normalization layers need to fix
**System information**
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Window 11
- TensorFlow version and how it was installed (source or binary): binary
- TensorFlow-Addons version and how it was installed (source or binary): binary 
- Python version: 3.9.7
- Is GPU used? (yes/no): yes

**Describe the bug**
When calling function `compute_output_shape`  of `tfa.layers.GroupNormalization`, `tfa.layers.InstanceNormalization` and `tfa.layers.FilterResponseNormalization` ,  the layer will not be built, different form the description in `compute_output_shape`, such as ["https://github.com/keras-team/keras/blob/v2.8.0/keras/engine/base_layer.py#L798-L842"](https://tensorflow.google.cn/addons/api_docs/python/tfa/layers/GroupNormalization?hl=en#compute_output_shape):

> compute_output_shape
> [View source](https://github.com/tensorflow/addons/blob/v0.15.0/tensorflow_addons/layers/normalizations.py#L158-L159)
> compute_output_shape(input_shape)
> Computes the output shape of the layer.
> If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

**Code to reproduce the issue**
```
>>> import tensorflow as tf
>>> import tensorflow_addons as tfa
>>> layer = tfa.layers.GroupNormalization(groups=2, center=True, scale=True)
>>> layer.compute_output_shape(input_shape=[8, 28, 28, 16])
[8, 28, 28, 16]
>>> print(len(layer.varibales))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'GroupNormalization' object has no attribute 'varibales'
>>> print(len(layer.trainable_varibales))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'GroupNormalization' object has no attribute 'trainable_varibales'
>>> assert len(layer.trainable_variables) == 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
```
**Other info / logs**
I deeply know the bug.  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` in  `tfa.layers.GroupNormalization`, `tfa.layers.InstanceNormalization` and `tfa.layers.FilterResponseNormalization`, the bug will disappear.



Discussion:

Resolving patch:
diff --git a/tensorflow_addons/layers/normalizations.py b/tensorflow_addons/layers/normalizations.py
--- a/tensorflow_addons/layers/normalizations.py
+++ b/tensorflow_addons/layers/normalizations.py
@@ -155,9 +155,6 @@ def get_config(self):
         base_config = super().get_config()
         return {**base_config, **config}
 
-    def compute_output_shape(self, input_shape):
-        return input_shape
-
     def _reshape_into_groups(self, inputs, input_shape, tensor_input_shape):
 
         group_shape = [tensor_input_shape[i] for i in range(len(input_shape))]
@@ -447,9 +444,6 @@ def call(self, inputs):
         normalized_inputs = inputs * tf.math.rsqrt(nu2 + epsilon)
         return self.gamma * normalized_inputs + self.beta
 
-    def compute_output_shape(self, input_shape):
-        return input_shape
-
     def get_config(self):
         config = {
             "axis": self.axis,


Test patch:
diff --git a/tensorflow_addons/layers/tests/normalizations_test.py b/tensorflow_addons/layers/tests/normalizations_test.py
--- a/tensorflow_addons/layers/tests/normalizations_test.py
+++ b/tensorflow_addons/layers/tests/normalizations_test.py
@@ -346,6 +346,52 @@ def test_groupnorm_convnet_no_center_no_scale():
     )
 
 
+@pytest.mark.usefixtures("maybe_run_functions_eagerly")
+@pytest.mark.parametrize("center", [True, False])
+@pytest.mark.parametrize("scale", [True, False])
+def test_group_norm_compute_output_shape(center, scale):
+
+    target_variables_len = [center, scale].count(True)
+    target_trainable_variables_len = [center, scale].count(True)
+    layer1 = GroupNormalization(groups=2, center=center, scale=scale)
+    layer1.build(input_shape=[8, 28, 28, 16])  # build()
+    assert len(layer1.variables) == target_variables_len
+    assert len(layer1.trainable_variables) == target_trainable_variables_len
+
+    layer2 = GroupNormalization(groups=2, center=center, scale=scale)
+    layer2.compute_output_shape(input_shape=[8, 28, 28, 16])  # compute_output_shape()
+    assert len(layer2.variables) == target_variables_len
+    assert len(layer2.trainable_variables) == target_trainable_variables_len
+
+    layer3 = GroupNormalization(groups=2, center=center, scale=scale)
+    layer3(tf.random.normal(shape=[8, 28, 28, 16]))  # call()
+    assert len(layer3.variables) == target_variables_len
+    assert len(layer3.trainable_variables) == target_trainable_variables_len
+
+
+@pytest.mark.usefixtures("maybe_run_functions_eagerly")
+@pytest.mark.parametrize("center", [True, False])
+@pytest.mark.parametrize("scale", [True, False])
+def test_instance_norm_compute_output_shape(center, scale):
+
+    target_variables_len = [center, scale].count(True)
+    target_trainable_variables_len = [center, scale].count(True)
+    layer1 = InstanceNormalization(groups=2, center=center, scale=scale)
+    layer1.build(input_shape=[8, 28, 28, 16])  # build()
+    assert len(layer1.variables) == target_variables_len
+    assert len(layer1.trainable_variables) == target_trainable_variables_len
+
+    layer2 = InstanceNormalization(groups=2, center=center, scale=scale)
+    layer2.compute_output_shape(input_shape=[8, 28, 28, 16])  # compute_output_shape()
+    assert len(layer2.variables) == target_variables_len
+    assert len(layer2.trainable_variables) == target_trainable_variables_len
+
+    layer3 = InstanceNormalization(groups=2, center=center, scale=scale)
+    layer3(tf.random.normal(shape=[8, 28, 28, 16]))  # call()
+    assert len(layer3.variables) == target_variables_len
+    assert len(layer3.trainable_variables) == target_trainable_variables_len
+
+
 def calculate_frn(
     x, beta=0.2, gamma=1, eps=1e-6, learned_epsilon=False, dtype=np.float32
 ):
@@ -471,3 +517,23 @@ def test_filter_response_normalization_save(tmpdir):
     model.save(filepath, save_format="h5")
     filepath = str(tmpdir / "test")
     model.save(filepath, save_format="tf")
+
+
+@pytest.mark.usefixtures("maybe_run_functions_eagerly")
+def test_filter_response_norm_compute_output_shape():
+    target_variables_len = 2
+    target_trainable_variables_len = 2
+    layer1 = FilterResponseNormalization()
+    layer1.build(input_shape=[8, 28, 28, 16])  # build()
+    assert len(layer1.variables) == target_variables_len
+    assert len(layer1.trainable_variables) == target_trainable_variables_len
+
+    layer2 = FilterResponseNormalization()
+    layer2.compute_output_shape(input_shape=[8, 28, 28, 16])  # compute_output_shape()
+    assert len(layer2.variables) == target_variables_len
+    assert len(layer2.trainable_variables) == target_trainable_variables_len
+
+    layer3 = FilterResponseNormalization()
+    layer3(tf.random.normal(shape=[8, 28, 28, 16]))  # call()
+    assert len(layer3.variables) == target_variables_len
+    assert len(layer3.trainable_variables) == target_trainable_variables_len