code: def downsample_seg_for_ds_transform3(
      seg,
      ds_scales=((1, 1, 1), (0.5, 0.5, 0.5), (0.25, 0.25, 0.25)),
      classes=None,
  ):
      output = []
      one_hot = paddle.to_tensor(
          convert_seg_image_to_one_hot_encoding_batched(seg, classes)
      )
  
      for s in ds_scales:
          if all([i == 1 for i in s]):
              output.append(paddle.to_tensor(seg))
          else:
              kernel_size = tuple(int(1 / i) for i in s)
              stride = kernel_size
              pad = tuple((i - 1) // 2 for i in kernel_size)
  
              if len(s) == 2:
                  pool_op = avg_pool2d
              elif len(s) == 3:
                  pool_op = avg_pool3d
              else:
                  raise RuntimeError()
  
              pooled = pool_op(
                  one_hot,
                  kernel_size,
                  stride,
                  pad,
                  count_include_pad=False,
                  ceil_mode=False,
              )
              output.append(pooled)
      return output
  
imports: import random
  import numpy
  import paddle
  from paddle.nn.functional import avg_pool2d, avg_pool3d
  from typing import List, Tuple, Union, Callable
  from copy import deepcopy
  from scipy.ndimage import map_coordinates, fourier_gaussian
  from scipy.ndimage.filters import gaussian_filter, gaussian_gradient_magnitude
  from scipy.ndimage.morphology import grey_dilation
  from skimage.transform import resize
  from scipy.ndimage.measurements import label
label_desc: Use image node_id 4 for calling a global function with example usage: downsample_seg_for_ds_transform3(seg, ds_scales, classes) and returns: output