code: def downsample_2d(x, k=None, factor=2, gain=1):
      r"""Downsample2D a batch of 2D images with the given filter.
  
      Args:
      Accepts a batch of 2D images of the shape `[N, C, H, W]` or `[N, H, W, C]` and downsamples each image with the
      given filter. The filter is normalized so that if the input pixels are constant, they will be scaled by the
      specified `gain`. Pixels outside the image are assumed to be zero, and the filter is padded with zeros so that its
      shape is a multiple of the downsampling factor.
          x: Input tensor of the shape `[N, C, H, W]` or `[N, H, W,
            C]`.
          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).
  
      Returns:
          Tensor of the shape `[N, C, H // factor, W // factor]`
      """
  
      assert isinstance(factor, int) and factor >= 1
      if k is None:
          k = [1] * factor
  
      k = np.asarray(k, dtype=np.float32)
      if k.ndim == 1:
          k = np.outer(k, k)
      k /= np.sum(k)
  
      k = k * gain
      p = k.shape[0] - factor
      return upfirdn2d_native(
          x,
          paddle.to_tensor(k),
          down=factor,
          pad=((p + 1) // 2, p // 2),
      )
  
imports: from functools import partial
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
label_desc: Use image node_id 3 for calling a global function with example usage: downsample_2d(x, k, factor, gain) and returns: upfirdn2d_native