code: def get_loader(args, ds_type):
      if ds_type not in ("train", "val"):
          raise ValueError("ds_type has to be either 'train' or 'val'")
  
      if args.loader == "pytorch":
          if ds_type == "train":
              dataset = imageDataset(
                  args.frames,
                  args.is_cropped,
                  args.crop_size,
                  os.path.join(args.root, "train"),
                  args.batchsize,
                  args.world_size,
              )
  
              if args.world_size > 1:
                  sampler = (
                      torch.utils.data.distributed.DistributedSampler(
                          dataset
                      )
                  )
              else:
                  sampler = torch.utils.data.RandomSampler(dataset)
  
              loader = DataLoader(
                  dataset,
                  batch_size=args.batchsize,
                  shuffle=(sampler is None),
                  num_workers=0,
                  pin_memory=True,
                  sampler=sampler,
                  drop_last=True,
              )
  
              effective_bsz = args.batchsize * float(args.world_size)
              batches = math.ceil(len(dataset) / float(effective_bsz))
  
          if ds_type == "val":
              dataset = imageDataset(
                  args.frames,
                  args.is_cropped,
                  args.crop_size,
                  os.path.join(args.root, "val"),
                  args.batchsize,
                  args.world_size,
              )
  
              if args.world_size > 1:
                  sampler = (
                      torch.utils.data.distributed.DistributedSampler(
                          dataset
                      )
                  )
              else:
                  sampler = torch.utils.data.RandomSampler(dataset)
  
              loader = DataLoader(
                  dataset,
                  batch_size=1,
                  shuffle=False,
                  num_workers=1,
                  pin_memory=True,
                  sampler=sampler,
                  drop_last=True,
              )
  
              batches = math.ceil(len(dataset) / float(args.world_size))
  
      elif args.loader == "DALI":
          loader = DALILoader(
              args.batchsize,
              os.path.join(args.root, ds_type),
              args.frames,
              args.crop_size,
          )
          batches = len(loader)
          sampler = None
  
      else:
          raise ValueError(
              "%s is not a valid option for --loader" % args.loader
          )
  
      return loader, batches, sampler
  
file_path: DALI/docs/examples/use_cases/video_superres/dataloading/dataloaders.py
imports: import sys
  import copy
  from glob import glob
  import math
  import os
  import torch
  from torch.utils.data import DataLoader
  from dataloading.datasets import imageDataset
  from nvidia.dali.pipeline import pipeline_def
  from nvidia.dali.plugin import pytorch
  import nvidia.dali.fn
  import nvidia.dali.types
label_desc: Use image node_id 2 for calling a global function with example usage: get_loader(args, ds_type) and returns: loader,  batches,  sampler