We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
FileNotFoundError: img file does not exist: tools/deployment/../demo/demo.jpg
```
Traceback (most recent call last):
  File "tools/deployment/onnx2tensorrt.py", line 255, in <module>
    verbose=args.verbose)
  File "tools/deployment/onnx2tensorrt.py", line 54, in onnx2tensorrt
    one_img, one_meta = preprocess_example_input(input_config)
  File "/workspace/mmdetection-2.18.1/mmdet/core/export/pytorch2onnx.py", line 139, in preprocess_example_input
    one_img = mmcv.imread(input_path)
  File "/workspace/mmcv-1.3.17-trt/mmcv/image/io.py", line 177, in imread
    f'img file does not exist: {img_or_path}')
  File "/workspace/mmcv-1.3.17-trt/mmcv/utils/path.py", line 23, in check_file_exist
    raise FileNotFoundError(msg_tmpl.format(filename))
FileNotFoundError: img file does not exist: tools/deployment/../demo/demo.jpg
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tools/deployment/onnx2tensorrt.py`
Content:
```
1 # Copyright (c) OpenMMLab. All rights reserved.
2 import argparse
3 import os
4 import os.path as osp
5 import warnings
6 
7 import numpy as np
8 import onnx
9 import torch
10 from mmcv import Config
11 from mmcv.tensorrt import is_tensorrt_plugin_loaded, onnx2trt, save_trt_engine
12 
13 from mmdet.core.export import preprocess_example_input
14 from mmdet.core.export.model_wrappers import (ONNXRuntimeDetector,
15                                               TensorRTDetector)
16 from mmdet.datasets import DATASETS
17 
18 
19 def get_GiB(x: int):
20     """return x GiB."""
21     return x * (1 << 30)
22 
23 
24 def onnx2tensorrt(onnx_file,
25                   trt_file,
26                   input_config,
27                   verify=False,
28                   show=False,
29                   workspace_size=1,
30                   verbose=False):
31     import tensorrt as trt
32     onnx_model = onnx.load(onnx_file)
33     max_shape = input_config['max_shape']
34     min_shape = input_config['min_shape']
35     opt_shape = input_config['opt_shape']
36     fp16_mode = False
37     # create trt engine and wrapper
38     opt_shape_dict = {'input': [min_shape, opt_shape, max_shape]}
39     max_workspace_size = get_GiB(workspace_size)
40     trt_engine = onnx2trt(
41         onnx_model,
42         opt_shape_dict,
43         log_level=trt.Logger.VERBOSE if verbose else trt.Logger.ERROR,
44         fp16_mode=fp16_mode,
45         max_workspace_size=max_workspace_size)
46     save_dir, _ = osp.split(trt_file)
47     if save_dir:
48         os.makedirs(save_dir, exist_ok=True)
49     save_trt_engine(trt_engine, trt_file)
50     print(f'Successfully created TensorRT engine: {trt_file}')
51 
52     if verify:
53         # prepare input
54         one_img, one_meta = preprocess_example_input(input_config)
55         img_list, img_meta_list = [one_img], [[one_meta]]
56         img_list = [_.cuda().contiguous() for _ in img_list]
57 
58         # wrap ONNX and TensorRT model
59         onnx_model = ONNXRuntimeDetector(onnx_file, CLASSES, device_id=0)
60         trt_model = TensorRTDetector(trt_file, CLASSES, device_id=0)
61 
62         # inference with wrapped model
63         with torch.no_grad():
64             onnx_results = onnx_model(
65                 img_list, img_metas=img_meta_list, return_loss=False)[0]
66             trt_results = trt_model(
67                 img_list, img_metas=img_meta_list, return_loss=False)[0]
68 
69         if show:
70             out_file_ort, out_file_trt = None, None
71         else:
72             out_file_ort, out_file_trt = 'show-ort.png', 'show-trt.png'
73         show_img = one_meta['show_img']
74         score_thr = 0.3
75         onnx_model.show_result(
76             show_img,
77             onnx_results,
78             score_thr=score_thr,
79             show=True,
80             win_name='ONNXRuntime',
81             out_file=out_file_ort)
82         trt_model.show_result(
83             show_img,
84             trt_results,
85             score_thr=score_thr,
86             show=True,
87             win_name='TensorRT',
88             out_file=out_file_trt)
89         with_mask = trt_model.with_masks
90         # compare a part of result
91         if with_mask:
92             compare_pairs = list(zip(onnx_results, trt_results))
93         else:
94             compare_pairs = [(onnx_results, trt_results)]
95         err_msg = 'The numerical values are different between Pytorch' + \
96                   ' and ONNX, but it does not necessarily mean the' + \
97                   ' exported ONNX model is problematic.'
98         # check the numerical value
99         for onnx_res, pytorch_res in compare_pairs:
100             for o_res, p_res in zip(onnx_res, pytorch_res):
101                 np.testing.assert_allclose(
102                     o_res, p_res, rtol=1e-03, atol=1e-05, err_msg=err_msg)
103         print('The numerical values are the same between Pytorch and ONNX')
104 
105 
106 def parse_normalize_cfg(test_pipeline):
107     transforms = None
108     for pipeline in test_pipeline:
109         if 'transforms' in pipeline:
110             transforms = pipeline['transforms']
111             break
112     assert transforms is not None, 'Failed to find `transforms`'
113     norm_config_li = [_ for _ in transforms if _['type'] == 'Normalize']
114     assert len(norm_config_li) == 1, '`norm_config` should only have one'
115     norm_config = norm_config_li[0]
116     return norm_config
117 
118 
119 def parse_args():
120     parser = argparse.ArgumentParser(
121         description='Convert MMDetection models from ONNX to TensorRT')
122     parser.add_argument('config', help='test config file path')
123     parser.add_argument('model', help='Filename of input ONNX model')
124     parser.add_argument(
125         '--trt-file',
126         type=str,
127         default='tmp.trt',
128         help='Filename of output TensorRT engine')
129     parser.add_argument(
130         '--input-img', type=str, default='', help='Image for test')
131     parser.add_argument(
132         '--show', action='store_true', help='Whether to show output results')
133     parser.add_argument(
134         '--dataset',
135         type=str,
136         default='coco',
137         help='Dataset name. This argument is deprecated and will be \
138         removed in future releases.')
139     parser.add_argument(
140         '--verify',
141         action='store_true',
142         help='Verify the outputs of ONNXRuntime and TensorRT')
143     parser.add_argument(
144         '--verbose',
145         action='store_true',
146         help='Whether to verbose logging messages while creating \
147                 TensorRT engine. Defaults to False.')
148     parser.add_argument(
149         '--to-rgb',
150         action='store_false',
151         help='Feed model with RGB or BGR image. Default is RGB. This \
152         argument is deprecated and will be removed in future releases.')
153     parser.add_argument(
154         '--shape',
155         type=int,
156         nargs='+',
157         default=[400, 600],
158         help='Input size of the model')
159     parser.add_argument(
160         '--mean',
161         type=float,
162         nargs='+',
163         default=[123.675, 116.28, 103.53],
164         help='Mean value used for preprocess input data. This argument \
165         is deprecated and will be removed in future releases.')
166     parser.add_argument(
167         '--std',
168         type=float,
169         nargs='+',
170         default=[58.395, 57.12, 57.375],
171         help='Variance value used for preprocess input data. \
172         This argument is deprecated and will be removed in future releases.')
173     parser.add_argument(
174         '--min-shape',
175         type=int,
176         nargs='+',
177         default=None,
178         help='Minimum input size of the model in TensorRT')
179     parser.add_argument(
180         '--max-shape',
181         type=int,
182         nargs='+',
183         default=None,
184         help='Maximum input size of the model in TensorRT')
185     parser.add_argument(
186         '--workspace-size',
187         type=int,
188         default=1,
189         help='Max workspace size in GiB')
190 
191     args = parser.parse_args()
192     return args
193 
194 
195 if __name__ == '__main__':
196 
197     assert is_tensorrt_plugin_loaded(), 'TensorRT plugin should be compiled.'
198     args = parse_args()
199     warnings.warn(
200         'Arguments like `--to-rgb`, `--mean`, `--std`, `--dataset` would be \
201         parsed directly from config file and are deprecated and will be \
202         removed in future releases.')
203     if not args.input_img:
204         args.input_img = osp.join(osp.dirname(__file__), '../demo/demo.jpg')
205 
206     cfg = Config.fromfile(args.config)
207 
208     def parse_shape(shape):
209         if len(shape) == 1:
210             shape = (1, 3, shape[0], shape[0])
211         elif len(args.shape) == 2:
212             shape = (1, 3) + tuple(shape)
213         else:
214             raise ValueError('invalid input shape')
215         return shape
216 
217     if args.shape:
218         input_shape = parse_shape(args.shape)
219     else:
220         img_scale = cfg.test_pipeline[1]['img_scale']
221         input_shape = (1, 3, img_scale[1], img_scale[0])
222 
223     if not args.max_shape:
224         max_shape = input_shape
225     else:
226         max_shape = parse_shape(args.max_shape)
227 
228     if not args.min_shape:
229         min_shape = input_shape
230     else:
231         min_shape = parse_shape(args.min_shape)
232 
233     dataset = DATASETS.get(cfg.data.test['type'])
234     assert (dataset is not None)
235     CLASSES = dataset.CLASSES
236     normalize_cfg = parse_normalize_cfg(cfg.test_pipeline)
237 
238     input_config = {
239         'min_shape': min_shape,
240         'opt_shape': input_shape,
241         'max_shape': max_shape,
242         'input_shape': input_shape,
243         'input_path': args.input_img,
244         'normalize_cfg': normalize_cfg
245     }
246     # Create TensorRT engine
247     onnx2tensorrt(
248         args.model,
249         args.trt_file,
250         input_config,
251         verify=args.verify,
252         show=args.show,
253         workspace_size=args.workspace_size,
254         verbose=args.verbose)
255
```
--- 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/tools/deployment/onnx2tensorrt.py b/tools/deployment/onnx2tensorrt.py
--- a/tools/deployment/onnx2tensorrt.py
+++ b/tools/deployment/onnx2tensorrt.py
@@ -201,7 +201,7 @@
         parsed directly from config file and are deprecated and will be \
         removed in future releases.')
     if not args.input_img:
