code: def build_pipes(
      device,
      dim,
      batch_size,
      channel_first,
      mode,
      interp,
      dtype,
      w_input,
      h_input,
      d_input,
      use_size_arg,
      use_size_input,
      use_roi,
  ):
      dali_pipe = Pipeline(
          batch_size=batch_size, num_threads=8, device_id=0, seed=1234
      )
      with dali_pipe:
          if dim == 2:
              files, labels = dali.fn.readers.caffe(
                  path=db_2d_folder, random_shuffle=True
              )
              images_cpu = dali.fn.decoders.image(files, device="cpu")
          else:
              images_cpu = dali.fn.external_source(
                  source=random_3d_loader(batch_size), layout="DHWC"
              )
  
          images_hwc = (
              images_cpu if device == "cpu" else images_cpu.gpu()
          )
  
          if channel_first:
              images = dali.fn.transpose(
                  images_hwc,
                  perm=[3, 0, 1, 2] if dim == 3 else [2, 0, 1],
                  transpose_layout=True,
              )
          else:
              images = images_hwc
  
          roi_start = None
          roi_end = None
          w = None
          h = None
          d = None
          size = None
  
          minibatch_size = 2 if dim == 3 else 8
  
          if use_roi:
              # Calculate absolute RoI
              in_size = fn.slice(
                  fn.shapes(images_cpu),
                  types.Constant(0, dtype=types.FLOAT, device="cpu"),
                  types.Constant(dim, dtype=types.FLOAT, device="cpu"),
                  axes=[0],
                  normalized_shape=False,
              )
              roi_start = (
                  fn.random.uniform(range=(0, 0.4), shape=[dim])
                  * in_size
              )
              roi_end = (
                  fn.random.uniform(range=(0.6, 1.0), shape=[dim])
                  * in_size
              )
  
          size_range = (10, 200) if dim == 3 else (10, 1000)
  
          if use_size_arg:
              if use_size_input:
                  mask = fn.cast(
                      fn.random.uniform(range=(0.8, 1.9), shape=[dim]),
                      dtype=types.INT32,
                  )
                  size = (
                      fn.random.uniform(range=size_range, shape=[dim])
                      * mask
                  )
              else:
                  size = [300, 400] if dim == 2 else [80, 100, 120]
  
              resized = resize_dali(
                  images,
                  channel_first,
                  dtype,
                  interp,
                  mode,
                  size,
                  None,
                  None,
                  None,
                  roi_start,
                  roi_end,
                  minibatch_size=minibatch_size,
                  max_size=max_size(dim),
              )
          else:
              if w_input:
                  has_w = fn.random.coin_flip(probability=0.8)
                  w = fn.random.uniform(range=size_range) * has_w
              else:
                  w = 320  # some fixed value
  
              if h_input:
                  has_h = fn.random.coin_flip(probability=0.8)
                  h = fn.random.uniform(range=size_range) * has_h
              else:
                  h = 240  # some other fixed value
  
              if dim >= 3:
                  if d_input:
                      has_d = fn.random.coin_flip(probability=0.8)
                      d = fn.random.uniform(range=size_range) * has_d
                  else:
                      d = 31  # some other fixed value
  
              resized = resize_dali(
                  images,
                  channel_first,
                  dtype,
                  interp,
                  mode,
                  None,
                  w,
                  h,
                  d,
                  roi_start,
                  roi_end,
                  minibatch_size=minibatch_size,
                  max_size=max_size(dim),
              )
  
          outputs = [images, resized]
          if roi_start is not None and roi_end is not None:
              outputs += [roi_start, roi_end]
  
          for x in (d, h, w, size):
              if x is not None:
                  if isinstance(x, _DataNode):
                      outputs.append(x)
                  else:
                      outputs.append(
                          types.Constant(np.array(x, dtype=np.float32))
                      )
  
          dali_pipe.set_outputs(*outputs)
  
      pil_pipe = Pipeline(
          batch_size=batch_size,
          num_threads=8,
          device_id=0,
          exec_async=False,
          exec_pipelined=False,
      )
      with pil_pipe:
          images = fn.external_source(
              name="images", layout=layout_str(dim, channel_first)
          )
          sizes = fn.external_source(name="size")
          roi_start = fn.external_source(name="roi_start")
          roi_end = fn.external_source(name="roi_end")
          resized = resize_PIL(
              dim,
              channel_first,
              dtype,
              interp,
              images,
              sizes,
              roi_start,
              roi_end,
          )
          resized = fn.reshape(
              resized, layout=layout_str(dim, channel_first)
          )
          pil_pipe.set_outputs(resized)
      dali_pipe.build()
      pil_pipe.build()
  
      return dali_pipe, pil_pipe
  
imports: import cv2
  import functools
  import math
  import numpy
  import nvidia.dali
  import nvidia.dali.fn
  import nvidia.dali.types
  import os.path
  from nvidia.dali import Pipeline, pipeline_def
  from nvidia.dali.data_node import DataNode
  from test_utils import check_batch, get_dali_extra_path, as_array
  import PIL.Image
label_desc: Use image node_id 9 for calling a global function with example usage: build_pipes(device, dim, batch_size, channel_first, mode, interp, dtype, w_input, h_input, d_input, use_size_arg, use_size_input, use_roi) and returns: dali_pipe,  pil_pipe