We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support different result formats of mmdet in demo
```
bbox_xywh[:, 2] = bbox_xywh[:, 2] - bbox_xywh[:, 0] + 1
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
```

The following script is used to call mmpose on a video
`
python $PATH_MMPOSE/demo/top_down_video_demo_with_mmdet.py $PATH_MMDET/configs/cascade_rcnn/cascade_mask_rcnn_x101_32x4d_fpn_20e_coco.py $PATH_WEIGHTS/MMDet/cascade_mask_rcnn_x101_32x4d_fpn_20e_coco_20200528_083917-ed1f4751.pth $PATH_MMPOSE/configs/top_down/darkpose/coco-wholebody/hrnet_w48_coco_wholebody_384x288_dark_plus.py $PATH_WEIGHTS/MMPose/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth --video-path test_video.mp4 --out-video-root ./results --show`



--- 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/top_down_img_demo_with_mmdet.py`
Content:
```
1 import os
2 from argparse import ArgumentParser
3 
4 from mmdet.apis import inference_detector, init_detector
5 
6 from mmpose.apis import (inference_top_down_pose_model, init_pose_model,
7                          vis_pose_result)
8 
9 
10 def main():
11     """Visualize the demo images.
12 
13     Using mmdet to detect the human.
14     """
15     parser = ArgumentParser()
16     parser.add_argument('det_config', help='Config file for detection')
17     parser.add_argument('det_checkpoint', help='Checkpoint file for detection')
18     parser.add_argument('pose_config', help='Config file for pose')
19     parser.add_argument('pose_checkpoint', help='Checkpoint file for pose')
20     parser.add_argument('--img-root', type=str, default='', help='Image root')
21     parser.add_argument('--img', type=str, default='', help='Image file')
22     parser.add_argument(
23         '--show',
24         action='store_true',
25         default=False,
26         help='whether to show img')
27     parser.add_argument(
28         '--out-img-root',
29         type=str,
30         default='',
31         help='root of the output img file. '
32         'Default not saving the visualization images.')
33     parser.add_argument(
34         '--device', default='cuda:0', help='Device used for inference')
35     parser.add_argument(
36         '--bbox-thr',
37         type=float,
38         default=0.3,
39         help='Bounding bbox score threshold')
40     parser.add_argument(
41         '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')
42 
43     args = parser.parse_args()
44 
45     assert args.show or (args.out_img_root != '')
46     assert args.img != ''
47     assert args.det_config is not None
48     assert args.det_checkpoint is not None
49 
50     det_model = init_detector(
51         args.det_config, args.det_checkpoint, device=args.device)
52     # build the pose model from a config file and a checkpoint file
53     pose_model = init_pose_model(
54         args.pose_config, args.pose_checkpoint, device=args.device)
55 
56     dataset = pose_model.cfg.data['test']['type']
57 
58     image_name = os.path.join(args.img_root, args.img)
59 
60     # test a single image, the resulting box is (x1, y1, x2, y2)
61     det_results = inference_detector(det_model, image_name)
62 
63     # keep the person class bounding boxes. (FasterRCNN)
64     person_bboxes = det_results[0].copy()
65 
66     # test a single image, with a list of bboxes.
67     pose_results, heatmaps = inference_top_down_pose_model(
68         pose_model,
69         image_name,
70         person_bboxes,
71         bbox_thr=args.bbox_thr,
72         format='xyxy',
73         dataset=dataset)
74 
75     if args.out_img_root == '':
76         out_file = None
77     else:
78         os.makedirs(args.out_img_root, exist_ok=True)
79         out_file = os.path.join(args.out_img_root, f'vis_{args.img}')
80 
81     # show the results
82     vis_pose_result(
83         pose_model,
84         image_name,
85         pose_results,
86         dataset=dataset,
87         kpt_score_thr=args.kpt_thr,
88         show=args.show,
89         out_file=out_file)
90 
91 
92 if __name__ == '__main__':
93     main()
94
```

Path: `demo/top_down_video_demo_with_mmdet.py`
Content:
```
1 import os
2 from argparse import ArgumentParser
3 
4 import cv2
5 from mmdet.apis import inference_detector, init_detector
6 
7 from mmpose.apis import (inference_top_down_pose_model, init_pose_model,
8                          vis_pose_result)
9 
10 
11 def main():
12     """Visualize the demo images.
13 
14     Using mmdet to detect the human.
15     """
16     parser = ArgumentParser()
17     parser.add_argument('det_config', help='Config file for detection')
18     parser.add_argument('det_checkpoint', help='Checkpoint file for detection')
19     parser.add_argument('pose_config', help='Config file for pose')
20     parser.add_argument('pose_checkpoint', help='Checkpoint file for pose')
21     parser.add_argument('--video-path', type=str, help='Video path')
22     parser.add_argument(
23         '--show',
24         action='store_true',
25         default=False,
26         help='whether to show visualizations.')
27     parser.add_argument(
28         '--out-video-root',
29         default='',
30         help='Root of the output video file. '
31         'Default not saving the visualization video.')
32     parser.add_argument(
33         '--device', default='cuda:0', help='Device used for inference')
34     parser.add_argument(
35         '--bbox-thr',
36         type=float,
37         default=0.3,
38         help='Bounding box score threshold')
39     parser.add_argument(
40         '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')
41 
42     args = parser.parse_args()
43 
44     assert args.show or (args.out_video_root != '')
45     assert args.det_config is not None
46     assert args.det_checkpoint is not None
47 
48     det_model = init_detector(
49         args.det_config, args.det_checkpoint, device=args.device)
50     # build the pose model from a config file and a checkpoint file
51     pose_model = init_pose_model(
52         args.pose_config, args.pose_checkpoint, device=args.device)
53 
54     dataset = pose_model.cfg.data['test']['type']
55 
56     cap = cv2.VideoCapture(args.video_path)
57 
58     if args.out_video_root == '':
59         save_out_video = False
60     else:
61         os.makedirs(args.out_video_root, exist_ok=True)
62         save_out_video = True
63 
64     if save_out_video:
65         fps = cap.get(cv2.CAP_PROP_FPS)
66         size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
67                 int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
68         fourcc = cv2.VideoWriter_fourcc(*'mp4v')
69         videoWriter = cv2.VideoWriter(
70             os.path.join(args.out_video_root,
71                          f'vis_{os.path.basename(args.video_path)}'), fourcc,
72             fps, size)
73 
74     while (cap.isOpened()):
75         flag, img = cap.read()
76         if not flag:
77             break
78         # test a single image, the resulting box is (x1, y1, x2, y2)
79         det_results = inference_detector(det_model, img)
80         # keep the person class bounding boxes.
81         person_bboxes = det_results[0].copy()
82 
83         # test a single image, with a list of bboxes.
84         pose_results, heatmaps = inference_top_down_pose_model(
85             pose_model,
86             img,
87             person_bboxes,
88             bbox_thr=args.bbox_thr,
89             format='xyxy',
90             dataset=dataset)
91 
92         # show the results
93         vis_img = vis_pose_result(
94             pose_model,
95             img,
96             pose_results,
97             dataset=dataset,
98             kpt_score_thr=args.kpt_thr,
99             show=False)
100 
101         if args.show:
102             cv2.imshow('Image', vis_img)
103 
104         if save_out_video:
105             videoWriter.write(vis_img)
106 
107         if cv2.waitKey(1) & 0xFF == ord('q'):
108             break
109 
110     cap.release()
111     if save_out_video:
112         videoWriter.release()
113     cv2.destroyAllWindows()
114 
115 
116 if __name__ == '__main__':
117     main()
118
```
--- 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()

```

