Skip to content

Commit f15f193

Browse files
authored
fix(yolox): some bugs due to upgrade (Megvii-BaseDetection#1602)
1 parent 5c110a2 commit f15f193

File tree

9 files changed

+35
-31
lines changed

9 files changed

+35
-31
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,10 @@ events.out.tfevents*
219219

220220
# vim
221221
.vim
222+
223+
# OS generated files
224+
.DS_Store
225+
.DS_Store?
226+
.Trashes
227+
ehthumbs.db
228+
Thumbs.db

demo/ONNXRuntime/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
This doc introduces how to convert your pytorch model into onnx, and how to run an onnxruntime demo to verify your convertion.
44

5-
### Download ONNX models.
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.
617

718
| Model | Parameters | GFLOPs | Test Size | mAP | Weights |
819
|:------| :----: | :----: | :---: | :---: | :---: |
@@ -14,8 +25,7 @@ This doc introduces how to convert your pytorch model into onnx, and how to run
1425
| YOLOX-Darknet53| 63.72M | 185.3 | 640x640 |48.0 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_darknet.onnx) |
1526
| YOLOX-X | 99.1M | 281.9 | 640x640 |51.5 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_x.onnx) |
1627

17-
18-
### Convert Your Model to ONNX
28+
#### Convert Your Model to ONNX
1929

2030
First, you should move to <YOLOX_HOME> by:
2131
```shell
@@ -38,7 +48,7 @@ Notes:
3848
dummy_input = torch.randn(1, 3, exp.test_size[0], exp.test_size[1])
3949
```
4050

41-
2. Convert a standard YOLOX model by -f. When using -f, the above command is equivalent to:
51+
1. Convert a standard YOLOX model by -f. When using -f, the above command is equivalent to:
4252

4353
```shell
4454
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.
5060
python3 tools/export_onnx.py --output-name your_yolox.onnx -f exps/your_dir/your_yolox.py -c your_yolox.pth
5161
```
5262

53-
### ONNXRuntime Demo
63+
### Step3: ONNXRuntime Demo
5464

5565
Step1.
5666
```shell

demo/ONNXRuntime/onnx_inference.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
# Copyright (c) Megvii, Inc. and its affiliates.
43

54
import argparse
@@ -51,11 +50,6 @@ def make_parser():
5150
default="640,640",
5251
help="Specify an input shape for inference.",
5352
)
54-
parser.add_argument(
55-
"--with_p6",
56-
action="store_true",
57-
help="Whether your model uses p6 in FPN/PAN.",
58-
)
5953
return parser
6054

6155

@@ -70,7 +64,7 @@ def make_parser():
7064

7165
ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
7266
output = session.run(None, ort_inputs)
73-
predictions = demo_postprocess(output[0], input_shape, p6=args.with_p6)[0]
67+
predictions = demo_postprocess(output[0], input_shape)[0]
7468

7569
boxes = predictions[:, :4]
7670
scores = predictions[:, 4:5] * predictions[:, 5:]

demo/OpenVINO/python/openvino_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def main():
128128
# ---------------------------Step 8. Process output--------------------------------------------------------------------
129129
res = res[out_blob]
130130

131-
predictions = demo_postprocess(res, (h, w), p6=False)[0]
131+
predictions = demo_postprocess(res, (h, w))[0]
132132

133133
boxes = predictions[:, :4]
134134
scores = predictions[:, 4, None] * predictions[:, 5:]

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ thop
99
ninja
1010
tabulate
1111
psutil
12+
tensorboard
1213

1314
# verified versions
1415
# pycocotools corresponds to https://github.com/ppwwyyxx/cocoapi
1516
pycocotools>=2.0.2
16-
onnx==1.8.1
17-
onnxruntime==1.8.0
18-
onnx-simplifier==0.4.1
17+
onnx>=1.13.0
18+
onnx-simplifier==0.4.10

yolox/evaluators/voc_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def voc_eval(
107107
for imagename in imagenames:
108108
R = [obj for obj in recs[imagename] if obj["name"] == classname]
109109
bbox = np.array([x["bbox"] for x in R])
110-
difficult = np.array([x["difficult"] for x in R]).astype(np.bool)
110+
difficult = np.array([x["difficult"] for x in R]).astype(bool)
111111
det = [False] * len(R)
112112
npos = npos + sum(~difficult)
113113
class_recs[imagename] = {"bbox": bbox, "difficult": difficult, "det": det}

yolox/exp/default/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# This file is used for package installation and find default exp file
66

7-
import importlib
87
import sys
8+
from importlib import abc, util
99
from pathlib import Path
1010

1111
_EXP_PATH = Path(__file__).resolve().parent.parent.parent.parent / "exps" / "default"
@@ -14,7 +14,7 @@
1414
# This is true only for in-place installation (pip install -e, setup.py develop),
1515
# where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
1616

17-
class _ExpFinder(importlib.abc.MetaPathFinder):
17+
class _ExpFinder(abc.MetaPathFinder):
1818

1919
def find_spec(self, name, path, target=None):
2020
if not name.startswith("yolox.exp.default"):
@@ -23,6 +23,6 @@ def find_spec(self, name, path, target=None):
2323
target_file = _EXP_PATH / project_name
2424
if not target_file.is_file():
2525
return
26-
return importlib.util.spec_from_file_location(name, target_file)
26+
return util.spec_from_file_location(name, target_file)
2727

2828
sys.meta_path.append(_ExpFinder())

yolox/tools/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env python3
2-
# -*- coding:utf-8 -*-
32
# Copyright (c) Megvii Inc. All rights reserved.
43

54
# This file is used for package installation. Script of train/eval/export will be available.
65

7-
import importlib
86
import sys
7+
from importlib import abc, util
98
from pathlib import Path
109

1110
_TOOLS_PATH = Path(__file__).resolve().parent.parent.parent / "tools"
@@ -14,7 +13,7 @@
1413
# This is true only for in-place installation (pip install -e, setup.py develop),
1514
# where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
1615

17-
class _PathFinder(importlib.abc.MetaPathFinder):
16+
class _PathFinder(abc.MetaPathFinder):
1817

1918
def find_spec(self, name, path, target=None):
2019
if not name.startswith("yolox.tools."):
@@ -23,6 +22,6 @@ def find_spec(self, name, path, target=None):
2322
target_file = _TOOLS_PATH / project_name
2423
if not target_file.is_file():
2524
return
26-
return importlib.util.spec_from_file_location(name, target_file)
25+
return util.spec_from_file_location(name, target_file)
2726

2827
sys.meta_path.append(_PathFinder())

yolox/utils/demo_utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding:utf-8 -*-
32
# Copyright (c) Megvii Inc. All rights reserved.
43

54
import os
@@ -97,14 +96,9 @@ def multiclass_nms_class_agnostic(boxes, scores, nms_thr, score_thr):
9796

9897

9998
def demo_postprocess(outputs, img_size, p6=False):
100-
10199
grids = []
102100
expanded_strides = []
103-
104-
if not p6:
105-
strides = [8, 16, 32]
106-
else:
107-
strides = [8, 16, 32, 64]
101+
strides = [8, 16, 32] if not p6 else [8, 16, 32, 64]
108102

109103
hsizes = [img_size[0] // stride for stride in strides]
110104
wsizes = [img_size[1] // stride for stride in strides]

0 commit comments

Comments
 (0)