code: def build_dataloader(cfg):
      """Build dataloader for training/validation"""
      train_dataset = VideoClsDataset(
          anno_path=cfg.CONFIG.DATA.TRAIN_ANNO_PATH,
          data_path=cfg.CONFIG.DATA.TRAIN_DATA_PATH,
          mode="train",
          use_multigrid=cfg.CONFIG.TRAIN.MULTIGRID.USE_SHORT_CYCLE
          or cfg.CONFIG.TRAIN.MULTIGRID.USE_LONG_CYCLE,
          clip_len=cfg.CONFIG.DATA.CLIP_LEN,
          frame_sample_rate=cfg.CONFIG.DATA.FRAME_RATE,
          num_segment=cfg.CONFIG.DATA.NUM_SEGMENT,
          num_crop=cfg.CONFIG.DATA.NUM_CROP,
          keep_aspect_ratio=cfg.CONFIG.DATA.KEEP_ASPECT_RATIO,
          crop_size=cfg.CONFIG.DATA.CROP_SIZE,
          short_side_size=cfg.CONFIG.DATA.SHORT_SIDE_SIZE,
          new_height=cfg.CONFIG.DATA.NEW_HEIGHT,
          new_width=cfg.CONFIG.DATA.NEW_WIDTH,
      )
      val_dataset = VideoClsDataset(
          anno_path=cfg.CONFIG.DATA.VAL_ANNO_PATH,
          data_path=cfg.CONFIG.DATA.VAL_DATA_PATH,
          mode="validation",
          use_multigrid=False,
          clip_len=cfg.CONFIG.DATA.CLIP_LEN,
          frame_sample_rate=cfg.CONFIG.DATA.FRAME_RATE,
          num_segment=cfg.CONFIG.DATA.NUM_SEGMENT,
          num_crop=cfg.CONFIG.DATA.NUM_CROP,
          keep_aspect_ratio=cfg.CONFIG.DATA.KEEP_ASPECT_RATIO,
          crop_size=cfg.CONFIG.DATA.CROP_SIZE,
          short_side_size=cfg.CONFIG.DATA.SHORT_SIDE_SIZE,
          new_height=cfg.CONFIG.DATA.NEW_HEIGHT,
          new_width=cfg.CONFIG.DATA.NEW_WIDTH,
      )
  
      if cfg.DDP_CONFIG.DISTRIBUTED:
          train_sampler = (
              torch.utils.data.distributed.DistributedSampler(
                  train_dataset
              )
          )
          val_sampler = torch.utils.data.distributed.DistributedSampler(
              val_dataset
          )
      else:
          train_sampler = None
          val_sampler = None
  
      mg_sampler = None
      if (
          cfg.CONFIG.TRAIN.MULTIGRID.USE_LONG_CYCLE
          or cfg.CONFIG.TRAIN.MULTIGRID.USE_SHORT_CYCLE
      ):
          mg_sampler = MultiGridBatchSampler(
              train_sampler,
              batch_size=cfg.CONFIG.TRAIN.BATCH_SIZE,
              drop_last=True,
              use_long=cfg.CONFIG.TRAIN.MULTIGRID.USE_LONG_CYCLE,
              use_short=cfg.CONFIG.TRAIN.MULTIGRID.USE_SHORT_CYCLE,
          )
          train_loader = torch.utils.data.DataLoader(
              train_dataset,
              batch_size=1,
              shuffle=False,
              num_workers=9,
              pin_memory=True,
              batch_sampler=mg_sampler,
          )
      else:
          train_loader = torch.utils.data.DataLoader(
              train_dataset,
              batch_size=cfg.CONFIG.TRAIN.BATCH_SIZE,
              shuffle=(train_sampler is None),
              num_workers=9,
              sampler=train_sampler,
              pin_memory=True,
          )
  
      val_loader = torch.utils.data.DataLoader(
          val_dataset,
          batch_size=cfg.CONFIG.VAL.BATCH_SIZE,
          shuffle=(val_sampler is None),
          num_workers=9,
          sampler=val_sampler,
          pin_memory=True,
      )
  
      return (
          train_loader,
          val_loader,
          train_sampler,
          val_sampler,
          mg_sampler,
      )
  
file_path: gluon-cv/gluoncv/torch/data/video_cls/dataset_classification.py
imports: import os
  import warnings
  import numpy
  import torch
  from torch.utils.data import Dataset
  from ..transforms.videotransforms import video_transforms, volume_transforms
  from .multigrid_helper import multiGridHelper, MultiGridBatchSampler
label_desc: Use image node_id 1 for calling a global function with example usage: build_dataloader(cfg) and returns: train_loader,  val_loader,  train_sampler,  val_sampler,  mg_sampler