Skip to content

Commit

Permalink
refactor(YOLOX): refactor datasets and add demo_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
FateScript committed Jul 19, 2021
1 parent cbc1900 commit bae9234
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 97 deletions.
24 changes: 24 additions & 0 deletions datasets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Prepare datasets

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.
```
$YOLOX_DATADIR/
COCO/
```
You can set the location for builtin datasets by
```shell
export YOLOX_DATADIR=/path/to/your/datasets
```
If `YOLOX_DATADIR` is not set, the default value of dataset directory is `./datasets` relative to your current working directory.

## Expected dataset structure for [COCO detection](https://cocodataset.org/#download):

```
COCO/
annotations/
instances_{train,val}2017.json
{train,val}2017/
# image files that are mentioned in the corresponding json
```

You can use the 2014 version of the dataset as well.
16 changes: 10 additions & 6 deletions demo/ONNXRuntime/onnx_inference.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import argparse
import os

import cv2
import numpy as np

import onnxruntime

from yolox.data.data_augment import preproc as preprocess
from yolox.data.datasets import COCO_CLASSES
from yolox.utils.visualize import vis

import argparse
import onnxruntime
import os
from demo_utils import mkdir, multiclass_nms, postprocess
from yolox.utils import mkdir, multiclass_nms, postprocess, vis


def make_parser():
Expand Down
86 changes: 0 additions & 86 deletions demo/OpenVINO/python/demo_utils.py

This file was deleted.

6 changes: 4 additions & 2 deletions demo/OpenVINO/python/openvino_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) Megvii, Inc. and its affiliates.

import argparse
import logging as log
import os
Expand All @@ -10,11 +12,11 @@
import cv2
import numpy as np

from demo_utils import mkdir, multiclass_nms, postprocess
from openvino.inference_engine import IECore

from yolox.data.data_augment import preproc as preprocess
from yolox.data.datasets import COCO_CLASSES
from yolox.utils.visualize import vis
from yolox.utils import mkdir, multiclass_nms, postprocess, vis


def parse_args() -> argparse.Namespace:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ known_standard_library = setuptools
known_third_party = tqdm,loguru
known_data_processing = cv2,numpy,scipy,PIL,matplotlib,scikit_image
known_datasets = pycocotools
known_deeplearning = torch,torchvision,caffe2,onnx,apex,timm,thop,torch2trt,tensorrt
known_deeplearning = torch,torchvision,caffe2,onnx,apex,timm,thop,torch2trt,tensorrt,openvino,onnxruntime
known_myself = yolox
sections = FUTURE,STDLIB,THIRDPARTY,data_processing,datasets,deeplearning,myself,FIRSTPARTY,LOCALFOLDER
no_lines_before=STDLIB,THIRDPARTY,datasets
Expand Down
3 changes: 2 additions & 1 deletion yolox/data/dataloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def get_yolox_datadir():
yolox_datadir = os.getenv("YOLOX_DATADIR", None)
if yolox_datadir is None:
import yolox
yolox_datadir = os.path.join(os.path.dirname(yolox.__file__), "data")
yolox_path = os.path.dirname(os.path.dirname(yolox.__file__))
yolox_datadir = os.path.join(yolox_path, "datasets")
return yolox_datadir


Expand Down
1 change: 1 addition & 0 deletions yolox/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .allreduce_norm import *
from .boxes import *
from .checkpoint import load_ckpt, save_checkpoint
from .demo_utils import *
from .dist import *
from .ema import ModelEMA
from .logger import setup_logger
Expand Down
8 changes: 7 additions & 1 deletion demo/ONNXRuntime/demo_utils.py → yolox/utils/demo_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import numpy as np
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.

import os

import numpy as np

__all__ = ["mkdir", "nms", "multiclass_nms", "postprocess"]


def mkdir(path):
if not os.path.exists(path):
Expand Down

0 comments on commit bae9234

Please sign in to comment.