code: def main():
      opt = parse_args()
  
      makedirs(opt.save_dir)
  
      filehandler = logging.FileHandler(
          os.path.join(opt.save_dir, opt.logging_file)
      )
      streamhandler = logging.StreamHandler()
      logger = logging.getLogger("")
      logger.setLevel(logging.INFO)
      logger.addHandler(filehandler)
      logger.addHandler(streamhandler)
      logger.info(opt)
  
      gc.set_threshold(100, 5, 5)
  
      # set env
      if opt.gpu_id == -1:
          context = mx.cpu()
      else:
          gpu_id = opt.gpu_id
          context = mx.gpu(gpu_id)
  
      # get data preprocess
      image_norm_mean = [0.485, 0.456, 0.406]
      image_norm_std = [0.229, 0.224, 0.225]
      if opt.ten_crop:
          transform_test = transforms.Compose(
              [
                  video.VideoTenCrop(opt.input_size),
                  video.VideoToTensor(),
                  video.VideoNormalize(image_norm_mean, image_norm_std),
              ]
          )
          opt.num_crop = 10
      elif opt.three_crop:
          transform_test = transforms.Compose(
              [
                  video.VideoThreeCrop(opt.input_size),
                  video.VideoToTensor(),
                  video.VideoNormalize(image_norm_mean, image_norm_std),
              ]
          )
          opt.num_crop = 3
      else:
          transform_test = video.VideoGroupValTransform(
              size=opt.input_size,
              mean=image_norm_mean,
              std=image_norm_std,
          )
          opt.num_crop = 1
  
      # get model
      if opt.use_pretrained and len(opt.hashtag) > 0:
          opt.use_pretrained = opt.hashtag
      classes = opt.num_classes
      model_name = opt.model
      net = get_model(
          name=model_name,
          nclass=classes,
          pretrained=opt.use_pretrained,
          num_segments=opt.num_segments,
          num_crop=opt.num_crop,
      )
      net.cast(opt.dtype)
      net.collect_params().reset_ctx(context)
      if opt.mode == "hybrid":
          net.hybridize(static_alloc=True, static_shape=True)
      if opt.resume_params != "" and not opt.use_pretrained:
          net.load_parameters(opt.resume_params, ctx=context)
          logger.info(
              "Pre-trained model %s is successfully loaded."
              % (opt.resume_params)
          )
      else:
          logger.info(
              "Pre-trained model is successfully loaded from the model zoo."
          )
      logger.info("Successfully built model {}".format(model_name))
  
      # get classes list, if we are using a pretrained network from the model_zoo
      classes = None
      if opt.use_pretrained:
          if "kinetics400" in model_name:
              classes = Kinetics400Attr().classes
          elif "ucf101" in model_name:
              classes = UCF101Attr().classes
          elif "hmdb51" in model_name:
              classes = HMDB51Attr().classes
          elif "sthsth" in model_name:
              classes = SomethingSomethingV2Attr().classes
  
      # get data
      anno_file = opt.data_list
      f = open(anno_file, "r")
      data_list = f.readlines()
      logger.info("Load %d video samples." % len(data_list))
  
      # build a pseudo dataset instance to use its children class methods
      video_utils = VideoClsCustom(
          root=opt.data_dir,
          setting=opt.data_list,
          num_segments=opt.num_segments,
          num_crop=opt.num_crop,
          new_length=opt.new_length,
          new_step=opt.new_step,
          new_width=opt.new_width,
          new_height=opt.new_height,
          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,
          lazy_init=True,
      )
  
      start_time = time.time()
      for vid, vline in enumerate(data_list):
          video_path = vline.split()[0]
          video_name = video_path.split("/")[-1]
          if opt.need_root:
              video_path = os.path.join(opt.data_dir, video_path)
          video_data = read_data(
              opt, video_path, transform_test, video_utils
          )
          video_input = video_data.as_in_context(context)
          pred = net(video_input.astype(opt.dtype, copy=False))
          if opt.save_logits:
              logits_file = "%s_%s_logits.npy" % (
                  model_name,
                  video_name,
              )
              np.save(
                  os.path.join(opt.save_dir, logits_file),
                  pred.asnumpy(),
              )
          pred_label = np.argmax(pred.asnumpy())
          if opt.save_preds:
              preds_file = "%s_%s_preds.npy" % (model_name, video_name)
              np.save(
                  os.path.join(opt.save_dir, preds_file), pred_label
              )
  
          # Try to report a text label instead of the number.
          if classes:
              pred_label = classes[pred_label]
  
          logger.info(
              "%04d/%04d: %s is predicted to class %s"
              % (vid, len(data_list), video_name, pred_label)
          )
  
      end_time = time.time()
      logger.info(
          "Total inference time is %4.2f minutes"
          % ((end_time - start_time) / 60)
      )
  
file_path: gluon-cv/scripts/action-recognition/inference.py
imports: import os
  import time
  import argparse
  import logging
  import gc
  from gluoncv.utils.filesystem import try_import_decord
  import numpy
  import mxnet
  from mxnet import nd
  from mxnet.gluon.data.vision import transforms
  from gluoncv.data import Kinetics400Attr, UCF101Attr, SomethingSomethingV2Attr, HMDB51Attr, VideoClsCustom
  from gluoncv.data.transforms import video
  from gluoncv.model_zoo import get_model
  from gluoncv.utils import makedirs
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types