def spectral_norm(w, num_iters=1, update_collection=None):
    """
    https://github.com/taki0112/BigGAN-Tensorflow/blob/master/ops.py
    """
    w_shape = w.shape.as_list()
    w = tf.reshape(w, [-1, w_shape[-1]])

    u = tf.get_variable("u", [1, w_shape[-1]], initializer=tf.truncated_normal_initializer(), trainable=False)

    u_hat = u
    v_hat = None
    for _ in range(num_iters):
        v_ = tf.matmul(u_hat, w, transpose_b=True)
        v_hat = _l2normalize(v_)

        u_ = tf.matmul(v_hat, w)
        u_hat = _l2normalize(u_)

    sigma = tf.squeeze(tf.matmul(tf.matmul(v_hat, w), u_hat, transpose_b=True))
    w_norm = w / sigma

    if update_collection is None:
        with tf.control_dependencies([u.assign(u_hat)]):
            w_norm = tf.reshape(w_norm, w_shape)
    elif update_collection == "NO_OPS":
        w_norm = tf.reshape(w_norm, w_shape)
    else:
        raise NotImplementedError

    return w_norm

    https://github.com/taki0112/BigGAN-Tensorflow/blob/master/ops.py
    
examples/inverse_gan_author_utils.py