Feng Wang commited on
Commit
a04b1de
·
1 Parent(s): 4f029a3

fix(yolox): some bugs due to upgrade (#1602)

Browse files
.gitignore CHANGED
@@ -219,3 +219,10 @@ events.out.tfevents*
219
 
220
  # vim
221
  .vim
 
 
 
 
 
 
 
 
219
 
220
  # vim
221
  .vim
222
+
223
+ # OS generated files
224
+ .DS_Store
225
+ .DS_Store?
226
+ .Trashes
227
+ ehthumbs.db
228
+ Thumbs.db
demo/ONNXRuntime/README.md CHANGED
@@ -2,7 +2,18 @@
2
 
3
  This doc introduces how to convert your pytorch model into onnx, and how to run an onnxruntime demo to verify your convertion.
4
 
5
- ### Download ONNX models.
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  | Model | Parameters | GFLOPs | Test Size | mAP | Weights |
8
  |:------| :----: | :----: | :---: | :---: | :---: |
@@ -14,8 +25,7 @@ This doc introduces how to convert your pytorch model into onnx, and how to run
14
  | YOLOX-Darknet53| 63.72M | 185.3 | 640x640 |48.0 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_darknet.onnx) |
15
  | YOLOX-X | 99.1M | 281.9 | 640x640 |51.5 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_x.onnx) |
16
 
17
-
18
- ### Convert Your Model to ONNX
19
 
20
  First, you should move to <YOLOX_HOME> by:
21
  ```shell
@@ -38,7 +48,7 @@ Notes:
38
  dummy_input = torch.randn(1, 3, exp.test_size[0], exp.test_size[1])
39
  ```
40
 
41
- 2. Convert a standard YOLOX model by -f. When using -f, the above command is equivalent to:
42
 
43
  ```shell
44
  python3 tools/export_onnx.py --output-name yolox_s.onnx -f exps/default/yolox_s.py -c yolox_s.pth
@@ -50,7 +60,7 @@ python3 tools/export_onnx.py --output-name yolox_s.onnx -f exps/default/yolox_s.
50
  python3 tools/export_onnx.py --output-name your_yolox.onnx -f exps/your_dir/your_yolox.py -c your_yolox.pth
51
  ```
52
 
53
- ### ONNXRuntime Demo
54
 
55
  Step1.
56
  ```shell
 
2
 
3
  This doc introduces how to convert your pytorch model into onnx, and how to run an onnxruntime demo to verify your convertion.
4
 
5
+ ### Step1: Install onnxruntime
6
+
7
+ run the following command to install onnxruntime:
8
+ ```shell
9
+ pip install onnxruntime
10
+ ```
11
+
12
+ ### Step2: Get ONNX models
13
+
14
+ Users might download our pre-generated ONNX models or convert their own models to ONNX.
15
+
16
+ #### Download ONNX models.
17
 
18
  | Model | Parameters | GFLOPs | Test Size | mAP | Weights |
19
  |:------| :----: | :----: | :---: | :---: | :---: |
 
25
  | YOLOX-Darknet53| 63.72M | 185.3 | 640x640 |48.0 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_darknet.onnx) |
26
  | YOLOX-X | 99.1M | 281.9 | 640x640 |51.5 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_x.onnx) |
27
 
28
+ #### Convert Your Model to ONNX
 
29
 
30
  First, you should move to <YOLOX_HOME> by:
31
  ```shell
 
48
  dummy_input = torch.randn(1, 3, exp.test_size[0], exp.test_size[1])
49
  ```
50
 
51
+ 1. Convert a standard YOLOX model by -f. When using -f, the above command is equivalent to:
52
 
53
  ```shell
54
  python3 tools/export_onnx.py --output-name yolox_s.onnx -f exps/default/yolox_s.py -c yolox_s.pth
 
60
  python3 tools/export_onnx.py --output-name your_yolox.onnx -f exps/your_dir/your_yolox.py -c your_yolox.pth
61
  ```
62
 
63
+ ### Step3: ONNXRuntime Demo
64
 
65
  Step1.
66
  ```shell
demo/ONNXRuntime/onnx_inference.py CHANGED
@@ -1,5 +1,4 @@
1
  #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
  # Copyright (c) Megvii, Inc. and its affiliates.
4
 
5
  import argparse
@@ -51,11 +50,6 @@ def make_parser():
51
  default="640,640",
52
  help="Specify an input shape for inference.",
53
  )
