(x, output_dim,
                         k_h, k_w, d_h, d_w,
                         init=False, init_scale=1.0,
                         stddev=0.02,
                         name="wn_deconv2d",
                         initializer=tf.truncated_normal_initializer)
Performs Transposed Convolution with Weight Normalization.
Performs Transposed Convolution with Weight Normalization.
Performs Transposed Convolution with Weight Normalization .
def weight_norm_deconv2d(x, output_dim,
                         k_h, k_w, d_h, d_w,
                         init=False, init_scale=1.0,
                         stddev=0.02,
                         name="wn_deconv2d",
                         initializer=tf.truncated_normal_initializer):
  """Performs Transposed Convolution with Weight Normalization."""
  xs = x.get_shape().as_list()
  target_shape = [xs[0], xs[1] * d_h, xs[2] * d_w, output_dim]
  with tf.variable_scope(name):
    if init:
      v = tf.get_variable(
          "V", [k_h, k_w] + [output_dim, int(x.get_shape()[-1])],
          tf.float32, initializer(0, stddev), trainable=True)
      v_norm = tf.nn.l2_normalize(v.initialized_value(), [0, 1, 3])
      x_init = tf.nn.conv2d_transpose(x, v_norm, target_shape,
                                      [1, d_h, d_w, 1], padding="SAME")
      m_init, v_init = tf.nn.moments(x_init, [0, 1, 2])
      scale_init = init_scale/tf.sqrt(v_init + 1e-8)
      g = tf.get_variable("g", dtype=tf.float32,
                          initializer=scale_init, trainable=True)
      b = tf.get_variable("b", dtype=tf.float32,
                          initializer=-m_init*scale_init, trainable=True)
      x_init = tf.reshape(scale_init, [1, 1, 1, output_dim]) * (
          x_init - tf.reshape(m_init, [1, 1, 1, output_dim]))
      return x_init
    else:
      v = tf.get_variable("v")
      g = tf.get_variable("g")
      b = tf.get_variable("b")
      tf.assert_variables_initialized([v, g, b])
      w = tf.reshape(g, [1, 1, output_dim, 1]) * tf.nn.l2_normalize(
          v, [0, 1, 3])
      x = tf.nn.conv2d_transpose(x, w, target_shape, strides=[1, d_h, d_w, 1],
                                 padding="SAME")
      x = tf.nn.bias_add(x, b)
      return x
def weight_norm_deconv2d ( x , output_dim , k_h , k_w , d_h , d_w , init = False , init_scale = 1.0 , stddev = 0.02 , name = "wn_deconv2d" , initializer = tf . truncated_normal_initializer ) : xs = x . get_shape ( ) . as_list ( ) target_shape = [ xs [ 0 ] , xs [ 1 ] * d_h , xs [ 2 ] * d_w , output_dim ] with tf . variable_scope ( name ) : if init : v = tf . get_variable ( "V" , [ k_h , k_w ] + [ output_dim , int ( x . get_shape ( ) [ - 1 ] ) ] , tf . float32 , initializer ( 0 , stddev ) , trainable = True ) v_norm = tf . nn . l2_normalize ( v . initialized_value ( ) , [ 0 , 1 , 3 ] ) x_init = tf . nn . conv2d_transpose ( x , v_norm , target_shape , [ 1 , d_h , d_w , 1 ] , padding = "SAME" ) m_init , v_init = tf . nn . moments ( x_init , [ 0 , 1 , 2 ] ) scale_init = init_scale / tf . sqrt ( v_init + 1e-8 ) g = tf . get_variable ( "g" , dtype = tf . float32 , initializer = scale_init , trainable = True ) b = tf . get_variable ( "b" , dtype = tf . float32 , initializer = - m_init * scale_init , trainable = True ) x_init = tf . reshape ( scale_init , [ 1 , 1 , 1 , output_dim ] ) * ( x_init - tf . reshape ( m_init , [ 1 , 1 , 1 , output_dim ] ) ) return x_init else : v = tf . get_variable ( "v" ) g = tf . get_variable ( "g" ) b = tf . get_variable ( "b" ) tf . assert_variables_initialized ( [ v , g , b ] ) w = tf . reshape ( g , [ 1 , 1 , output_dim , 1 ] ) * tf . nn . l2_normalize ( v , [ 0 , 1 , 3 ] ) x = tf . nn . conv2d_transpose ( x , w , target_shape , strides = [ 1 , d_h , d_w , 1 ] , padding = "SAME" ) x = tf . nn . bias_add ( x , b ) return x