code: def dali_dataloader(args, mode, device):
      """
      Define a dali dataloader with configuration to operate datasets.
  
      Args:
          args(Namespace): Arguments obtained from ArgumentParser.
          mode(utils.Mode): Train or eval mode.
          device(int): Id of GPU to load data.
      Outputs:
          DALIGenericIterator(nvidia.dali.plugin.paddle.DALIGenericIterator)
              Iteratable outputs of DALI pipeline,
              including "data" and "label" in type of Paddle's Tensor.
      """
      assert "gpu" in device, "gpu training is required for DALI"
      assert mode in Mode, "Dataset mode should be in supported Modes"
  
      device_id = int(device.split(":")[1])
  
      seed = args.dali_random_seed
      num_threads = args.dali_num_threads
      batch_size = args.batch_size
  
      interp = 1  # settings.interpolation or 1  # default to linear
      interp_map = {
          # cv2.INTER_NEAREST
          0: types.DALIInterpType.INTERP_NN,
          # cv2.INTER_LINEAR
          1: types.DALIInterpType.INTERP_LINEAR,
          # cv2.INTER_CUBIC
          2: types.DALIInterpType.INTERP_CUBIC,
          # LANCZOS3 for cv2.INTER_LANCZOS4
          3: types.DALIInterpType.INTERP_LANCZOS3,
      }
      assert (
          interp in interp_map
      ), "interpolation method not supported by DALI"
      interp = interp_map[interp]
  
      normalize_scale = args.normalize_scale
      normalize_mean = args.normalize_mean
      normalize_std = args.normalize_std
      normalize_mean = [v / normalize_scale for v in normalize_mean]
      normalize_std = [v / normalize_scale for v in normalize_std]
  
      output_layout = args.data_layout[1:]  # NCHW -> CHW or NHWC -> HWC
      pad_output = args.image_channel == 4
      output_dtype = (
          types.FLOAT16 if args.dali_output_fp16 else types.FLOAT
      )
  
      shard_id = get_trainer_id()
      num_shards = get_num_trainers()
  
      scale = args.rand_crop_scale
      ratio = args.rand_crop_ratio
  
      ops_meta = PipeOpMeta(
          crop=args.crop_size,
          resize_shorter=args.resize_short,
          min_area=scale[0],
          max_area=scale[1],
          lower=ratio[0],
          upper=ratio[1],
          interp=interp,
          mean=normalize_mean,
          std=normalize_std,
          output_dtype=output_dtype,
          output_layout=output_layout,
          pad_output=pad_output,
      )
  
      file_root = args.image_root
  
      if mode == Mode.TRAIN:
          file_root = os.path.join(file_root, "train")
      else:
          file_root = os.path.join(file_root, "val")
  
      pipe = create_dali_pipeline(
          data_dir=file_root,
          batch_size=batch_size,
          is_training=mode == Mode.TRAIN,
          device_id=device_id,
          ops_meta=ops_meta,
          num_threads=num_threads,
          seed=seed + shard_id,
          shard_id=shard_id,
          num_shards=num_shards,
      )
      pipe.build()
      return DALIGenericIterator(
          [pipe], ["data", "label"], reader_name="Reader"
      )
  
file_path: DALI/docs/examples/use_cases/paddle/resnet50/dali.py
imports: import ctypes
  import os
  from dataclasses import dataclass
  import paddle
  import numpy
  from nvidia.dali.backend import TensorListCPU
  import nvidia.dali.fn
  import nvidia.dali.types
  from nvidia.dali.pipeline import pipeline_def
  from nvidia.dali.plugin.paddle import DALIGenericIterator
  from utils.mode import Mode
  from utils.utility import get_num_trainers, get_trainer_id
label_desc: Use image node_id 2 for calling a global function with example usage: dali_dataloader(args, mode, device) and returns: DALIGenericIterator