code: def conv_downsample_2d(
      x, w, k=None, factor=2, gain=1, data_format="NCHW", impl="cuda"
  ):
      r"""Fused `tf.nn.conv2d()` followed by `downsample_2d()`.
  
      Padding is performed only once at the beginning, not between the operations.
      The fused op is considerably more efficient than performing the same calculation
      using standard TensorFlow ops. It supports gradients of arbitrary order.
  
      Args:
          x:            Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`.
          w:            Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`.
                        Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`.
          k:            FIR filter of the shape `[firH, firW]` or `[firN]` (separable).
                        The default is `[1] * factor`, which corresponds to average pooling.
          factor:       Integer downsampling factor (default: 2).
          gain:         Scaling factor for signal magnitude (default: 1.0).
          data_format:  `'NCHW'` or `'NHWC'` (default: `'NCHW'`).
          impl:         Name of the implementation to use. Can be `"ref"` or `"cuda"` (default).
  
      Returns:
          Tensor of the shape `[N, C, H // factor, W // factor]` or
          `[N, H // factor, W // factor, C]`, and same datatype as `x`.
      """
  
      assert isinstance(factor, int) and factor >= 1
      w = tf.convert_to_tensor(w)
      convH, convW, _inC, _outC = w.shape.as_list()
      assert convW == convH
      if k is None:
          k = [1] * factor
      k = _setup_kernel(k) * gain
      p = (k.shape[0] - factor) + (convW - 1)
      if data_format == "NCHW":
          s = [1, 1, factor, factor]
      else:
          s = [1, factor, factor, 1]
      x = _simple_upfirdn_2d(
          x,
          k,
          pad0=(p + 1) // 2,
          pad1=p // 2,
          data_format=data_format,
          impl=impl,
      )
      return tf.nn.conv2d(
          x, w, strides=s, padding="VALID", data_format=data_format
      )
  
file_path: insightface/reconstruction/ostec/external/stylegan2/dnnlib/tflib/ops/upfirdn_2d.py
imports: import os
  import numpy
  import tensorflow
  from ..None import custom_ops
label_desc: Use image node_id 9 for calling a global function with example usage: conv_downsample_2d(x, w, k, factor, gain, data_format, impl) and returns: tf