(inputs, z, is_training, use_sn,
                              center=True, scale=True,
                              name="batch_norm", num_hidden=32)
Performs a self-modulated batch normalization.

  Details can be found in "On Self Modulation for Generative Adversarial
  Networks", Chen T. et al., 2018. [https://arxiv.org/abs/1810.01365]

  Like a normal batch normalization but the scale and offset are trainable
  transformation of `z`.

  Args:
    inputs: A tensor with 2 or 4 dimensions, where the first dimension is
      `batch_size`. The normalization is over all but the last dimension if
      `data_format` is `NHWC`, and the second dimension if `data_format` is
      `NCHW`.
    z: 2-D tensor with shape [batch_size, ?] with the latent code.
    is_training: Whether or not the layer is in training mode.
    use_sn: Whether to apply spectral normalization to the weights of the
      hidden layer and the linear transformations.
    center: If True, add offset of beta to normalized tensor.
    scale: If True, multiply by gamma. When the next layer is linear  this can
      be disabled since the scaling will be done by the next layer.
    name: Name of the variable scope.
    num_hidden: Number of hidden units in the hidden layer. If 0 the scale and
      offset are simple linear transformations of `z`.

  Returns:
Performs a self-modulated batch normalization.
Performs a self - modulated batch normalization .
def self_modulated_batch_norm(inputs, z, is_training, use_sn,
                              center=True, scale=True,
                              name="batch_norm", num_hidden=32):
  """Performs a self-modulated batch normalization.

  Details can be found in "On Self Modulation for Generative Adversarial
  Networks", Chen T. et al., 2018. [https://arxiv.org/abs/1810.01365]

  Like a normal batch normalization but the scale and offset are trainable
  transformation of `z`.

  Args:
    inputs: A tensor with 2 or 4 dimensions, where the first dimension is
      `batch_size`. The normalization is over all but the last dimension if
      `data_format` is `NHWC`, and the second dimension if `data_format` is
      `NCHW`.
    z: 2-D tensor with shape [batch_size, ?] with the latent code.
    is_training: Whether or not the layer is in training mode.
    use_sn: Whether to apply spectral normalization to the weights of the
      hidden layer and the linear transformations.
    center: If True, add offset of beta to normalized tensor.
    scale: If True, multiply by gamma. When the next layer is linear  this can
      be disabled since the scaling will be done by the next layer.
    name: Name of the variable scope.
    num_hidden: Number of hidden units in the hidden layer. If 0 the scale and
      offset are simple linear transformations of `z`.

  Returns:
  """
  if z is None:
    raise ValueError("You must provide z for self modulation.")
  with tf.variable_scope(name, values=[inputs]):
    outputs = standardize_batch(inputs, is_training=is_training)
    num_channels = inputs.shape[-1].value

    with tf.variable_scope("sbn", values=[inputs, z]):
      h = z
      if num_hidden > 0:
        h = linear(h, num_hidden, scope="hidden", use_sn=use_sn)
        h = tf.nn.relu(h)
      if scale:
        gamma = linear(h, num_channels, scope="gamma", bias_start=1.0,
                       use_sn=use_sn)
        gamma = tf.reshape(gamma, [-1, 1, 1, num_channels])
        outputs *= gamma
      if center:
        beta = linear(h, num_channels, scope="beta", use_sn=use_sn)
        beta = tf.reshape(beta, [-1, 1, 1, num_channels])
        outputs += beta
      return outputs
def self_modulated_batch_norm ( inputs , z , is_training , use_sn , center = True , scale = True , name = "batch_norm" , num_hidden = 32 ) : if z is None : raise ValueError ( "You must provide z for self modulation." ) with tf . variable_scope ( name , values = [ inputs ] ) : outputs = standardize_batch ( inputs , is_training = is_training ) num_channels = inputs . shape [ - 1 ] . value with tf . variable_scope ( "sbn" , values = [ inputs , z ] ) : h = z if num_hidden > 0 : h = linear ( h , num_hidden , scope = "hidden" , use_sn = use_sn ) h = tf . nn . relu ( h ) if scale : gamma = linear ( h , num_channels , scope = "gamma" , bias_start = 1.0 , use_sn = use_sn ) gamma = tf . reshape ( gamma , [ - 1 , 1 , 1 , num_channels ] ) outputs *= gamma if center : beta = linear ( h , num_channels , scope = "beta" , use_sn = use_sn ) beta = tf . reshape ( beta , [ - 1 , 1 , 1 , num_channels ] ) outputs += beta return outputs