54
- parser.add_argument(
55
- "--with_p6",
56
- action="store_true",
57
- help="Whether your model uses p6 in FPN/PAN.",
58
- )
59
  return parser
60
 
61
 
@@ -70,7 +64,7 @@ if __name__ == '__main__':
70
 
71
  ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
72
  output = session.run(None, ort_inputs)
73
- predictions = demo_postprocess(output[0], input_shape, p6=args.with_p6)[0]
74
 
75
  boxes = predictions[:, :4]
76
  scores = predictions[:, 4:5] * predictions[:, 5:]
 
1
  #!/usr/bin/env python3
 
2
  # Copyright (c) Megvii, Inc. and its affiliates.
3
 
4
  import argparse
 
50
  default="640,640",
51
  help="Specify an input shape for inference.",
52
  )
 
 
 
 
 
53
  return parser
54
 
55
 
 
64
 
65
  ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
66
  output = session.run(None, ort_inputs)
67
+ predictions = demo_postprocess(output[0], input_shape)[0]
68
 
69
  boxes = predictions[:, :4]
70
  scores = predictions[:, 4:5] * predictions[:, 5:]
demo/OpenVINO/python/openvino_inference.py CHANGED
@@ -128,7 +128,7 @@ def main():
128
  # ---------------------------Step 8. Process output--------------------------------------------------------------------
129
  res = res[out_blob]
130
 
131
- predictions = demo_postprocess(res, (h, w), p6=False)[0]
132
 
133
  boxes = predictions[:, :4]
134
  scores = predictions[:, 4, None] * predictions[:, 5:]
 
128
  # ---------------------------Step 8. Process output--------------------------------------------------------------------
129
  res = res[out_blob]
130
 
131
+ predictions = demo_postprocess(res, (h, w))[0]
132
 
133
  boxes = predictions[:, :4]
134
  scores = predictions[:, 4, None] * predictions[:, 5:]
requirements.txt CHANGED
@@ -9,10 +9,10 @@ thop
9
  ninja
10
  tabulate
11
  psutil
 
12
 
13
  # verified versions
14
  # pycocotools corresponds to https://github.com/ppwwyyxx/cocoapi
15
  pycocotools>=2.0.2
16
- onnx==1.8.1
17
- onnxruntime==1.8.0
18
- onnx-simplifier==0.4.1
 
9
  ninja
10
  tabulate
11
  psutil
12
+ tensorboard
13
 
14
  # verified versions
15
  # pycocotools corresponds to https://github.com/ppwwyyxx/cocoapi
16
  pycocotools>=2.0.2
17
+ onnx>=1.13.0
18
+ onnx-simplifier==0.4.10
 
