class_docstr: Performs spectral normalization on the weights of a target layer.
  
  This wrapper controls the Lipschitz constant of the weights of a layer by
  constraining their spectral norm, which can stabilize the training of GANs.
  
  Args:
      layer: A `keras.layers.Layer` instance that
          has either a `kernel` (e.g. `Conv2D`, `Dense`...)
          or an `embeddings` attribute (`Embedding` layer).
      power_iterations: int, the number of iterations during normalization.
      **kwargs: Base wrapper keyword arguments.
  
  Examples:
  
  Wrap `keras.layers.Conv2D`:
  >>> x = np.random.rand(1, 10, 10, 1)
  >>> conv2d = SpectralNormalization(keras.layers.Conv2D(2, 2))
  >>> y = conv2d(x)
  >>> y.shape
  (1, 9, 9, 2)
  
  Wrap `keras.layers.Dense`:
  >>> x = np.random.rand(1, 10, 10, 1)
  >>> dense = SpectralNormalization(keras.layers.Dense(10))
  >>> y = dense(x)
  >>> y.shape
  (1, 10, 10, 10)
  
  Reference:
  
  - [Spectral Normalization for GAN](https://arxiv.org/abs/1802.05957).
docstr: Generate spectral normalized weights.
  
  This method will update the value of `self.kernel` with the
  spectral normalized value, so that the layer is ready for `call()`.
docstr_tok: ["Generate","spectral","normalized","weights",".","This","method","will","update","the","value","of","`","self.kernel","`","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.kernel` with the
      spectral normalized value, so that the layer is ready for `call()`.
      """
  
      weights = ops.reshape(self.kernel, [-1, self.kernel_shape[-1]])
      vector_u = self.vector_u
  
      # check for zeroes weights
      if not all([w == 0.0 for w in weights]):
          for _ in range(self.power_iterations):
              vector_v = normalize(
                  ops.matmul(vector_u, ops.transpose(weights)),
                  axis=None,
              )
              vector_u = normalize(
                  ops.matmul(vector_v, weights), axis=None
              )
          # vector_u = tf.stop_gradient(vector_u)
          # vector_v = tf.stop_gradient(vector_v)
          sigma = ops.matmul(
              ops.matmul(vector_v, weights), ops.transpose(vector_u)
          )
          self.vector_u.assign(ops.cast(vector_u, self.vector_u.dtype))
          self.kernel.assign(
              ops.cast(
                  ops.reshape(self.kernel / sigma, self.kernel_shape),
                  self.kernel.dtype,
              )
          )
  
file_path: keras/keras/layers/normalization/spectral_normalization.py
imports: from keras import initializers
  from keras import ops
  from keras.api_export import keras_export
  from keras.layers import Wrapper
  from keras.layers.input_spec import InputSpec
  from keras.utils.numerical_utils import normalize
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