Repository: tensorflow/addons

Issue:
WeightNormalization layer can't save in h5
**System information**
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
Ubuntu 16.04.6 LTS
- TensorFlow version and how it was installed (source or binary):
tensorflow-gpu                   2.0.0, binary
- TensorFlow-Addons version and how it was installed (source or binary):
tensorflow-addons                0.6.0, binary
- Python version:
Python 3.6.9
- Is GPU used? (yes/no):
yes
**Describe the bug**
WeightNormalization layer can't save to h5

A clear and concise description of what the bug is.
WeightNormalization causing duplicate names of variables.

**Code to reproduce the issue**

```python
import tensorflow as tf
import tensorflow_addons as tfa

conv = tf.keras.layers.Conv1D(1, 1, name='conv')
wn_conv = tfa.layers.WeightNormalization(conv)

model = tf.keras.Sequential(layers=[wn_conv])
model.build([1, 2, 3])
print([w.name for w in model.layers[0].weights])
model.save_weights('model.h5')
```

Provide a reproducible test case that is the bare minimum necessary to generate the problem.
See above.

**Other info / logs**

```
['weight_normalization/g:0', 'weight_normalization/kernel:0', 'weight_normalization/bias:0', 'weight_normalization/initialized:0', 'weight_normalization/kernel:0', 'weight_normalization/bias:0']
Traceback (most recent call last):
  File "/home/ubuntu/hankcs/laser/tests/playground/wn_bug.py", line 14, in <module>
    model.save_weights('model.h5')
  File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py", line 1074, in save_weights
    saving.save_weights_to_hdf5_group(f, self.layers)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 631, in save_weights_to_hdf5_group
    param_dset = g.create_dataset(name, val.shape, dtype=val.dtype)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/h5py/_hl/group.py", line 139, in create_dataset
    self[name] = dset
  File "/home/ubuntu/.local/lib/python3.6/site-packages/h5py/_hl/group.py", line 371, in __setitem__
    h5o.link(obj.id, self.id, name, lcpl=lcpl, lapl=self._lapl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5o.pyx", line 202, in h5py.h5o.link
RuntimeError: Unable to create link (name already exists)
```

There are 2 `weight_normalization/kernel:0`.



Discussion:
Thanks for reporting @hankcs! I'll take a look at this when time allows, but if anyone else is interested in investigating/patching it'd be much appreciated, just post your findings in this issue.

Resolving patch:
diff --git a/tensorflow_addons/layers/wrappers.py b/tensorflow_addons/layers/wrappers.py
--- a/tensorflow_addons/layers/wrappers.py
+++ b/tensorflow_addons/layers/wrappers.py
@@ -93,12 +93,14 @@ def build(self, input_shape):
 
         if self.data_init:
             # Used for data initialization in self._data_dep_init.
-            layer_config = tf.keras.layers.serialize(self.layer)
-            layer_config['config']['trainable'] = False
-            self._naked_clone_layer = tf.keras.layers.deserialize(layer_config)
-            self._naked_clone_layer.build(input_shape)
-            self._naked_clone_layer.set_weights(self.layer.get_weights())
-            self._naked_clone_layer.activation = None
+            with tf.name_scope('data_dep_init'):
+                layer_config = tf.keras.layers.serialize(self.layer)
+                layer_config['config']['trainable'] = False
+                self._naked_clone_layer = tf.keras.layers.deserialize(
+                    layer_config)
+                self._naked_clone_layer.build(input_shape)
+                self._naked_clone_layer.set_weights(self.layer.get_weights())
+                self._naked_clone_layer.activation = None
 
         self.built = True
 


Test patch:
diff --git a/tensorflow_addons/layers/wrappers_test.py b/tensorflow_addons/layers/wrappers_test.py
--- a/tensorflow_addons/layers/wrappers_test.py
+++ b/tensorflow_addons/layers/wrappers_test.py
@@ -81,6 +81,14 @@ def test_weightnorm_with_time_dist(self):
         out = tf.keras.layers.TimeDistributed(b)(inputs)
         model = tf.keras.Model(inputs, out)
 
+    def test_save_file_h5(self):
+        self.create_tempfile('wrapper_test_model.h5')
+        conv = tf.keras.layers.Conv1D(1, 1)
+        wn_conv = wrappers.WeightNormalization(conv)
+        model = tf.keras.Sequential(layers=[wn_conv])
+        model.build([1, 2, 3])
+        model.save_weights('wrapper_test_model.h5')
+
 
 if __name__ == "__main__":
     tf.test.main()