Skip to content

Commit bae9234

Browse files
committed
refactor(YOLOX): refactor datasets and add demo_utils
1 parent cbc1900 commit bae9234

File tree

8 files changed

+49
-97
lines changed

8 files changed

+49
-97
lines changed

datasets/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Prepare datasets
2+
3+
If you have a dataset directory, you could use os environment variable named `YOLOX_DATADIR`. Under this directory, YOLOX will look for datasets in the structure described below, if needed.
4+
```
5+
$YOLOX_DATADIR/
6+
COCO/
7+
```
8+
You can set the location for builtin datasets by
9+
```shell
10+
export YOLOX_DATADIR=/path/to/your/datasets
11+
```
12+
If `YOLOX_DATADIR` is not set, the default value of dataset directory is `./datasets` relative to your current working directory.
13+
14+
## Expected dataset structure for [COCO detection](https://cocodataset.org/#download):
15+
16+
```
17+
COCO/
18+
annotations/
19+
instances_{train,val}2017.json
20+
{train,val}2017/
21+
# image files that are mentioned in the corresponding json
22+
```
23+
24+
You can use the 2014 version of the dataset as well.

demo/ONNXRuntime/onnx_inference.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) Megvii, Inc. and its affiliates.
4+
5+
import argparse
6+
import os
7+
18
import cv2
29
import numpy as np
310

11+
import onnxruntime
12+
413
from yolox.data.data_augment import preproc as preprocess
514
from yolox.data.datasets import COCO_CLASSES
6-
from yolox.utils.visualize import vis
7-
8-
import argparse
9-
import onnxruntime
10-
import os
11-
from demo_utils import mkdir, multiclass_nms, postprocess
15+
from yolox.utils import mkdir, multiclass_nms, postprocess, vis
1216

1317

1418
def make_parser():

demo/OpenVINO/python/demo_utils.py

-86
This file was deleted.

demo/OpenVINO/python/openvino_inference.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (C) 2018-2021 Intel Corporation
44
# SPDX-License-Identifier: Apache-2.0
5+
# Copyright (c) Megvii, Inc. and its affiliates.
6+
57
import argparse
68
import logging as log
79
import os
@@ -10,11 +12,11 @@
1012
import cv2
1113
import numpy as np
1214

13-
from demo_utils import mkdir, multiclass_nms, postprocess
1415
from openvino.inference_engine import IECore
16+
1517
from yolox.data.data_augment import preproc as preprocess
1618
from yolox.data.datasets import COCO_CLASSES
17-
from yolox.utils.visualize import vis
19+
from yolox.utils import mkdir, multiclass_nms, postprocess, vis
1820

1921

2022
def parse_args() -> argparse.Namespace:

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ known_standard_library = setuptools
66
known_third_party = tqdm,loguru
77
known_data_processing = cv2,numpy,scipy,PIL,matplotlib,scikit_image
88
known_datasets = pycocotools
9-
known_deeplearning = torch,torchvision,caffe2,onnx,apex,timm,thop,torch2trt,tensorrt
9+
known_deeplearning = torch,torchvision,caffe2,onnx,apex,timm,thop,torch2trt,tensorrt,openvino,onnxruntime
1010
known_myself = yolox
1111
sections = FUTURE,STDLIB,THIRDPARTY,data_processing,datasets,deeplearning,myself,FIRSTPARTY,LOCALFOLDER
1212
no_lines_before=STDLIB,THIRDPARTY,datasets

yolox/data/dataloading.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def get_yolox_datadir():
2020
yolox_datadir = os.getenv("YOLOX_DATADIR", None)
2121
if yolox_datadir is None:
2222
import yolox
23-
yolox_datadir = os.path.join(os.path.dirname(yolox.__file__), "data")
23+
yolox_path = os.path.dirname(os.path.dirname(yolox.__file__))
24+
yolox_datadir = os.path.join(yolox_path, "datasets")
2425
return yolox_datadir
2526

2627

yolox/utils/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .allreduce_norm import *
66
from .boxes import *
77
from .checkpoint import load_ckpt, save_checkpoint
8+
from .demo_utils import *
89
from .dist import *
910
from .ema import ModelEMA
1011
from .logger import setup_logger

demo/ONNXRuntime/demo_utils.py yolox/utils/demo_utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import numpy as np
1+
#!/usr/bin/env python3
2+
# -*- coding:utf-8 -*-
3+
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
24

35
import os
46

7+
import numpy as np
8+
9+
__all__ = ["mkdir", "nms", "multiclass_nms", "postprocess"]
10+
511

612
def mkdir(path):
713
if not os.path.exists(path):

0 commit comments

Comments
 (0)