class_docstr: Performs spectral normalization on weights.
  
  This wrapper controls the Lipschitz constant of the layer by
  constraining its spectral norm, which can stabilize the training of GANs.
  
  See [Spectral Normalization for Generative Adversarial Networks](https://arxiv.org/abs/1802.05957).
  
  Wrap `tf.keras.layers.Conv2D`:
  
  >>> x = np.random.rand(1, 10, 10, 1)
  >>> conv2d = SpectralNormalization(tf.keras.layers.Conv2D(2, 2))
  >>> y = conv2d(x)
  >>> y.shape
  TensorShape([1, 9, 9, 2])
  
  Wrap `tf.keras.layers.Dense`:
  
  >>> x = np.random.rand(1, 10, 10, 1)
  >>> dense = SpectralNormalization(tf.keras.layers.Dense(10))
  >>> y = dense(x)
  >>> y.shape
  TensorShape([1, 10, 10, 10])
  
  Args:
    layer: A `tf.keras.layers.Layer` instance that
      has either `kernel` or `embeddings` attribute.
    power_iterations: `int`, the number of iterations during normalization.
  Raises:
    AssertionError: If not initialized with a `Layer` instance.
    ValueError: If initialized with negative `power_iterations`.
    AttributeError: If `layer` does not has `kernel` or `embeddings` attribute.
docstr: Generate spectral normalized weights.
  
  This method will update the value of `self.w` with the
  spectral normalized value, so that the layer is ready for `call()`.
code: def normalize_weights(self):
      """Generate spectral normalized weights.
  
      This method will update the value of `self.w` with the
      spectral normalized value, so that the layer is ready for `call()`.
      """
  
      w = tf.reshape(self.w, [-1, self.w_shape[-1]])
      u = self.u
  
      with tf.name_scope("spectral_normalize"):
          for _ in range(self.power_iterations):
              v = tf.math.l2_normalize(
                  tf.matmul(u, w, transpose_b=True)
              )
              u = tf.math.l2_normalize(tf.matmul(v, w))
          u = tf.stop_gradient(u)
          v = tf.stop_gradient(v)
          sigma = tf.matmul(tf.matmul(v, w), u, transpose_b=True)
          self.u.assign(tf.cast(u, self.u.dtype))
          self.w.assign(
              tf.cast(
                  tf.reshape(self.w / sigma, self.w_shape), self.w.dtype
              )
          )
  
file_path: addons/tensorflow_addons/layers/spectral_normalization.py
imports: import tensorflow
  from typeguard import typechecked
label_desc: Use image node_id 5 for calling the SpectralNormalization obj's underlying member method code with example usage: obj.normalize_weights() without return types