diff --git a/demo/top_down_img_demo_with_mmdet.py b/demo/top_down_img_demo_with_mmdet.py
--- a/demo/top_down_img_demo_with_mmdet.py
+++ b/demo/top_down_img_demo_with_mmdet.py
@@ -7,6 +7,20 @@
                          vis_pose_result)
 
 
+def process_mmdet_results(mmdet_results, cat_id=0):
+    """Process mmdet results, and return a list of bboxes.
+
+    :param mmdet_results:
+    :param cat_id: category id (default: 0 for human)
+    :return: a list of detected bounding boxes
+    """
+    if isinstance(mmdet_results, tuple):
+        det_results = mmdet_results[0]
+    else:
+        det_results = mmdet_results
+    return det_results[cat_id]
+
+
 def main():
     """Visualize the demo images.
 
@@ -58,10 +72,10 @@
     image_name = os.path.join(args.img_root, args.img)
 
     # test a single image, the resulting box is (x1, y1, x2, y2)
-    det_results = inference_detector(det_model, image_name)
+    mmdet_results = inference_detector(det_model, image_name)
 
-    # keep the person class bounding boxes. (FasterRCNN)
-    person_bboxes = det_results[0].copy()
+    # keep the person class bounding boxes.
+    person_bboxes = process_mmdet_results(mmdet_results)
 
     # test a single image, with a list of bboxes.
     pose_results, heatmaps = inference_top_down_pose_model(
diff --git a/demo/top_down_video_demo_with_mmdet.py b/demo/top_down_video_demo_with_mmdet.py
--- a/demo/top_down_video_demo_with_mmdet.py
+++ b/demo/top_down_video_demo_with_mmdet.py
@@ -8,6 +8,20 @@
                          vis_pose_result)
 
 
+def process_mmdet_results(mmdet_results, cat_id=0):
+    """Process mmdet results, and return a list of bboxes.
+
+    :param mmdet_results:
+    :param cat_id: category id (default: 0 for human)
+    :return: a list of detected bounding boxes
+    """
+    if isinstance(mmdet_results, tuple):
+        det_results = mmdet_results[0]
+    else:
+        det_results = mmdet_results
+    return det_results[cat_id]
+
+
 def main():
     """Visualize the demo images.
 