-        args.input_img = osp.join(osp.dirname(__file__), '../demo/demo.jpg')
+        args.input_img = osp.join(osp.dirname(__file__), '../../demo/demo.jpg')
 
     cfg = Config.fromfile(args.config)

{"golden_diff": "diff --git a/tools/deployment/onnx2tensorrt.py b/tools/deployment/onnx2tensorrt.py\n--- a/tools/deployment/onnx2tensorrt.py\n+++ b/tools/deployment/onnx2tensorrt.py\n@@ -201,7 +201,7 @@\n         parsed directly from config file and are deprecated and will be \\\n         removed in future releases.')\n     if not args.input_img:\n-        args.input_img = osp.join(osp.dirname(__file__), '../demo/demo.jpg')\n+        args.input_img = osp.join(osp.dirname(__file__), '../../demo/demo.jpg')\n \n     cfg = Config.fromfile(args.config)\n", "issue": "FileNotFoundError: img file does not exist: tools/deployment/../demo/demo.jpg\n```\r\nTraceback (most recent call last):\r\n  File \"tools/deployment/onnx2tensorrt.py\", line 255, in <module>\r\n    verbose=args.verbose)\r\n  File \"tools/deployment/onnx2tensorrt.py\", line 54, in onnx2tensorrt\r\n    one_img, one_meta = preprocess_example_input(input_config)\r\n  File \"/workspace/mmdetection-2.18.1/mmdet/core/export/pytorch2onnx.py\", line 139, in preprocess_example_input\r\n    one_img = mmcv.imread(input_path)\r\n  File \"/workspace/mmcv-1.3.17-trt/mmcv/image/io.py\", line 177, in imread\r\n    f'img file does not exist: {img_or_path}')\r\n  File \"/workspace/mmcv-1.3.17-trt/mmcv/utils/path.py\", line 23, in check_file_exist\r\n    raise FileNotFoundError(msg_tmpl.format(filename))\r\nFileNotFoundError: img file does not exist: tools/deployment/../demo/demo.jpg\r\n```\n", "before_files": [{"content": "# Copyright (c) OpenMMLab. All rights reserved.\nimport argparse\nimport os\nimport os.path as osp\nimport warnings\n\nimport numpy as np\nimport onnx\nimport torch\nfrom mmcv import Config\nfrom mmcv.tensorrt import is_tensorrt_plugin_loaded, onnx2trt, save_trt_engine\n\nfrom mmdet.core.export import preprocess_example_input\nfrom mmdet.core.export.model_wrappers import (ONNXRuntimeDetector,\n                                              TensorRTDetector)\nfrom mmdet.datasets import DATASETS\n\n\ndef get_GiB(x: int):\n    \"\"\"return x GiB.\"\"\"\n    return x * (1 << 30)\n\n\ndef onnx2tensorrt(onnx_file,\n                  trt_file,\n                  input_config,\n                  verify=False,\n                  show=False,\n                  workspace_size=1,\n                  verbose=False):\n    import tensorrt as trt\n    onnx_model = onnx.load(onnx_file)\n    max_shape = input_config['max_shape']\n    min_shape = input_config['min_shape']\n    opt_shape = input_config['opt_shape']\n    fp16_mode = False\n    # create trt engine and wrapper\n    opt_shape_dict = {'input': [min_shape, opt_shape, max_shape]}\n    max_workspace_size = get_GiB(workspace_size)\n    trt_engine = onnx2trt(\n        onnx_model,\n        opt_shape_dict,\n        log_level=trt.Logger.VERBOSE if verbose else trt.Logger.ERROR,\n        fp16_mode=fp16_mode,\n        max_workspace_size=max_workspace_size)\n    save_dir, _ = osp.split(trt_file)\n    if save_dir:\n        os.makedirs(save_dir, exist_ok=True)\n    save_trt_engine(trt_engine, trt_file)\n    print(f'Successfully created TensorRT engine: {trt_file}')\n\n    if verify:\n        # prepare input\n        one_img, one_meta = preprocess_example_input(input_config)\n        img_list, img_meta_list = [one_img], [[one_meta]]\n        img_list = [_.cuda().contiguous() for _ in img_list]\n\n        # wrap ONNX and TensorRT model\n        onnx_model = ONNXRuntimeDetector(onnx_file, CLASSES, device_id=0)\n        trt_model = TensorRTDetector(trt_file, CLASSES, device_id=0)\n\n        # inference with wrapped model\n        with torch.no_grad():\n            onnx_results = onnx_model(\n                img_list, img_metas=img_meta_list, return_loss=False)[0]\n            trt_results = trt_model(\n                img_list, img_metas=img_meta_list, return_loss=False)[0]\n\n        if show:\n            out_file_ort, out_file_trt = None, None\n        else:\n            out_file_ort, out_file_trt = 'show-ort.png', 'show-trt.png'\n        show_img = one_meta['show_img']\n        score_thr = 0.3\n        onnx_model.show_result(\n            show_img,\n            onnx_results,\n            score_thr=score_thr,\n            show=True,\n            win_name='ONNXRuntime',\n            out_file=out_file_ort)\n        trt_model.show_result(\n            show_img,\n            trt_results,\n            score_thr=score_thr,\n            show=True,\n            win_name='TensorRT',\n            out_file=out_file_trt)\n        with_mask = trt_model.with_masks\n        # compare a part of result\n        if with_mask:\n            compare_pairs = list(zip(onnx_results, trt_results))\n        else:\n            compare_pairs = [(onnx_results, trt_results)]\n        err_msg = 'The numerical values are different between Pytorch' + \\\n                  ' and ONNX, but it does not necessarily mean the' + \\\n                  ' exported ONNX model is problematic.'\n        # check the numerical value\n        for onnx_res, pytorch_res in compare_pairs:\n            for o_res, p_res in zip(onnx_res, pytorch_res):\n                np.testing.assert_allclose(\n                    o_res, p_res, rtol=1e-03, atol=1e-05, err_msg=err_msg)\n        print('The numerical values are the same between Pytorch and ONNX')\n\n\ndef parse_normalize_cfg(test_pipeline):\n    transforms = None\n    for pipeline in test_pipeline:\n        if 'transforms' in pipeline:\n            transforms = pipeline['transforms']\n            break\n    assert transforms is not None, 'Failed to find `transforms`'\n    norm_config_li = [_ for _ in transforms if _['type'] == 'Normalize']\n    assert len(norm_config_li) == 1, '`norm_config` should only have one'\n    norm_config = norm_config_li[0]\n    return norm_config\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(\n        description='Convert MMDetection models from ONNX to TensorRT')\n    parser.add_argument('config', help='test config file path')\n    parser.add_argument('model', help='Filename of input ONNX model')\n    parser.add_argument(\n        '--trt-file',\n        type=str,\n        default='tmp.trt',\n        help='Filename of output TensorRT engine')\n    parser.add_argument(\n        '--input-img', type=str, default='', help='Image for test')\n    parser.add_argument(\n        '--show', action='store_true', help='Whether to show output results')\n    parser.add_argument(\n        '--dataset',\n        type=str,\n        default='coco',\n        help='Dataset name. This argument is deprecated and will be \\\n        removed in future releases.')\n    parser.add_argument(\n        '--verify',\n        action='store_true',\n        help='Verify the outputs of ONNXRuntime and TensorRT')\n    parser.add_argument(\n        '--verbose',\n        action='store_true',\n        help='Whether to verbose logging messages while creating \\\n                TensorRT engine. Defaults to False.')\n    parser.add_argument(\n        '--to-rgb',\n        action='store_false',\n        help='Feed model with RGB or BGR image. Default is RGB. This \\\n        argument is deprecated and will be removed in future releases.')\n    parser.add_argument(\n        '--shape',\n        type=int,\n        nargs='+',\n        default=[400, 600],\n        help='Input size of the model')\n    parser.add_argument(\n        '--mean',\n        type=float,\n        nargs='+',\n        default=[123.675, 116.28, 103.53],\n        help='Mean value used for preprocess input data. This argument \\\n        is deprecated and will be removed in future releases.')\n    parser.add_argument(\n        '--std',\n        type=float,\n        nargs='+',\n        default=[58.395, 57.12, 57.375],\n        help='Variance value used for preprocess input data. \\\n        This argument is deprecated and will be removed in future releases.')\n    parser.add_argument(\n        '--min-shape',\n        type=int,\n        nargs='+',\n        default=None,\n        help='Minimum input size of the model in TensorRT')\n    parser.add_argument(\n        '--max-shape',\n        type=int,\n        nargs='+',\n        default=None,\n        help='Maximum input size of the model in TensorRT')\n    parser.add_argument(\n        '--workspace-size',\n        type=int,\n        default=1,\n        help='Max workspace size in GiB')\n\n    args = parser.parse_args()\n    return args\n\n\nif __name__ == '__main__':\n\n    assert is_tensorrt_plugin_loaded(), 'TensorRT plugin should be compiled.'\n    args = parse_args()\n    warnings.warn(\n        'Arguments like `--to-rgb`, `--mean`, `--std`, `--dataset` would be \\\n        parsed directly from config file and are deprecated and will be \\\n        removed in future releases.')\n    if not args.input_img:\n        args.input_img = osp.join(osp.dirname(__file__), '../demo/demo.jpg')\n\n    cfg = Config.fromfile(args.config)\n\n    def parse_shape(shape):\n        if len(shape) == 1:\n            shape = (1, 3, shape[0], shape[0])\n        elif len(args.shape) == 2:\n            shape = (1, 3) + tuple(shape)\n        else:\n            raise ValueError('invalid input shape')\n        return shape\n\n    if args.shape:\n        input_shape = parse_shape(args.shape)\n    else:\n        img_scale = cfg.test_pipeline[1]['img_scale']\n        input_shape = (1, 3, img_scale[1], img_scale[0])\n\n    if not args.max_shape:\n        max_shape = input_shape\n    else:\n        max_shape = parse_shape(args.max_shape)\n\n    if not args.min_shape:\n        min_shape = input_shape\n    else:\n        min_shape = parse_shape(args.min_shape)\n\n    dataset = DATASETS.get(cfg.data.test['type'])\n    assert (dataset is not None)\n    CLASSES = dataset.CLASSES\n    normalize_cfg = parse_normalize_cfg(cfg.test_pipeline)\n\n    input_config = {\n        'min_shape': min_shape,\n        'opt_shape': input_shape,\n        'max_shape': max_shape,\n        'input_shape': input_shape,\n        'input_path': args.input_img,\n        'normalize_cfg': normalize_cfg\n    }\n    # Create TensorRT engine\n    onnx2tensorrt(\n        args.model,\n        args.trt_file,\n        input_config,\n        verify=args.verify,\n        show=args.show,\n        workspace_size=args.workspace_size,\n        verbose=args.verbose)\n", "path": "tools/deployment/onnx2tensorrt.py"}], "after_files": [{"content": "# Copyright (c) OpenMMLab. All rights reserved.\nimport argparse\nimport os\nimport os.path as osp\nimport warnings\n\nimport numpy as np\nimport onnx\nimport torch\nfrom mmcv import Config\nfrom mmcv.tensorrt import is_tensorrt_plugin_loaded, onnx2trt, save_trt_engine\n\nfrom mmdet.core.export import preprocess_example_input\nfrom mmdet.core.export.model_wrappers import (ONNXRuntimeDetector,\n                                              TensorRTDetector)\nfrom mmdet.datasets import DATASETS\n\n\ndef get_GiB(x: int):\n    \"\"\"return x GiB.\"\"\"\n    return x * (1 << 30)\n\n\ndef onnx2tensorrt(onnx_file,\n                  trt_file,\n                  input_config,\n                  verify=False,\n                  show=False,\n                  workspace_size=1,\n                  verbose=False):\n    import tensorrt as trt\n    onnx_model = onnx.load(onnx_file)\n    max_shape = input_config['max_shape']\n    min_shape = input_config['min_shape']\n    opt_shape = input_config['opt_shape']\n    fp16_mode = False\n    # create trt engine and wrapper\n    opt_shape_dict = {'input': [min_shape, opt_shape, max_shape]}\n    max_workspace_size = get_GiB(workspace_size)\n    trt_engine = onnx2trt(\n        onnx_model,\n        opt_shape_dict,\n        log_level=trt.Logger.VERBOSE if verbose else trt.Logger.ERROR,\n        fp16_mode=fp16_mode,\n        max_workspace_size=max_workspace_size)\n    save_dir, _ = osp.split(trt_file)\n    if save_dir:\n        os.makedirs(save_dir, exist_ok=True)\n    save_trt_engine(trt_engine, trt_file)\n    print(f'Successfully created TensorRT engine: {trt_file}')\n\n    if verify:\n        # prepare input\n        one_img, one_meta = preprocess_example_input(input_config)\n        img_list, img_meta_list = [one_img], [[one_meta]]\n        img_list = [_.cuda().contiguous() for _ in img_list]\n\n        # wrap ONNX and TensorRT model\n        onnx_model = ONNXRuntimeDetector(onnx_file, CLASSES, device_id=0)\n        trt_model = TensorRTDetector(trt_file, CLASSES, device_id=0)\n\n        # inference with wrapped model\n        with torch.no_grad():\n            onnx_results = onnx_model(\n                img_list, img_metas=img_meta_list, return_loss=False)[0]\n            trt_results = trt_model(\n                img_list, img_metas=img_meta_list, return_loss=False)[0]\n\n        if show:\n            out_file_ort, out_file_trt = None, None\n        else:\n            out_file_ort, out_file_trt = 'show-ort.png', 'show-trt.png'\n        show_img = one_meta['show_img']\n        score_thr = 0.3\n        onnx_model.show_result(\n            show_img,\n            onnx_results,\n            score_thr=score_thr,\n            show=True,\n            win_name='ONNXRuntime',\n            out_file=out_file_ort)\n        trt_model.show_result(\n            show_img,\n            trt_results,\n            score_thr=score_thr,\n            show=True,\n            win_name='TensorRT',\n            out_file=out_file_trt)\n        with_mask = trt_model.with_masks\n        # compare a part of result\n        if with_mask:\n            compare_pairs = list(zip(onnx_results, trt_results))\n        else:\n            compare_pairs = [(onnx_results, trt_results)]\n        err_msg = 'The numerical values are different between Pytorch' + \\\n                  ' and ONNX, but it does not necessarily mean the' + \\\n                  ' exported ONNX model is problematic.'\n        # check the numerical value\n        for onnx_res, pytorch_res in compare_pairs:\n            for o_res, p_res in zip(onnx_res, pytorch_res):\n                np.testing.assert_allclose(\n                    o_res, p_res, rtol=1e-03, atol=1e-05, err_msg=err_msg)\n        print('The numerical values are the same between Pytorch and ONNX')\n\n\ndef parse_normalize_cfg(test_pipeline):\n    transforms = None\n    for pipeline in test_pipeline:\n        if 'transforms' in pipeline:\n            transforms = pipeline['transforms']\n            break\n    assert transforms is not None, 'Failed to find `transforms`'\n    norm_config_li = [_ for _ in transforms if _['type'] == 'Normalize']\n    assert len(norm_config_li) == 1, '`norm_config` should only have one'\n    norm_config = norm_config_li[0]\n    return norm_config\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(\n        description='Convert MMDetection models from ONNX to TensorRT')\n    parser.add_argument('config', help='test config file path')\n    parser.add_argument('model', help='Filename of input ONNX model')\n    parser.add_argument(\n        '--trt-file',\n        type=str,\n        default='tmp.trt',\n        help='Filename of output TensorRT engine')\n    parser.add_argument(\n        '--input-img', type=str, default='', help='Image for test')\n    parser.add_argument(\n        '--show', action='store_true', help='Whether to show output results')\n    parser.add_argument(\n        '--dataset',\n        type=str,\n        default='coco',\n        help='Dataset name. This argument is deprecated and will be \\\n        removed in future releases.')\n    parser.add_argument(\n        '--verify',\n        action='store_true',\n        help='Verify the outputs of ONNXRuntime and TensorRT')\n    parser.add_argument(\n        '--verbose',\n        action='store_true',\n        help='Whether to verbose logging messages while creating \\\n                TensorRT engine. Defaults to False.')\n    parser.add_argument(\n        '--to-rgb',\n        action='store_false',\n        help='Feed model with RGB or BGR image. Default is RGB. This \\\n        argument is deprecated and will be removed in future releases.')\n    parser.add_argument(\n        '--shape',\n        type=int,\n        nargs='+',\n        default=[400, 600],\n        help='Input size of the model')\n    parser.add_argument(\n        '--mean',\n        type=float,\n        nargs='+',\n        default=[123.675, 116.28, 103.53],\n        help='Mean value used for preprocess input data. This argument \\\n        is deprecated and will be removed in future releases.')\n    parser.add_argument(\n        '--std',\n        type=float,\n        nargs='+',\n        default=[58.395, 57.12, 57.375],\n        help='Variance value used for preprocess input data. \\\n        This argument is deprecated and will be removed in future releases.')\n    parser.add_argument(\n        '--min-shape',\n        type=int,\n        nargs='+',\n        default=None,\n        help='Minimum input size of the model in TensorRT')\n    parser.add_argument(\n        '--max-shape',\n        type=int,\n        nargs='+',\n        default=None,\n        help='Maximum input size of the model in TensorRT')\n    parser.add_argument(\n        '--workspace-size',\n        type=int,\n        default=1,\n        help='Max workspace size in GiB')\n\n    args = parser.parse_args()\n    return args\n\n\nif __name__ == '__main__':\n\n    assert is_tensorrt_plugin_loaded(), 'TensorRT plugin should be compiled.'\n    args = parse_args()\n    warnings.warn(\n        'Arguments like `--to-rgb`, `--mean`, `--std`, `--dataset` would be \\\n        parsed directly from config file and are deprecated and will be \\\n        removed in future releases.')\n    if not args.input_img:\n        args.input_img = osp.join(osp.dirname(__file__), '../../demo/demo.jpg')\n\n    cfg = Config.fromfile(args.config)\n\n    def parse_shape(shape):\n        if len(shape) == 1:\n            shape = (1, 3, shape[0], shape[0])\n        elif len(args.shape) == 2:\n            shape = (1, 3) + tuple(shape)\n        else:\n            raise ValueError('invalid input shape')\n        return shape\n\n    if args.shape:\n        input_shape = parse_shape(args.shape)\n    else:\n        img_scale = cfg.test_pipeline[1]['img_scale']\n        input_shape = (1, 3, img_scale[1], img_scale[0])\n\n    if not args.max_shape:\n        max_shape = input_shape\n    else:\n        max_shape = parse_shape(args.max_shape)\n\n    if not args.min_shape:\n        min_shape = input_shape\n    else:\n        min_shape = parse_shape(args.min_shape)\n\n    dataset = DATASETS.get(cfg.data.test['type'])\n    assert (dataset is not None)\n    CLASSES = dataset.CLASSES\n    normalize_cfg = parse_normalize_cfg(cfg.test_pipeline)\n\n    input_config = {\n        'min_shape': min_shape,\n        'opt_shape': input_shape,\n        'max_shape': max_shape,\n        'input_shape': input_shape,\n        'input_path': args.input_img,\n        'normalize_cfg': normalize_cfg\n    }\n    # Create TensorRT engine\n    onnx2tensorrt(\n        args.model,\n        args.trt_file,\n        input_config,\n        verify=args.verify,\n        show=args.show,\n        workspace_size=args.workspace_size,\n        verbose=args.verbose)\n", "path": "tools/deployment/onnx2tensorrt.py"}]}