(inputs, y, is_training, use_sn, center=True,
                           scale=True, name="batch_norm", use_bias=False)
Conditional batch normalization.
Conditional batch normalization.
Conditional batch normalization .
def conditional_batch_norm(inputs, y, is_training, use_sn, center=True,
                           scale=True, name="batch_norm", use_bias=False):
  """Conditional batch normalization."""
  if y is None:
    raise ValueError("You must provide y for conditional batch normalization.")
  if y.shape.ndims != 2:
    raise ValueError("Conditioning must have rank 2.")
  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("condition", values=[inputs, y]):
      if scale:
        gamma = linear(y, num_channels, scope="gamma", use_sn=use_sn,
                       use_bias=use_bias)
        gamma = tf.reshape(gamma, [-1, 1, 1, num_channels])
        outputs *= gamma
      if center:
        beta = linear(y, num_channels, scope="beta", use_sn=use_sn,
                      use_bias=use_bias)
        beta = tf.reshape(beta, [-1, 1, 1, num_channels])
        outputs += beta
      return outputs
def conditional_batch_norm ( inputs , y , is_training , use_sn , center = True , scale = True , name = "batch_norm" , use_bias = False ) : if y is None : raise ValueError ( "You must provide y for conditional batch normalization." ) if y . shape . ndims != 2 : raise ValueError ( "Conditioning must have rank 2." ) 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 ( "condition" , values = [ inputs , y ] ) : if scale : gamma = linear ( y , num_channels , scope = "gamma" , use_sn = use_sn , use_bias = use_bias ) gamma = tf . reshape ( gamma , [ - 1 , 1 , 1 , num_channels ] ) outputs *= gamma if center : beta = linear ( y , num_channels , scope = "beta" , use_sn = use_sn , use_bias = use_bias ) beta = tf . reshape ( beta , [ - 1 , 1 , 1 , num_channels ] ) outputs += beta return outputs