yolox/evaluators/voc_eval.py CHANGED
@@ -107,7 +107,7 @@ def voc_eval(
107
  for imagename in imagenames:
108
  R = [obj for obj in recs[imagename] if obj["name"] == classname]
109
  bbox = np.array([x["bbox"] for x in R])
110
- difficult = np.array([x["difficult"] for x in R]).astype(np.bool)
111
  det = [False] * len(R)
112
  npos = npos + sum(~difficult)
113
  class_recs[imagename] = {"bbox": bbox, "difficult": difficult, "det": det}
 
107
  for imagename in imagenames:
108
  R = [obj for obj in recs[imagename] if obj["name"] == classname]
109
  bbox = np.array([x["bbox"] for x in R])
110
+ difficult = np.array([x["difficult"] for x in R]).astype(bool)
111
  det = [False] * len(R)
112
  npos = npos + sum(~difficult)
113
  class_recs[imagename] = {"bbox": bbox, "difficult": difficult, "det": det}
yolox/exp/default/__init__.py CHANGED
@@ -4,8 +4,8 @@
4
 
5
  # This file is used for package installation and find default exp file
6
 
7
- import importlib
8
  import sys
 
9
  from pathlib import Path
10
 
11
  _EXP_PATH = Path(__file__).resolve().parent.parent.parent.parent / "exps" / "default"
@@ -14,7 +14,7 @@ if _EXP_PATH.is_dir():
14
  # This is true only for in-place installation (pip install -e, setup.py develop),
15
  # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
16
 
17
- class _ExpFinder(importlib.abc.MetaPathFinder):
18
 
19
  def find_spec(self, name, path, target=None):
20
  if not name.startswith("yolox.exp.default"):
@@ -23,6 +23,6 @@ if _EXP_PATH.is_dir():
23
  target_file = _EXP_PATH / project_name
24
  if not target_file.is_file():
25
  return
26
- return importlib.util.spec_from_file_location(name, target_file)
27
 
28
  sys.meta_path.append(_ExpFinder())
 
4
 
5
  # This file is used for package installation and find default exp file
6
 
 
7
  import sys
8
+ from importlib import abc, util
9
  from pathlib import Path
10
 
11
  _EXP_PATH = Path(__file__).resolve().parent.parent.parent.parent / "exps" / "default"
 
14
  # This is true only for in-place installation (pip install -e, setup.py develop),
15
  # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
16
 
17
+ class _ExpFinder(abc.MetaPathFinder):
18
 
19
  def find_spec(self, name, path, target=None):
20
  if not name.startswith("yolox.exp.default"):
 
23
  target_file = _EXP_PATH / project_name
24
  if not target_file.is_file():
25
  return
26
+ return util.spec_from_file_location(name, target_file)
27
 
28
  sys.meta_path.append(_ExpFinder())
yolox/tools/__init__.py CHANGED
@@ -1,11 +1,10 @@
1
  #!/usr/bin/env python3
2
- # -*- coding:utf-8 -*-
3
  # Copyright (c) Megvii Inc. All rights reserved.
4
 
5
  # This file is used for package installation. Script of train/eval/export will be available.
6
 
7
- import importlib
8
  import sys
 
9
  from pathlib import Path
10
 
11
  _TOOLS_PATH = Path(__file__).resolve().parent.parent.parent / "tools"
@@ -14,7 +13,7 @@ if _TOOLS_PATH.is_dir():
14
  # This is true only for in-place installation (pip install -e, setup.py develop),
15
  # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
16
 
17
- class _PathFinder(importlib.abc.MetaPathFinder):
18
 
19
  def find_spec(self, name, path, target=None):
20
  if not name.startswith("yolox.tools."):
@@ -23,6 +22,6 @@ if _TOOLS_PATH.is_dir():
23
  target_file = _TOOLS_PATH / project_name
24
  if not target_file.is_file():
25
  return
26
- return importlib.util.spec_from_file_location(name, target_file)
27
 
28
  sys.meta_path.append(_PathFinder())
 
1
  #!/usr/bin/env python3
 
2
  # Copyright (c) Megvii Inc. All rights reserved.
3
 
4
  # This file is used for package installation. Script of train/eval/export will be available.
5
 
 
6
  import sys
7
+ from importlib import abc, util
8
  from pathlib import Path
9
 
10
  _TOOLS_PATH = Path(__file__).resolve().parent.parent.parent / "tools"
 
13
  # This is true only for in-place installation (pip install -e, setup.py develop),
14
  # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
15
 
16
+ class _PathFinder(abc.MetaPathFinder):
17
 
18
  def find_spec(self, name, path, target=None):
19
  if not name.startswith("yolox.tools."):
 
22
  target_file = _TOOLS_PATH / project_name
23
  if not target_file.is_file():
24
  return
25
+ return util.spec_from_file_location(name, target_file)
26
 
27
  sys.meta_path.append(_PathFinder())
yolox/utils/demo_utils.py CHANGED
@@ -1,5 +1,4 @@
1
  #!/usr/bin/env python3
2
- # -*- coding:utf-8 -*-
3
  # Copyright (c) Megvii Inc. All rights reserved.
4
 
5
  import os
@@ -97,14 +96,9 @@ def multiclass_nms_class_agnostic(boxes, scores, nms_thr, score_thr):
97
 
98
 
99
  def demo_postprocess(outputs, img_size, p6=False):
100
-
101
  grids = []
102
  expanded_strides = []
103
-
104
- if not p6:
105
- strides = [8, 16, 32]
106
- else:
107
- strides = [8, 16, 32, 64]
108
 
109
  hsizes = [img_size[0] // stride for stride in strides]
110
  wsizes = [img_size[1] // stride for stride in strides]
 
1
  #!/usr/bin/env python3
 
2
  # Copyright (c) Megvii Inc. All rights reserved.
3
 
4
  import os
 
96
 
97
 
98
  def demo_postprocess(outputs, img_size, p6=False):
 
99
  grids = []
100
  expanded_strides = []
101
+ strides = [8, 16, 32] if not p6 else [8, 16, 32, 64]
 
 
 
 
102
 
103
  hsizes = [img_size[0] // stride for stride in strides]
104
  wsizes = [img_size[1] // stride for stride in strides]