code: def get_data_loader(
      opt, batch_size, num_workers, logger, kvstore=None
  ):
      data_dir = opt.data_dir
      val_data_dir = opt.val_data_dir
      scale_ratios = [float(i) for i in opt.scale_ratios.split(",")]
      input_size = opt.input_size
      default_mean = [0.485, 0.456, 0.406]
      default_std = [0.229, 0.224, 0.225]
  
      def batch_fn(batch, ctx):
          data = split_and_load(
              batch[0], ctx_list=ctx, batch_axis=0, even_split=False
          )
          label = split_and_load(
              batch[1], ctx_list=ctx, batch_axis=0, even_split=False
          )
          return data, label
  
      if opt.data_aug == "v1":
          # GluonCV style, not keeping aspect ratio, multi-scale crop
          transform_train = video.VideoGroupTrainTransform(
              size=(input_size, input_size),
              scale_ratios=scale_ratios,
              more_fix_crop=opt.more_fix_crop,
              max_distort=opt.max_distort,
              mean=default_mean,
              std=default_std,
          )
          transform_test = video.VideoGroupValTransform(
              size=input_size, mean=default_mean, std=default_std
          )
      elif opt.data_aug == "v2":
          # GluonCV style, keeping aspect ratio, multi-scale crop, same as mmaction style
          transform_train = video.VideoGroupTrainTransformV2(
              size=(input_size, input_size),
              short_side=opt.new_height,
              scale_ratios=scale_ratios,
              mean=default_mean,
              std=default_std,
          )
          transform_test = video.VideoGroupValTransformV2(
              crop_size=(input_size, input_size),
              short_side=opt.new_height,
              mean=default_mean,
              std=default_std,
          )
      elif opt.data_aug == "v3":
          # PySlowFast style, keeping aspect ratio, random short side scale jittering
          transform_train = video.VideoGroupTrainTransformV3(
              crop_size=(input_size, input_size),
              min_size=opt.new_height,
              max_size=opt.new_width,
              mean=default_mean,
              std=default_std,
          )
          transform_test = video.VideoGroupValTransformV2(
              crop_size=(input_size, input_size),
              short_side=opt.new_height,
              mean=default_mean,
              std=default_std,
          )
      elif opt.data_aug == "v4":
          # mmaction style, keeping aspect ratio, random crop and resize, only for SlowFast family models, similar to 'v3'
          transform_train = video.VideoGroupTrainTransformV4(
              size=(input_size, input_size),
              mean=default_mean,
              std=default_std,
          )
          transform_test = video.VideoGroupValTransformV2(
              crop_size=(input_size, input_size),
              short_side=opt.new_height,
              mean=default_mean,
              std=default_std,
          )
      else:
          logger.info(
              "Data augmentation %s is not supported yet."
              % (opt.data_aug)
          )
  
      if opt.dataset == "kinetics400":
          train_dataset = Kinetics400(
              setting=opt.train_list,
              root=data_dir,
              train=True,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              slowfast=opt.slowfast,
              slow_temporal_stride=opt.slow_temporal_stride,
              fast_temporal_stride=opt.fast_temporal_stride,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_train,
          )
          val_dataset = Kinetics400(
              setting=opt.val_list,
              root=val_data_dir,
              train=False,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              slowfast=opt.slowfast,
              slow_temporal_stride=opt.slow_temporal_stride,
              fast_temporal_stride=opt.fast_temporal_stride,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_test,
          )
      elif opt.dataset == "ucf101":
          train_dataset = UCF101(
              setting=opt.train_list,
              root=data_dir,
              train=True,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              target_width=input_size,
              target_height=input_size,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_train,
          )
          val_dataset = UCF101(
              setting=opt.val_list,
              root=data_dir,
              train=False,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              target_width=input_size,
              target_height=input_size,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_test,
          )
      elif opt.dataset == "somethingsomethingv2":
          train_dataset = SomethingSomethingV2(
              setting=opt.train_list,
              root=data_dir,
              train=True,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_train,
          )
          val_dataset = SomethingSomethingV2(
              setting=opt.val_list,
              root=data_dir,
              train=False,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_test,
          )
      elif opt.dataset == "hmdb51":
          train_dataset = HMDB51(
              setting=opt.train_list,
              root=data_dir,
              train=True,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_train,
          )
          val_dataset = HMDB51(
              setting=opt.val_list,
              root=data_dir,
              train=False,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_test,
          )
      elif opt.dataset == "custom":
          train_dataset = VideoClsCustom(
              setting=opt.train_list,
              root=data_dir,
              train=True,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              slowfast=opt.slowfast,
              slow_temporal_stride=opt.slow_temporal_stride,
              fast_temporal_stride=opt.fast_temporal_stride,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_train,
          )
          val_dataset = VideoClsCustom(
              setting=opt.val_list,
              root=val_data_dir,
              train=False,
              new_width=opt.new_width,
              new_height=opt.new_height,
              new_length=opt.new_length,
              new_step=opt.new_step,
              target_width=input_size,
              target_height=input_size,
              video_loader=opt.video_loader,
              use_decord=opt.use_decord,
              slowfast=opt.slowfast,
              slow_temporal_stride=opt.slow_temporal_stride,
              fast_temporal_stride=opt.fast_temporal_stride,
              data_aug=opt.data_aug,
              num_segments=opt.num_segments,
              transform=transform_test,
          )
      else:
          logger.info(
              "Dataset %s is not supported yet." % (opt.dataset)
          )
  
      logger.info(
          "Load %d training samples and %d validation samples."
          % (len(train_dataset), len(val_dataset))
      )
  
      if kvstore is not None:
          train_data = gluon.data.DataLoader(
              train_dataset,
              batch_size=batch_size,
              num_workers=num_workers,
              sampler=ShuffleSplitSampler(
                  len(train_dataset),
                  num_parts=kvstore.num_workers,
                  part_index=kvstore.rank,
              ),
              prefetch=int(opt.prefetch_ratio * num_workers),
              last_batch="rollover",
          )
          val_data = gluon.data.DataLoader(
              val_dataset,
              batch_size=batch_size,
              num_workers=num_workers,
              sampler=ShuffleSplitSampler(
                  len(val_dataset),
                  num_parts=kvstore.num_workers,
                  part_index=kvstore.rank,
              ),
              prefetch=int(opt.prefetch_ratio * num_workers),
              last_batch="discard",
          )
      else:
          train_data = gluon.data.DataLoader(
              train_dataset,
              batch_size=batch_size,
              shuffle=True,
              num_workers=num_workers,
              prefetch=int(opt.prefetch_ratio * num_workers),
              last_batch="rollover",
          )
          val_data = gluon.data.DataLoader(
              val_dataset,
              batch_size=batch_size,
              shuffle=False,
              num_workers=num_workers,
              prefetch=int(opt.prefetch_ratio * num_workers),
              last_batch="discard",
          )
  
      return train_data, val_data, batch_fn
  
file_path: gluon-cv/scripts/action-recognition/train_recognizer.py
imports: import argparse, time, logging, os, sys, math
  import numpy
  import mxnet
  import gluoncv
  from mxnet import gluon, nd, init, context
  from mxnet import autograd
  from mxnet.gluon import nn
  from mxnet.gluon.data.vision import transforms
  from mxboard import SummaryWriter
  from mxnet.contrib import amp
  from gluoncv.data.transforms import video
  from gluoncv.data import UCF101, Kinetics400, SomethingSomethingV2, HMDB51, VideoClsCustom
  from gluoncv.model_zoo import get_model
  from gluoncv.utils import makedirs, LRSequential, LRScheduler, split_and_load
  from gluoncv.data.sampler import SplitSampler, ShuffleSplitSampler
label_desc: Use image node_id 2 for calling a global function with example usage: get_data_loader(opt, batch_size, num_workers, logger, kvstore) and returns: train_data,  val_data,  batch_fn, data,  label