@@ -76,9 +90,10 @@
         if not flag:
             break
         # test a single image, the resulting box is (x1, y1, x2, y2)
-        det_results = inference_detector(det_model, img)
+        mmdet_results = inference_detector(det_model, img)
+
         # keep the person class bounding boxes.
-        person_bboxes = det_results[0].copy()
+        person_bboxes = process_mmdet_results(mmdet_results)
 
         # test a single image, with a list of bboxes.
         pose_results, heatmaps = inference_top_down_pose_model(

{"golden_diff": "diff --git a/demo/top_down_img_demo_with_mmdet.py b/demo/top_down_img_demo_with_mmdet.py\n--- a/demo/top_down_img_demo_with_mmdet.py\n+++ b/demo/top_down_img_demo_with_mmdet.py\n@@ -7,6 +7,20 @@\n                          vis_pose_result)\n \n \n+def process_mmdet_results(mmdet_results, cat_id=0):\n+    \"\"\"Process mmdet results, and return a list of bboxes.\n+\n+    :param mmdet_results:\n+    :param cat_id: category id (default: 0 for human)\n+    :return: a list of detected bounding boxes\n+    \"\"\"\n+    if isinstance(mmdet_results, tuple):\n+        det_results = mmdet_results[0]\n+    else:\n+        det_results = mmdet_results\n+    return det_results[cat_id]\n+\n+\n def main():\n     \"\"\"Visualize the demo images.\n \n@@ -58,10 +72,10 @@\n     image_name = os.path.join(args.img_root, args.img)\n \n     # test a single image, the resulting box is (x1, y1, x2, y2)\n-    det_results = inference_detector(det_model, image_name)\n+    mmdet_results = inference_detector(det_model, image_name)\n \n-    # keep the person class bounding boxes. (FasterRCNN)\n-    person_bboxes = det_results[0].copy()\n+    # keep the person class bounding boxes.\n+    person_bboxes = process_mmdet_results(mmdet_results)\n \n     # test a single image, with a list of bboxes.\n     pose_results, heatmaps = inference_top_down_pose_model(\ndiff --git a/demo/top_down_video_demo_with_mmdet.py b/demo/top_down_video_demo_with_mmdet.py\n--- a/demo/top_down_video_demo_with_mmdet.py\n+++ b/demo/top_down_video_demo_with_mmdet.py\n@@ -8,6 +8,20 @@\n                          vis_pose_result)\n \n \n+def process_mmdet_results(mmdet_results, cat_id=0):\n+    \"\"\"Process mmdet results, and return a list of bboxes.\n+\n+    :param mmdet_results:\n+    :param cat_id: category id (default: 0 for human)\n+    :return: a list of detected bounding boxes\n+    \"\"\"\n+    if isinstance(mmdet_results, tuple):\n+        det_results = mmdet_results[0]\n+    else:\n+        det_results = mmdet_results\n+    return det_results[cat_id]\n+\n+\n def main():\n     \"\"\"Visualize the demo images.\n \n@@ -76,9 +90,10 @@\n         if not flag:\n             break\n         # test a single image, the resulting box is (x1, y1, x2, y2)\n-        det_results = inference_detector(det_model, img)\n+        mmdet_results = inference_detector(det_model, img)\n+\n         # keep the person class bounding boxes.\n-        person_bboxes = det_results[0].copy()\n+        person_bboxes = process_mmdet_results(mmdet_results)\n \n         # test a single image, with a list of bboxes.\n         pose_results, heatmaps = inference_top_down_pose_model(\n", "issue": "Support different result formats of mmdet in demo\n```\r\nbbox_xywh[:, 2] = bbox_xywh[:, 2] - bbox_xywh[:, 0] + 1\r\nIndexError: too many indices for array: array is 1-dimensional, but 2 were indexed\r\n```\r\n\r\nThe following script is used to call mmpose on a video\r\n`\r\npython $PATH_MMPOSE/demo/top_down_video_demo_with_mmdet.py $PATH_MMDET/configs/cascade_rcnn/cascade_mask_rcnn_x101_32x4d_fpn_20e_coco.py $PATH_WEIGHTS/MMDet/cascade_mask_rcnn_x101_32x4d_fpn_20e_coco_20200528_083917-ed1f4751.pth $PATH_MMPOSE/configs/top_down/darkpose/coco-wholebody/hrnet_w48_coco_wholebody_384x288_dark_plus.py $PATH_WEIGHTS/MMPose/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth --video-path test_video.mp4 --out-video-root ./results --show`\r\n\r\n\n", "before_files": [{"content": "import os\nfrom argparse import ArgumentParser\n\nfrom mmdet.apis import inference_detector, init_detector\n\nfrom mmpose.apis import (inference_top_down_pose_model, init_pose_model,\n                         vis_pose_result)\n\n\ndef main():\n    \"\"\"Visualize the demo images.\n\n    Using mmdet to detect the human.\n    \"\"\"\n    parser = ArgumentParser()\n    parser.add_argument('det_config', help='Config file for detection')\n    parser.add_argument('det_checkpoint', help='Checkpoint file for detection')\n    parser.add_argument('pose_config', help='Config file for pose')\n    parser.add_argument('pose_checkpoint', help='Checkpoint file for pose')\n    parser.add_argument('--img-root', type=str, default='', help='Image root')\n    parser.add_argument('--img', type=str, default='', help='Image file')\n    parser.add_argument(\n        '--show',\n        action='store_true',\n        default=False,\n        help='whether to show img')\n    parser.add_argument(\n        '--out-img-root',\n        type=str,\n        default='',\n        help='root of the output img file. '\n        'Default not saving the visualization images.')\n    parser.add_argument(\n        '--device', default='cuda:0', help='Device used for inference')\n    parser.add_argument(\n        '--bbox-thr',\n        type=float,\n        default=0.3,\n        help='Bounding bbox score threshold')\n    parser.add_argument(\n        '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')\n\n    args = parser.parse_args()\n\n    assert args.show or (args.out_img_root != '')\n    assert args.img != ''\n    assert args.det_config is not None\n    assert args.det_checkpoint is not None\n\n    det_model = init_detector(\n        args.det_config, args.det_checkpoint, device=args.device)\n    # build the pose model from a config file and a checkpoint file\n    pose_model = init_pose_model(\n        args.pose_config, args.pose_checkpoint, device=args.device)\n\n    dataset = pose_model.cfg.data['test']['type']\n\n    image_name = os.path.join(args.img_root, args.img)\n\n    # test a single image, the resulting box is (x1, y1, x2, y2)\n    det_results = inference_detector(det_model, image_name)\n\n    # keep the person class bounding boxes. (FasterRCNN)\n    person_bboxes = det_results[0].copy()\n\n    # test a single image, with a list of bboxes.\n    pose_results, heatmaps = inference_top_down_pose_model(\n        pose_model,\n        image_name,\n        person_bboxes,\n        bbox_thr=args.bbox_thr,\n        format='xyxy',\n        dataset=dataset)\n\n    if args.out_img_root == '':\n        out_file = None\n    else:\n        os.makedirs(args.out_img_root, exist_ok=True)\n        out_file = os.path.join(args.out_img_root, f'vis_{args.img}')\n\n    # show the results\n    vis_pose_result(\n        pose_model,\n        image_name,\n        pose_results,\n        dataset=dataset,\n        kpt_score_thr=args.kpt_thr,\n        show=args.show,\n        out_file=out_file)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/top_down_img_demo_with_mmdet.py"}, {"content": "import os\nfrom argparse import ArgumentParser\n\nimport cv2\nfrom mmdet.apis import inference_detector, init_detector\n\nfrom mmpose.apis import (inference_top_down_pose_model, init_pose_model,\n                         vis_pose_result)\n\n\ndef main():\n    \"\"\"Visualize the demo images.\n\n    Using mmdet to detect the human.\n    \"\"\"\n    parser = ArgumentParser()\n    parser.add_argument('det_config', help='Config file for detection')\n    parser.add_argument('det_checkpoint', help='Checkpoint file for detection')\n    parser.add_argument('pose_config', help='Config file for pose')\n    parser.add_argument('pose_checkpoint', help='Checkpoint file for pose')\n    parser.add_argument('--video-path', type=str, help='Video path')\n    parser.add_argument(\n        '--show',\n        action='store_true',\n        default=False,\n        help='whether to show visualizations.')\n    parser.add_argument(\n        '--out-video-root',\n        default='',\n        help='Root of the output video file. '\n        'Default not saving the visualization video.')\n    parser.add_argument(\n        '--device', default='cuda:0', help='Device used for inference')\n    parser.add_argument(\n        '--bbox-thr',\n        type=float,\n        default=0.3,\n        help='Bounding box score threshold')\n    parser.add_argument(\n        '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')\n\n    args = parser.parse_args()\n\n    assert args.show or (args.out_video_root != '')\n    assert args.det_config is not None\n    assert args.det_checkpoint is not None\n\n    det_model = init_detector(\n        args.det_config, args.det_checkpoint, device=args.device)\n    # build the pose model from a config file and a checkpoint file\n    pose_model = init_pose_model(\n        args.pose_config, args.pose_checkpoint, device=args.device)\n\n    dataset = pose_model.cfg.data['test']['type']\n\n    cap = cv2.VideoCapture(args.video_path)\n\n    if args.out_video_root == '':\n        save_out_video = False\n    else:\n        os.makedirs(args.out_video_root, exist_ok=True)\n        save_out_video = True\n\n    if save_out_video:\n        fps = cap.get(cv2.CAP_PROP_FPS)\n        size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),\n                int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))\n        fourcc = cv2.VideoWriter_fourcc(*'mp4v')\n        videoWriter = cv2.VideoWriter(\n            os.path.join(args.out_video_root,\n                         f'vis_{os.path.basename(args.video_path)}'), fourcc,\n            fps, size)\n\n    while (cap.isOpened()):\n        flag, img = cap.read()\n        if not flag:\n            break\n        # test a single image, the resulting box is (x1, y1, x2, y2)\n        det_results = inference_detector(det_model, img)\n        # keep the person class bounding boxes.\n        person_bboxes = det_results[0].copy()\n\n        # test a single image, with a list of bboxes.\n        pose_results, heatmaps = inference_top_down_pose_model(\n            pose_model,\n            img,\n            person_bboxes,\n            bbox_thr=args.bbox_thr,\n            format='xyxy',\n            dataset=dataset)\n\n        # show the results\n        vis_img = vis_pose_result(\n            pose_model,\n            img,\n            pose_results,\n            dataset=dataset,\n            kpt_score_thr=args.kpt_thr,\n            show=False)\n\n        if args.show:\n            cv2.imshow('Image', vis_img)\n\n        if save_out_video:\n            videoWriter.write(vis_img)\n\n        if cv2.waitKey(1) & 0xFF == ord('q'):\n            break\n\n    cap.release()\n    if save_out_video:\n        videoWriter.release()\n    cv2.destroyAllWindows()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/top_down_video_demo_with_mmdet.py"}], "after_files": [{"content": "import os\nfrom argparse import ArgumentParser\n\nfrom mmdet.apis import inference_detector, init_detector\n\nfrom mmpose.apis import (inference_top_down_pose_model, init_pose_model,\n                         vis_pose_result)\n\n\ndef process_mmdet_results(mmdet_results, cat_id=0):\n    \"\"\"Process mmdet results, and return a list of bboxes.\n\n    :param mmdet_results:\n    :param cat_id: category id (default: 0 for human)\n    :return: a list of detected bounding boxes\n    \"\"\"\n    if isinstance(mmdet_results, tuple):\n        det_results = mmdet_results[0]\n    else:\n        det_results = mmdet_results\n    return det_results[cat_id]\n\n\ndef main():\n    \"\"\"Visualize the demo images.\n\n    Using mmdet to detect the human.\n    \"\"\"\n    parser = ArgumentParser()\n    parser.add_argument('det_config', help='Config file for detection')\n    parser.add_argument('det_checkpoint', help='Checkpoint file for detection')\n    parser.add_argument('pose_config', help='Config file for pose')\n    parser.add_argument('pose_checkpoint', help='Checkpoint file for pose')\n    parser.add_argument('--img-root', type=str, default='', help='Image root')\n    parser.add_argument('--img', type=str, default='', help='Image file')\n    parser.add_argument(\n        '--show',\n        action='store_true',\n        default=False,\n        help='whether to show img')\n    parser.add_argument(\n        '--out-img-root',\n        type=str,\n        default='',\n        help='root of the output img file. '\n        'Default not saving the visualization images.')\n    parser.add_argument(\n        '--device', default='cuda:0', help='Device used for inference')\n    parser.add_argument(\n        '--bbox-thr',\n        type=float,\n        default=0.3,\n        help='Bounding bbox score threshold')\n    parser.add_argument(\n        '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')\n\n    args = parser.parse_args()\n\n    assert args.show or (args.out_img_root != '')\n    assert args.img != ''\n    assert args.det_config is not None\n    assert args.det_checkpoint is not None\n\n    det_model = init_detector(\n        args.det_config, args.det_checkpoint, device=args.device)\n    # build the pose model from a config file and a checkpoint file\n    pose_model = init_pose_model(\n        args.pose_config, args.pose_checkpoint, device=args.device)\n\n    dataset = pose_model.cfg.data['test']['type']\n\n    image_name = os.path.join(args.img_root, args.img)\n\n    # test a single image, the resulting box is (x1, y1, x2, y2)\n    mmdet_results = inference_detector(det_model, image_name)\n\n    # keep the person class bounding boxes.\n    person_bboxes = process_mmdet_results(mmdet_results)\n\n    # test a single image, with a list of bboxes.\n    pose_results, heatmaps = inference_top_down_pose_model(\n        pose_model,\n        image_name,\n        person_bboxes,\n        bbox_thr=args.bbox_thr,\n        format='xyxy',\n        dataset=dataset)\n\n    if args.out_img_root == '':\n        out_file = None\n    else:\n        os.makedirs(args.out_img_root, exist_ok=True)\n        out_file = os.path.join(args.out_img_root, f'vis_{args.img}')\n\n    # show the results\n    vis_pose_result(\n        pose_model,\n        image_name,\n        pose_results,\n        dataset=dataset,\n        kpt_score_thr=args.kpt_thr,\n        show=args.show,\n        out_file=out_file)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/top_down_img_demo_with_mmdet.py"}, {"content": "import os\nfrom argparse import ArgumentParser\n\nimport cv2\nfrom mmdet.apis import inference_detector, init_detector\n\nfrom mmpose.apis import (inference_top_down_pose_model, init_pose_model,\n                         vis_pose_result)\n\n\ndef process_mmdet_results(mmdet_results, cat_id=0):\n    \"\"\"Process mmdet results, and return a list of bboxes.\n\n    :param mmdet_results:\n    :param cat_id: category id (default: 0 for human)\n    :return: a list of detected bounding boxes\n    \"\"\"\n    if isinstance(mmdet_results, tuple):\n        det_results = mmdet_results[0]\n    else:\n        det_results = mmdet_results\n    return det_results[cat_id]\n\n\ndef main():\n    \"\"\"Visualize the demo images.\n\n    Using mmdet to detect the human.\n    \"\"\"\n    parser = ArgumentParser()\n    parser.add_argument('det_config', help='Config file for detection')\n    parser.add_argument('det_checkpoint', help='Checkpoint file for detection')\n    parser.add_argument('pose_config', help='Config file for pose')\n    parser.add_argument('pose_checkpoint', help='Checkpoint file for pose')\n    parser.add_argument('--video-path', type=str, help='Video path')\n    parser.add_argument(\n        '--show',\n        action='store_true',\n        default=False,\n        help='whether to show visualizations.')\n    parser.add_argument(\n        '--out-video-root',\n        default='',\n        help='Root of the output video file. '\n        'Default not saving the visualization video.')\n    parser.add_argument(\n        '--device', default='cuda:0', help='Device used for inference')\n    parser.add_argument(\n        '--bbox-thr',\n        type=float,\n        default=0.3,\n        help='Bounding box score threshold')\n    parser.add_argument(\n        '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')\n\n    args = parser.parse_args()\n\n    assert args.show or (args.out_video_root != '')\n    assert args.det_config is not None\n    assert args.det_checkpoint is not None\n\n    det_model = init_detector(\n        args.det_config, args.det_checkpoint, device=args.device)\n    # build the pose model from a config file and a checkpoint file\n    pose_model = init_pose_model(\n        args.pose_config, args.pose_checkpoint, device=args.device)\n\n    dataset = pose_model.cfg.data['test']['type']\n\n    cap = cv2.VideoCapture(args.video_path)\n\n    if args.out_video_root == '':\n        save_out_video = False\n    else:\n        os.makedirs(args.out_video_root, exist_ok=True)\n        save_out_video = True\n\n    if save_out_video:\n        fps = cap.get(cv2.CAP_PROP_FPS)\n        size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),\n                int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))\n        fourcc = cv2.VideoWriter_fourcc(*'mp4v')\n        videoWriter = cv2.VideoWriter(\n            os.path.join(args.out_video_root,\n                         f'vis_{os.path.basename(args.video_path)}'), fourcc,\n            fps, size)\n\n    while (cap.isOpened()):\n        flag, img = cap.read()\n        if not flag:\n            break\n        # test a single image, the resulting box is (x1, y1, x2, y2)\n        mmdet_results = inference_detector(det_model, img)\n\n        # keep the person class bounding boxes.\n        person_bboxes = process_mmdet_results(mmdet_results)\n\n        # test a single image, with a list of bboxes.\n        pose_results, heatmaps = inference_top_down_pose_model(\n            pose_model,\n            img,\n            person_bboxes,\n            bbox_thr=args.bbox_thr,\n            format='xyxy',\n            dataset=dataset)\n\n        # show the results\n        vis_img = vis_pose_result(\n            pose_model,\n            img,\n            pose_results,\n            dataset=dataset,\n            kpt_score_thr=args.kpt_thr,\n            show=False)\n\n        if args.show:\n            cv2.imshow('Image', vis_img)\n\n        if save_out_video:\n            videoWriter.write(vis_img)\n\n        if cv2.waitKey(1) & 0xFF == ord('q'):\n            break\n\n    cap.release()\n    if save_out_video:\n        videoWriter.release()\n    cv2.destroyAllWindows()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/top_down_video_demo_with_mmdet.py"}]}