未验证 提交 f15f1935 编写于 作者: F Feng Wang 提交者: GitHub

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

上级 5c110a25
......@@ -219,3 +219,10 @@ events.out.tfevents*
# vim
.vim
# OS generated files
.DS_Store
.DS_Store?
.Trashes
ehthumbs.db
Thumbs.db
......@@ -2,7 +2,18 @@
This doc introduces how to convert your pytorch model into onnx, and how to run an onnxruntime demo to verify your convertion.
### Download ONNX models.
### Step1: Install onnxruntime
run the following command to install onnxruntime:
```shell
pip install onnxruntime
```
### Step2: Get ONNX models
Users might download our pre-generated ONNX models or convert their own models to ONNX.
#### Download ONNX models.
| Model | Parameters | GFLOPs | Test Size | mAP | Weights |
|:------| :----: | :----: | :---: | :---: | :---: |
......@@ -14,8 +25,7 @@ This doc introduces how to convert your pytorch model into onnx, and how to run
| YOLOX-Darknet53| 63.72M | 185.3 | 640x640 |48.0 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_darknet.onnx) |
| YOLOX-X | 99.1M | 281.9 | 640x640 |51.5 | [github](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_x.onnx) |
### Convert Your Model to ONNX
#### Convert Your Model to ONNX
First, you should move to <YOLOX_HOME> by:
```shell
......@@ -38,7 +48,7 @@ Notes:
dummy_input = torch.randn(1, 3, exp.test_size[0], exp.test_size[1])
```
2. Convert a standard YOLOX model by -f. When using -f, the above command is equivalent to:
1. Convert a standard YOLOX model by -f. When using -f, the above command is equivalent to:
```shell
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.
python3 tools/export_onnx.py --output-name your_yolox.onnx -f exps/your_dir/your_yolox.py -c your_yolox.pth
```
### ONNXRuntime Demo
### Step3: ONNXRuntime Demo
Step1.
```shell
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.
import argparse
......@@ -51,11 +50,6 @@ def make_parser():
default="640,640",
help="Specify an input shape for inference.",
)
parser.add_argument(
"--with_p6",
action="store_true",
help="Whether your model uses p6 in FPN/PAN.",
)
return parser
......@@ -70,7 +64,7 @@ if __name__ == '__main__':
ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
output = session.run(None, ort_inputs)
predictions = demo_postprocess(output[0], input_shape, p6=args.with_p6)[0]
predictions = demo_postprocess(output[0], input_shape)[0]
boxes = predictions[:, :4]
scores = predictions[:, 4:5] * predictions[:, 5:]
......
......@@ -128,7 +128,7 @@ def main():
# ---------------------------Step 8. Process output--------------------------------------------------------------------
res = res[out_blob]
predictions = demo_postprocess(res, (h, w), p6=False)[0]
predictions = demo_postprocess(res, (h, w))[0]
boxes = predictions[:, :4]
scores = predictions[:, 4, None] * predictions[:, 5:]
......
......@@ -9,10 +9,10 @@ thop
ninja
tabulate
psutil
tensorboard
# verified versions
# pycocotools corresponds to https://github.com/ppwwyyxx/cocoapi
pycocotools>=2.0.2
onnx==1.8.1
onnxruntime==1.8.0
onnx-simplifier==0.4.1
onnx>=1.13.0
onnx-simplifier==0.4.10
......@@ -107,7 +107,7 @@ def voc_eval(
for imagename in imagenames:
R = [obj for obj in recs[imagename] if obj["name"] == classname]
bbox = np.array([x["bbox"] for x in R])
difficult = np.array([x["difficult"] for x in R]).astype(np.bool)
difficult = np.array([x["difficult"] for x in R]).astype(bool)
det = [False] * len(R)
npos = npos + sum(~difficult)
class_recs[imagename] = {"bbox": bbox, "difficult": difficult, "det": det}
......
......@@ -4,8 +4,8 @@
# This file is used for package installation and find default exp file
import importlib
import sys
from importlib import abc, util
from pathlib import Path
_EXP_PATH = Path(__file__).resolve().parent.parent.parent.parent / "exps" / "default"
......@@ -14,7 +14,7 @@ if _EXP_PATH.is_dir():
# This is true only for in-place installation (pip install -e, setup.py develop),
# where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
class _ExpFinder(importlib.abc.MetaPathFinder):
class _ExpFinder(abc.MetaPathFinder):
def find_spec(self, name, path, target=None):
if not name.startswith("yolox.exp.default"):
......@@ -23,6 +23,6 @@ if _EXP_PATH.is_dir():
target_file = _EXP_PATH / project_name
if not target_file.is_file():
return
return importlib.util.spec_from_file_location(name, target_file)
return util.spec_from_file_location(name, target_file)
sys.meta_path.append(_ExpFinder())
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii Inc. All rights reserved.
# This file is used for package installation. Script of train/eval/export will be available.
import importlib
import sys
from importlib import abc, util
from pathlib import Path
_TOOLS_PATH = Path(__file__).resolve().parent.parent.parent / "tools"
......@@ -14,7 +13,7 @@ if _TOOLS_PATH.is_dir():
# This is true only for in-place installation (pip install -e, setup.py develop),
# where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
class _PathFinder(importlib.abc.MetaPathFinder):
class _PathFinder(abc.MetaPathFinder):
def find_spec(self, name, path, target=None):
if not name.startswith("yolox.tools."):
......@@ -23,6 +22,6 @@ if _TOOLS_PATH.is_dir():
target_file = _TOOLS_PATH / project_name
if not target_file.is_file():
return
return importlib.util.spec_from_file_location(name, target_file)
return util.spec_from_file_location(name, target_file)
sys.meta_path.append(_PathFinder())
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii Inc. All rights reserved.
import os
......@@ -97,14 +96,9 @@ def multiclass_nms_class_agnostic(boxes, scores, nms_thr, score_thr):
def demo_postprocess(outputs, img_size, p6=False):
grids = []
expanded_strides = []
if not p6:
strides = [8, 16, 32]
else:
strides = [8, 16, 32, 64]
strides = [8, 16, 32] if not p6 else [8, 16, 32, 64]
hsizes = [img_size[0] // stride for stride in strides]
wsizes = [img_size[1] // stride for stride in strides]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册