code: def custom_conv2d(
      x,
      filters,
      kernel_size,
      strides=(1, 1),
      padding="SAME",
      activation=None,
      he_initializer_slope=1.0,
      use_weight_scaling=True,
      scope="custom_conv2d",
      reuse=None,
  ):
      """Custom conv2d layer.
  
      In comparison with tf.layers.conv2d this implementation use the He initializer
      to initialize convolutional kernel and the weight scaling trick (if
      `use_weight_scaling` is True) to equalize learning rates. See
      https://arxiv.org/abs/1710.10196 for more details.
  
      Args:
        x: A `Tensor` of NHWC format.
        filters: An int of output channels.
        kernel_size: An integer or a int tuple of [kernel_height, kernel_width].
        strides: A list of strides.
        padding: One of "VALID" or "SAME".
        activation: An activation function to be applied. None means no
            activation. Defaults to None.
        he_initializer_slope: A float slope for the He initializer. Defaults to 1.0.
        use_weight_scaling: Whether to apply weight scaling. Defaults to True.
        scope: A string or variable scope.
        reuse: Whether to reuse the weights. Defaults to None.
  
      Returns:
        A `Tensor` of NHWC format where the last dimension has size `filters`.
      """
      if not isinstance(kernel_size, (list, tuple)):
          kernel_size = [kernel_size] * 2
      kernel_size = list(kernel_size)
  
      def _apply_kernel(kernel_shape, kernel_initializer):
          return tf.layers.conv2d(
              x,
              filters=filters,
              kernel_size=kernel_shape[0:2],
              strides=strides,
              padding=padding,
              use_bias=False,
              kernel_initializer=kernel_initializer,
          )
  
      with tf.variable_scope(scope, reuse=reuse):
          return _custom_layer_impl(
              _apply_kernel,
              kernel_shape=kernel_size
              + [x.shape.as_list()[3], filters],
              bias_shape=(filters,),
              activation=activation,
              he_initializer_slope=he_initializer_slope,
              use_weight_scaling=use_weight_scaling,
          )
  
file_path: magenta/magenta/models/gansynth/lib/layers.py
imports: import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 12 for calling a global function with example usage: custom_conv2d(x, filters, kernel_size, strides, padding, activation, he_initializer_slope, use_weight_scaling, scope, reuse) and returns: tf, _custom_layer_impl