prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  TypeError: list indices must be integers or slices, not str
  When I run the demo code **video_gpuaccel_demo.py**, it has the following error. How to solve it, thanks.
  
  Traceback (most recent call last):
    File "demo/video_gpuaccel_demo.py", line 147, in <module>
      main()
    File "demo/video_gpuaccel_demo.py", line 102, in main
      batch_input_shape = prefetch_batch_input_shape(
    File "demo/video_gpuaccel_demo.py", line 60, in prefetch_batch_input_shape
      _, data_sample = model.data_preprocessor([data], False)
    File "C:\Anaconda\Anaconda\envs\mmdetection\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
      return forward_call(*input, **kwargs)
    File "c:\research\programmar\deeplearning\vehicle_classification\mmdet\models\data_preprocessors\data_preprocessor.py", line 121, in forward
      batch_pad_shape = self._get_pad_shape(data)
    File "c:\research\programmar\deeplearning\vehicle_classification\mmdet\models\data_preprocessors\data_preprocessor.py", line 154, in _get_pad_shape
      _batch_inputs = data['inputs']
  TypeError: list indices must be integers or slices, not str
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `demo/video_gpuaccel_demo.py`
  Content:
  ```
  1 # Copyright (c) OpenMMLab. All rights reserved.
  2 import argparse
  3 from typing import Tuple
  4 
  5 import cv2
  6 import mmcv
  7 import numpy as np
  8 import torch
  9 import torch.nn as nn
  10 from mmcv.transforms import Compose
  11 from mmengine.utils import track_iter_progress
  12 
  13 from mmdet.apis import init_detector
  14 from mmdet.registry import VISUALIZERS
  15 from mmdet.structures import DetDataSample
  16 
  17 try:
  18     import ffmpegcv
  19 except ImportError:
  20     raise ImportError(
  21         'Please install ffmpegcv with:\n\n    pip install ffmpegcv')
  22 
  23 
  24 def parse_args():
  25     parser = argparse.ArgumentParser(
  26         description='MMDetection video demo with GPU acceleration')
  27     parser.add_argument('video', help='Video file')
  28     parser.add_argument('config', help='Config file')
  29     parser.add_argument('checkpoint', help='Checkpoint file')
  30     parser.add_argument(
  31         '--device', default='cuda:0', help='Device used for inference')
  32     parser.add_argument(
  33         '--score-thr', type=float, default=0.3, help='Bbox score threshold')
  34     parser.add_argument('--out', type=str, help='Output video file')
  35     parser.add_argument('--show', action='store_true', help='Show video')
  36     parser.add_argument(
  37         '--nvdecode', action='store_true', help='Use NVIDIA decoder')
  38     parser.add_argument(
  39         '--wait-time',
  40         type=float,
  41         default=1,
  42         help='The interval of show (s), 0 is block')
  43     args = parser.parse_args()
  44     return args
  45 
  46 
  47 def prefetch_batch_input_shape(model: nn.Module, ori_wh: Tuple[int,
  48                                                                int]) -> dict:
  49     cfg = model.cfg
  50     w, h = ori_wh
  51     cfg.test_dataloader.dataset.pipeline[0].type = 'LoadImageFromNDArray'
  52     test_pipeline = Compose(cfg.test_dataloader.dataset.pipeline)
  53     data = {'img': np.zeros((h, w, 3), dtype=np.uint8), 'img_id': 0}
  54     data = test_pipeline(data)
  55     _, data_sample = model.data_preprocessor([data], False)
  56     batch_input_shape = data_sample[0].batch_input_shape
  57     return batch_input_shape
  58 
  59 
  60 def pack_data(frame_resize: np.ndarray, batch_input_shape: Tuple[int, int],
  61               ori_shape: Tuple[int, int]) -> dict:
  62     assert frame_resize.shape[:2] == batch_input_shape
  63     data_sample = DetDataSample()
  64     data_sample.set_metainfo({
  65         'img_shape':
  66         batch_input_shape,
  67         'ori_shape':
  68         ori_shape,
  69         'scale_factor': (batch_input_shape[0] / ori_shape[0],
  70                          batch_input_shape[1] / ori_shape[1])
  71     })
  72     frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1))
  73     data = {'inputs': frame_resize, 'data_sample': data_sample}
  74     return data
  75 
  76 
  77 def main():
  78     args = parse_args()
  79     assert args.out or args.show, \
  80         ('Please specify at least one operation (save/show the '
  81          'video) with the argument "--out" or "--show"')
  82 
  83     model = init_detector(args.config, args.checkpoint, device=args.device)
  84 
  85     # init visualizer
  86     visualizer = VISUALIZERS.build(model.cfg.visualizer)
  87     # the dataset_meta is loaded from the checkpoint and
  88     # then pass to the model in init_detector
  89     visualizer.dataset_meta = model.dataset_meta
  90 
  91     if args.nvdecode:
  92         VideoCapture = ffmpegcv.VideoCaptureNV
  93     else:
  94         VideoCapture = ffmpegcv.VideoCapture
  95     video_origin = VideoCapture(args.video)
  96 
  97     batch_input_shape = prefetch_batch_input_shape(
  98         model, (video_origin.width, video_origin.height))
  99     ori_shape = (video_origin.height, video_origin.width)
  100     resize_wh = batch_input_shape[::-1]
  101     video_resize = VideoCapture(
  102         args.video,
  103         resize=resize_wh,
  104         resize_keepratio=True,
  105         resize_keepratioalign='topleft')
  106 
  107     video_writer = None
  108     if args.out:
  109         video_writer = ffmpegcv.VideoWriter(args.out, fps=video_origin.fps)
  110 
  111     with torch.no_grad():
  112         for i, (frame_resize, frame_origin) in enumerate(
  113                 zip(track_iter_progress(video_resize), video_origin)):
  114             data = pack_data(frame_resize, batch_input_shape, ori_shape)
  115             result = model.test_step([data])[0]
  116 
  117             visualizer.add_datasample(
  118                 name='video',
  119                 image=frame_origin,
  120                 data_sample=result,
  121                 draw_gt=False,
  122                 show=False,
  123                 pred_score_thr=args.score_thr)
  124 
  125             frame_mask = visualizer.get_image()
  126 
  127             if args.show:
  128                 cv2.namedWindow('video', 0)
  129                 mmcv.imshow(frame_mask, 'video', args.wait_time)
  130             if args.out:
  131                 video_writer.write(frame_mask)
  132 
  133     if video_writer:
  134         video_writer.release()
  135     video_origin.release()
  136     video_resize.release()
  137 
  138     cv2.destroyAllWindows()
  139 
  140 
  141 if __name__ == '__main__':
  142     main()
  143
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/demo/video_gpuaccel_demo.py b/demo/video_gpuaccel_demo.py
  --- a/demo/video_gpuaccel_demo.py
  +++ b/demo/video_gpuaccel_demo.py
  @@ -52,7 +52,9 @@
       test_pipeline = Compose(cfg.test_dataloader.dataset.pipeline)
       data = {'img': np.zeros((h, w, 3), dtype=np.uint8), 'img_id': 0}
       data = test_pipeline(data)
  -    _, data_sample = model.data_preprocessor([data], False)
  +    data['inputs'] = [data['inputs']]
  +    data['data_samples'] = [data['data_samples']]
  +    data_sample = model.data_preprocessor(data, False)['data_samples']
       batch_input_shape = data_sample[0].batch_input_shape
       return batch_input_shape
   
  @@ -69,8 +71,8 @@
           'scale_factor': (batch_input_shape[0] / ori_shape[0],
                            batch_input_shape[1] / ori_shape[1])
       })
  -    frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1))
  -    data = {'inputs': frame_resize, 'data_sample': data_sample}
  +    frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1)).cuda()
  +    data = {'inputs': [frame_resize], 'data_samples': [data_sample]}
       return data
   
   
  @@ -112,7 +114,7 @@
           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]
  +            result = model.test_step(data)[0]
   
               visualizer.add_datasample(
                   name='video',
  
verification_info: {"golden_diff": "diff --git a/demo/video_gpuaccel_demo.py b/demo/video_gpuaccel_demo.py\n--- a/demo/video_gpuaccel_demo.py\n+++ b/demo/video_gpuaccel_demo.py\n@@ -52,7 +52,9 @@\n     test_pipeline = Compose(cfg.test_dataloader.dataset.pipeline)\n     data = {'img': np.zeros((h, w, 3), dtype=np.uint8), 'img_id': 0}\n     data = test_pipeline(data)\n-    _, data_sample = model.data_preprocessor([data], False)\n+    data['inputs'] = [data['inputs']]\n+    data['data_samples'] = [data['data_samples']]\n+    data_sample = model.data_preprocessor(data, False)['data_samples']\n     batch_input_shape = data_sample[0].batch_input_shape\n     return batch_input_shape\n \n@@ -69,8 +71,8 @@\n         'scale_factor': (batch_input_shape[0] / ori_shape[0],\n                          batch_input_shape[1] / ori_shape[1])\n     })\n-    frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1))\n-    data = {'inputs': frame_resize, 'data_sample': data_sample}\n+    frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1)).cuda()\n+    data = {'inputs': [frame_resize], 'data_samples': [data_sample]}\n     return data\n \n \n@@ -112,7 +114,7 @@\n         for i, (frame_resize, frame_origin) in enumerate(\n                 zip(track_iter_progress(video_resize), video_origin)):\n             data = pack_data(frame_resize, batch_input_shape, ori_shape)\n-            result = model.test_step([data])[0]\n+            result = model.test_step(data)[0]\n \n             visualizer.add_datasample(\n                 name='video',\n", "issue": "TypeError: list indices must be integers or slices, not str\nWhen I run the demo code **video_gpuaccel_demo.py**, it has the following error. How to solve it, thanks.\r\n\r\nTraceback (most recent call last):\r\n  File \"demo/video_gpuaccel_demo.py\", line 147, in <module>\r\n    main()\r\n  File \"demo/video_gpuaccel_demo.py\", line 102, in main\r\n    batch_input_shape = prefetch_batch_input_shape(\r\n  File \"demo/video_gpuaccel_demo.py\", line 60, in prefetch_batch_input_shape\r\n    _, data_sample = model.data_preprocessor([data], False)\r\n  File \"C:\\Anaconda\\Anaconda\\envs\\mmdetection\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1130, in _call_impl\r\n    return forward_call(*input, **kwargs)\r\n  File \"c:\\research\\programmar\\deeplearning\\vehicle_classification\\mmdet\\models\\data_preprocessors\\data_preprocessor.py\", line 121, in forward\r\n    batch_pad_shape = self._get_pad_shape(data)\r\n  File \"c:\\research\\programmar\\deeplearning\\vehicle_classification\\mmdet\\models\\data_preprocessors\\data_preprocessor.py\", line 154, in _get_pad_shape\r\n    _batch_inputs = data['inputs']\r\nTypeError: list indices must be integers or slices, not str\r\n\n", "before_files": [{"content": "# Copyright (c) OpenMMLab. All rights reserved.\nimport argparse\nfrom typing import Tuple\n\nimport cv2\nimport mmcv\nimport numpy as np\nimport torch\nimport torch.nn as nn\nfrom mmcv.transforms import Compose\nfrom mmengine.utils import track_iter_progress\n\nfrom mmdet.apis import init_detector\nfrom mmdet.registry import VISUALIZERS\nfrom mmdet.structures import DetDataSample\n\ntry:\n    import ffmpegcv\nexcept ImportError:\n    raise ImportError(\n        'Please install ffmpegcv with:\\n\\n    pip install ffmpegcv')\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(\n        description='MMDetection video demo with GPU acceleration')\n    parser.add_argument('video', help='Video file')\n    parser.add_argument('config', help='Config file')\n    parser.add_argument('checkpoint', help='Checkpoint file')\n    parser.add_argument(\n        '--device', default='cuda:0', help='Device used for inference')\n    parser.add_argument(\n        '--score-thr', type=float, default=0.3, help='Bbox score threshold')\n    parser.add_argument('--out', type=str, help='Output video file')\n    parser.add_argument('--show', action='store_true', help='Show video')\n    parser.add_argument(\n        '--nvdecode', action='store_true', help='Use NVIDIA decoder')\n    parser.add_argument(\n        '--wait-time',\n        type=float,\n        default=1,\n        help='The interval of show (s), 0 is block')\n    args = parser.parse_args()\n    return args\n\n\ndef prefetch_batch_input_shape(model: nn.Module, ori_wh: Tuple[int,\n                                                               int]) -> dict:\n    cfg = model.cfg\n    w, h = ori_wh\n    cfg.test_dataloader.dataset.pipeline[0].type = 'LoadImageFromNDArray'\n    test_pipeline = Compose(cfg.test_dataloader.dataset.pipeline)\n    data = {'img': np.zeros((h, w, 3), dtype=np.uint8), 'img_id': 0}\n    data = test_pipeline(data)\n    _, data_sample = model.data_preprocessor([data], False)\n    batch_input_shape = data_sample[0].batch_input_shape\n    return batch_input_shape\n\n\ndef pack_data(frame_resize: np.ndarray, batch_input_shape: Tuple[int, int],\n              ori_shape: Tuple[int, int]) -> dict:\n    assert frame_resize.shape[:2] == batch_input_shape\n    data_sample = DetDataSample()\n    data_sample.set_metainfo({\n        'img_shape':\n        batch_input_shape,\n        'ori_shape':\n        ori_shape,\n        'scale_factor': (batch_input_shape[0] / ori_shape[0],\n                         batch_input_shape[1] / ori_shape[1])\n    })\n    frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1))\n    data = {'inputs': frame_resize, 'data_sample': data_sample}\n    return data\n\n\ndef main():\n    args = parse_args()\n    assert args.out or args.show, \\\n        ('Please specify at least one operation (save/show the '\n         'video) with the argument \"--out\" or \"--show\"')\n\n    model = init_detector(args.config, args.checkpoint, device=args.device)\n\n    # init visualizer\n    visualizer = VISUALIZERS.build(model.cfg.visualizer)\n    # the dataset_meta is loaded from the checkpoint and\n    # then pass to the model in init_detector\n    visualizer.dataset_meta = model.dataset_meta\n\n    if args.nvdecode:\n        VideoCapture = ffmpegcv.VideoCaptureNV\n    else:\n        VideoCapture = ffmpegcv.VideoCapture\n    video_origin = VideoCapture(args.video)\n\n    batch_input_shape = prefetch_batch_input_shape(\n        model, (video_origin.width, video_origin.height))\n    ori_shape = (video_origin.height, video_origin.width)\n    resize_wh = batch_input_shape[::-1]\n    video_resize = VideoCapture(\n        args.video,\n        resize=resize_wh,\n        resize_keepratio=True,\n        resize_keepratioalign='topleft')\n\n    video_writer = None\n    if args.out:\n        video_writer = ffmpegcv.VideoWriter(args.out, fps=video_origin.fps)\n\n    with torch.no_grad():\n        for i, (frame_resize, frame_origin) in enumerate(\n                zip(track_iter_progress(video_resize), video_origin)):\n            data = pack_data(frame_resize, batch_input_shape, ori_shape)\n            result = model.test_step([data])[0]\n\n            visualizer.add_datasample(\n                name='video',\n                image=frame_origin,\n                data_sample=result,\n                draw_gt=False,\n                show=False,\n                pred_score_thr=args.score_thr)\n\n            frame_mask = visualizer.get_image()\n\n            if args.show:\n                cv2.namedWindow('video', 0)\n                mmcv.imshow(frame_mask, 'video', args.wait_time)\n            if args.out:\n                video_writer.write(frame_mask)\n\n    if video_writer:\n        video_writer.release()\n    video_origin.release()\n    video_resize.release()\n\n    cv2.destroyAllWindows()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/video_gpuaccel_demo.py"}], "after_files": [{"content": "# Copyright (c) OpenMMLab. All rights reserved.\nimport argparse\nfrom typing import Tuple\n\nimport cv2\nimport mmcv\nimport numpy as np\nimport torch\nimport torch.nn as nn\nfrom mmcv.transforms import Compose\nfrom mmengine.utils import track_iter_progress\n\nfrom mmdet.apis import init_detector\nfrom mmdet.registry import VISUALIZERS\nfrom mmdet.structures import DetDataSample\n\ntry:\n    import ffmpegcv\nexcept ImportError:\n    raise ImportError(\n        'Please install ffmpegcv with:\\n\\n    pip install ffmpegcv')\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(\n        description='MMDetection video demo with GPU acceleration')\n    parser.add_argument('video', help='Video file')\n    parser.add_argument('config', help='Config file')\n    parser.add_argument('checkpoint', help='Checkpoint file')\n    parser.add_argument(\n        '--device', default='cuda:0', help='Device used for inference')\n    parser.add_argument(\n        '--score-thr', type=float, default=0.3, help='Bbox score threshold')\n    parser.add_argument('--out', type=str, help='Output video file')\n    parser.add_argument('--show', action='store_true', help='Show video')\n    parser.add_argument(\n        '--nvdecode', action='store_true', help='Use NVIDIA decoder')\n    parser.add_argument(\n        '--wait-time',\n        type=float,\n        default=1,\n        help='The interval of show (s), 0 is block')\n    args = parser.parse_args()\n    return args\n\n\ndef prefetch_batch_input_shape(model: nn.Module, ori_wh: Tuple[int,\n                                                               int]) -> dict:\n    cfg = model.cfg\n    w, h = ori_wh\n    cfg.test_dataloader.dataset.pipeline[0].type = 'LoadImageFromNDArray'\n    test_pipeline = Compose(cfg.test_dataloader.dataset.pipeline)\n    data = {'img': np.zeros((h, w, 3), dtype=np.uint8), 'img_id': 0}\n    data = test_pipeline(data)\n    data['inputs'] = [data['inputs']]\n    data['data_samples'] = [data['data_samples']]\n    data_sample = model.data_preprocessor(data, False)['data_samples']\n    batch_input_shape = data_sample[0].batch_input_shape\n    return batch_input_shape\n\n\ndef pack_data(frame_resize: np.ndarray, batch_input_shape: Tuple[int, int],\n              ori_shape: Tuple[int, int]) -> dict:\n    assert frame_resize.shape[:2] == batch_input_shape\n    data_sample = DetDataSample()\n    data_sample.set_metainfo({\n        'img_shape':\n        batch_input_shape,\n        'ori_shape':\n        ori_shape,\n        'scale_factor': (batch_input_shape[0] / ori_shape[0],\n                         batch_input_shape[1] / ori_shape[1])\n    })\n    frame_resize = torch.from_numpy(frame_resize).permute((2, 0, 1)).cuda()\n    data = {'inputs': [frame_resize], 'data_samples': [data_sample]}\n    return data\n\n\ndef main():\n    args = parse_args()\n    assert args.out or args.show, \\\n        ('Please specify at least one operation (save/show the '\n         'video) with the argument \"--out\" or \"--show\"')\n\n    model = init_detector(args.config, args.checkpoint, device=args.device)\n\n    # init visualizer\n    visualizer = VISUALIZERS.build(model.cfg.visualizer)\n    # the dataset_meta is loaded from the checkpoint and\n    # then pass to the model in init_detector\n    visualizer.dataset_meta = model.dataset_meta\n\n    if args.nvdecode:\n        VideoCapture = ffmpegcv.VideoCaptureNV\n    else:\n        VideoCapture = ffmpegcv.VideoCapture\n    video_origin = VideoCapture(args.video)\n\n    batch_input_shape = prefetch_batch_input_shape(\n        model, (video_origin.width, video_origin.height))\n    ori_shape = (video_origin.height, video_origin.width)\n    resize_wh = batch_input_shape[::-1]\n    video_resize = VideoCapture(\n        args.video,\n        resize=resize_wh,\n        resize_keepratio=True,\n        resize_keepratioalign='topleft')\n\n    video_writer = None\n    if args.out:\n        video_writer = ffmpegcv.VideoWriter(args.out, fps=video_origin.fps)\n\n    with torch.no_grad():\n        for i, (frame_resize, frame_origin) in enumerate(\n                zip(track_iter_progress(video_resize), video_origin)):\n            data = pack_data(frame_resize, batch_input_shape, ori_shape)\n            result = model.test_step(data)[0]\n\n            visualizer.add_datasample(\n                name='video',\n                image=frame_origin,\n                data_sample=result,\n                draw_gt=False,\n                show=False,\n                pred_score_thr=args.score_thr)\n\n            frame_mask = visualizer.get_image()\n\n            if args.show:\n                cv2.namedWindow('video', 0)\n                mmcv.imshow(frame_mask, 'video', args.wait_time)\n            if args.out:\n                video_writer.write(frame_mask)\n\n    if video_writer:\n        video_writer.release()\n    video_origin.release()\n    video_resize.release()\n\n    cv2.destroyAllWindows()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/video_gpuaccel_demo.py"}]}