code: def main():
      args = parse_args()
      assert args.out or args.show, (
          "Please specify at least one operation (save/show the "
          'video) with the argument "--out" or "--show"'
      )
  
      model = init_detector(
          args.config, args.checkpoint, device=args.device
      )
  
      # init visualizer
      visualizer = VISUALIZERS.build(model.cfg.visualizer)
      # the dataset_meta is loaded from the checkpoint and
      # then pass to the model in init_detector
      visualizer.dataset_meta = model.dataset_meta
  
      if args.nvdecode:
          VideoCapture = ffmpegcv.VideoCaptureNV
      else:
          VideoCapture = ffmpegcv.VideoCapture
      video_origin = VideoCapture(args.video)
  
      batch_input_shape = prefetch_batch_input_shape(
          model, (video_origin.width, video_origin.height)
      )
      ori_shape = (video_origin.height, video_origin.width)
      resize_wh = batch_input_shape[::-1]
      video_resize = VideoCapture(
          args.video,
          resize=resize_wh,
          resize_keepratio=True,
          resize_keepratioalign="topleft",
      )
  
      video_writer = None
      if args.out:
          video_writer = ffmpegcv.VideoWriter(
              args.out, fps=video_origin.fps
          )
  
      with torch.no_grad():
          for i, (frame_resize, frame_origin) in enumerate(
              zip(track_iter_progress(video_resize), video_origin)
          ):
              data = pack_data(
                  frame_resize, batch_input_shape, ori_shape
              )
              result = model.test_step(data)[0]
  
              visualizer.add_datasample(
                  name="video",
                  image=frame_origin,
                  data_sample=result,
                  draw_gt=False,
                  show=False,
                  pred_score_thr=args.score_thr,
              )
  
              frame_mask = visualizer.get_image()
  
              if args.show:
                  cv2.namedWindow("video", 0)
                  mmcv.imshow(frame_mask, "video", args.wait_time)
              if args.out:
                  video_writer.write(frame_mask)
  
      if video_writer:
          video_writer.release()
      video_origin.release()
      video_resize.release()
  
      cv2.destroyAllWindows()
  
file_path: mmdetection/demo/video_gpuaccel_demo.py
imports: import argparse
  from typing import Tuple
  import cv2
  import mmcv
  import numpy
  import torch
  import torch.nn
  from mmcv.transforms import Compose
  from mmengine.utils import track_iter_progress
  from mmdet.apis import init_detector
  from mmdet.registry import VISUALIZERS
  from mmdet.structures import DetDataSample
label_desc: Use image node_id 4 for calling a global function with example usage: main() without return types