(input_, output_dim,
                       k_h, k_w, d_h, d_w,
                       init, init_scale,
                       stddev=0.02,
                       name="wn_conv2d",
                       initializer=tf.truncated_normal_initializer)
Performs convolution with Weight Normalization.
Performs convolution with Weight Normalization.
Performs convolution with Weight Normalization .
def weight_norm_conv2d(input_, output_dim,
                       k_h, k_w, d_h, d_w,
                       init, init_scale,
                       stddev=0.02,
                       name="wn_conv2d",
                       initializer=tf.truncated_normal_initializer):
  """Performs convolution with Weight Normalization."""
  with tf.variable_scope(name):
    if init:
      v = tf.get_variable(
          "V", [k_h, k_w] + [int(input_.get_shape()[-1]), output_dim],
          tf.float32, initializer(0, stddev), trainable=True)
      v_norm = tf.nn.l2_normalize(v.initialized_value(), [0, 1, 2])
      x_init = tf.nn.conv2d(input_, v_norm, strides=[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, 1, output_dim]) * tf.nn.l2_normalize(
          v, [0, 1, 2])
      x = tf.nn.bias_add(
          tf.nn.conv2d(input_, w, [1, d_h, d_w, 1], padding="SAME"), b)
      return x
def weight_norm_conv2d ( input_ , output_dim , k_h , k_w , d_h , d_w , init , init_scale , stddev = 0.02 , name = "wn_conv2d" , initializer = tf . truncated_normal_initializer ) : with tf . variable_scope ( name ) : if init : v = tf . get_variable ( "V" , [ k_h , k_w ] + [ int ( input_ . get_shape ( ) [ - 1 ] ) , output_dim ] , tf . float32 , initializer ( 0 , stddev ) , trainable = True ) v_norm = tf . nn . l2_normalize ( v . initialized_value ( ) , [ 0 , 1 , 2 ] ) x_init = tf . nn . conv2d ( input_ , v_norm , strides = [ 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 , 1 , output_dim ] ) * tf . nn . l2_normalize ( v , [ 0 , 1 , 2 ] ) x = tf . nn . bias_add ( tf . nn . conv2d ( input_ , w , [ 1 , d_h , d_w , 1 ] , padding = "SAME" ) , b ) return x