├── docs ├── .gitignore ├── demo │ ├── ncnn_cpp_readme.md │ ├── onnx_readme.md │ ├── trt_cpp_readme.md │ ├── trt_py_readme.md │ ├── megengine_cpp_readme.md │ ├── ncnn_android_readme.md │ ├── openvino_cpp_readme.md │ ├── openvino_py_readme.md │ └── megengine_py_readme.md ├── requirements-doc.txt ├── index.rst ├── Makefile ├── _static │ └── css │ │ └── custom.css ├── freeze_module.md ├── assignment_visualization.md ├── updates_note.md ├── manipulate_training_image_size.md ├── mlflow_integration.md ├── quick_run.md ├── model_zoo.md └── cache.md ├── demo ├── ncnn │ ├── android │ │ ├── settings.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── app │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ └── strings.xml │ │ │ │ │ └── layout │ │ │ │ │ │ └── main.xml │ │ │ │ │ ├── jni │ │ │ │ │ └── CMakeLists.txt │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── megvii │ │ │ │ │ └── yoloXncnn │ │ │ │ │ ├── YOLOXncnn.java │ │ │ │ │ └── yoloXncnn.java │ │ │ └── build.gradle │ │ ├── build.gradle │ │ ├── README.md │ │ └── gradlew.bat │ ├── README.md │ └── cpp │ │ └── README.md ├── OpenVINO │ ├── README.md │ ├── cpp │ │ ├── CMakeLists.txt │ │ └── README.md │ └── python │ │ └── README.md ├── MegEngine │ ├── python │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── yolox.py │ │ │ ├── yolo_fpn.py │ │ │ └── yolo_pafpn.py │ │ ├── README.md │ │ ├── dump.py │ │ ├── build.py │ │ └── convert_weights.py │ └── cpp │ │ └── build.sh ├── TensorRT │ ├── cpp │ │ ├── CMakeLists.txt │ │ └── README.md │ └── python │ │ └── README.md ├── nebullvm │ ├── nebullvm_optimization.py │ └── README.md └── ONNXRuntime │ ├── onnx_inference.py │ └── README.md ├── tests ├── __init__.py └── utils │ └── test_model_utils.py ├── assets ├── demo.png ├── dog.jpg ├── logo.png ├── git_fig.png ├── sunjian.png └── assignment.png ├── MANIFEST.in ├── yolox ├── __init__.py ├── core │ ├── __init__.py │ └── launch.py ├── exp │ ├── __init__.py │ ├── default │ │ └── __init__.py │ ├── build.py │ └── base_exp.py ├── evaluators │ └── __init__.py ├── models │ ├── __init__.py │ ├── yolox.py │ ├── losses.py │ ├── yolo_fpn.py │ ├── yolo_pafpn.py │ └── build.py ├── data │ ├── datasets │ │ ├── __init__.py │ │ ├── voc_classes.py │ │ └── coco_classes.py │ ├── __init__.py │ ├── data_prefetcher.py │ ├── samplers.py │ └── dataloading.py ├── utils │ ├── compat.py │ ├── __init__.py │ ├── checkpoint.py │ ├── ema.py │ ├── setup_env.py │ ├── allreduce_norm.py │ ├── metric.py │ ├── visualize.py │ ├── boxes.py │ └── demo_utils.py ├── layers │ ├── __init__.py │ ├── cocoeval │ │ └── cocoeval.h │ └── jit_ops.py └── tools │ └── __init__.py ├── tools ├── __init__.py ├── export_torchscript.py ├── trt.py ├── visualize_assign.py ├── export_onnx.py └── train.py ├── exps ├── default │ ├── __init__.py │ ├── yolox_l.py │ ├── yolox_m.py │ ├── yolox_s.py │ ├── yolox_x.py │ ├── yolox_tiny.py │ ├── yolov3.py │ └── yolox_nano.py └── example │ ├── custom │ ├── yolox_s.py │ └── nano.py │ └── yolox_voc │ └── yolox_voc_s.py ├── requirements.txt ├── .github └── workflows │ ├── format_check.sh │ └── ci.yaml ├── hubconf.py ├── .readthedocs.yaml ├── setup.cfg ├── datasets └── README.md ├── .pre-commit-config.yaml ├── SECURITY.md ├── setup.py └── .gitignore /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build -------------------------------------------------------------------------------- /demo/ncnn/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /docs/demo/ncnn_cpp_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/ncnn/cpp/README.md -------------------------------------------------------------------------------- /docs/demo/onnx_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/ONNXRuntime/README.md -------------------------------------------------------------------------------- /docs/demo/trt_cpp_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/TensorRT/cpp/README.md -------------------------------------------------------------------------------- /docs/demo/trt_py_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/TensorRT/python/README.md -------------------------------------------------------------------------------- /docs/demo/megengine_cpp_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/MegEngine/cpp/README.md -------------------------------------------------------------------------------- /docs/demo/ncnn_android_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/ncnn/android/README.md -------------------------------------------------------------------------------- /docs/demo/openvino_cpp_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/OpenVINO/cpp/README.md -------------------------------------------------------------------------------- /docs/demo/openvino_py_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/OpenVINO/python/README.md -------------------------------------------------------------------------------- /docs/demo/megengine_py_readme.md: -------------------------------------------------------------------------------- 1 | ../../demo/MegEngine/python/README.md -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | -------------------------------------------------------------------------------- /assets/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/assets/demo.png -------------------------------------------------------------------------------- /assets/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/assets/dog.jpg -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/assets/logo.png -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements.txt 2 | recursive-include yolox *.cpp *.h *.cu *.cuh *.cc 3 | -------------------------------------------------------------------------------- /assets/git_fig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/assets/git_fig.png -------------------------------------------------------------------------------- /assets/sunjian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/assets/sunjian.png -------------------------------------------------------------------------------- /demo/OpenVINO/README.md: -------------------------------------------------------------------------------- 1 | ## YOLOX for OpenVINO 2 | 3 | * [C++ Demo](./cpp) 4 | * [Python Demo](./python) -------------------------------------------------------------------------------- /yolox/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | __version__ = "0.3.0" 5 | -------------------------------------------------------------------------------- /assets/assignment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/assets/assignment.png -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | -------------------------------------------------------------------------------- /exps/default/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | -------------------------------------------------------------------------------- /demo/ncnn/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/HEAD/demo/ncnn/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/ncnn/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | yoloXncnn 4 | 5 | -------------------------------------------------------------------------------- /yolox/core/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | from .launch import launch 6 | from .trainer import Trainer 7 | -------------------------------------------------------------------------------- /yolox/exp/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Megvii Inc. All rights reserved. 3 | 4 | from .base_exp import BaseExp 5 | from .build import get_exp 6 | from .yolox_base import Exp, check_exp_value 7 | -------------------------------------------------------------------------------- /yolox/evaluators/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | from .coco_evaluator import COCOEvaluator 6 | from .voc_evaluator import VOCEvaluator 7 | -------------------------------------------------------------------------------- /docs/requirements-doc.txt: -------------------------------------------------------------------------------- 1 | docutils==0.16 2 | # https://github.com/sphinx-doc/sphinx/commit/7acd3ada3f38076af7b2b5c9f3b60bb9c2587a3d 3 | sphinx==3.2.0 4 | recommonmark==0.6.0 5 | sphinx_rtd_theme 6 | omegaconf>=2.1.0.dev24 7 | hydra-core>=1.1.0.dev5 8 | sphinx-markdown-tables==0.0.15 9 | -------------------------------------------------------------------------------- /demo/ncnn/README.md: -------------------------------------------------------------------------------- 1 | # YOLOX-ncnn 2 | 3 | Compile files of YOLOX object detection base on [ncnn](https://github.com/Tencent/ncnn). 4 | YOLOX is included in ncnn now, you could also try building from ncnn, it's better. 5 | 6 | ## Acknowledgement 7 | 8 | * [ncnn](https://github.com/Tencent/ncnn) 9 | -------------------------------------------------------------------------------- /demo/ncnn/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Aug 25 10:34:48 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /demo/MegEngine/python/models/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii Inc. All rights reserved. 4 | 5 | from .darknet import CSPDarknet, Darknet 6 | from .yolo_fpn import YOLOFPN 7 | from .yolo_head import YOLOXHead 8 | from .yolo_pafpn import YOLOPAFPN 9 | from .yolox import YOLOX 10 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # TODO: Update with exact module version 2 | numpy 3 | torch>=1.7 4 | opencv_python 5 | loguru 6 | tqdm 7 | torchvision 8 | thop 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 19 | -------------------------------------------------------------------------------- /yolox/models/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii Inc. All rights reserved. 4 | 5 | from .build import * 6 | from .darknet import CSPDarknet, Darknet 7 | from .losses import IOUloss 8 | from .yolo_fpn import YOLOFPN 9 | from .yolo_head import YOLOXHead 10 | from .yolo_pafpn import YOLOPAFPN 11 | from .yolox import YOLOX 12 | -------------------------------------------------------------------------------- /yolox/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | from .coco import COCODataset 6 | from .coco_classes import COCO_CLASSES 7 | from .datasets_wrapper import CacheDataset, ConcatDataset, Dataset, MixConcatDataset 8 | from .mosaicdetection import MosaicDetection 9 | from .voc import VOCDetection 10 | -------------------------------------------------------------------------------- /yolox/utils/compat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | import torch 5 | 6 | _TORCH_VER = [int(x) for x in torch.__version__.split(".")[:2]] 7 | 8 | __all__ = ["meshgrid"] 9 | 10 | 11 | def meshgrid(*tensors): 12 | if _TORCH_VER >= [1, 10]: 13 | return torch.meshgrid(*tensors, indexing="ij") 14 | else: 15 | return torch.meshgrid(*tensors) 16 | -------------------------------------------------------------------------------- /demo/ncnn/android/app/src/main/jni/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(yoloXncnn) 2 | 3 | cmake_minimum_required(VERSION 3.4.1) 4 | 5 | set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20210525-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn) 6 | find_package(ncnn REQUIRED) 7 | 8 | add_library(yoloXncnn SHARED yoloXncnn_jni.cpp) 9 | 10 | target_link_libraries(yoloXncnn 11 | ncnn 12 | 13 | jnigraphics 14 | ) 15 | -------------------------------------------------------------------------------- /yolox/data/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | from .data_augment import TrainTransform, ValTransform 6 | from .data_prefetcher import DataPrefetcher 7 | from .dataloading import DataLoader, get_yolox_datadir, worker_init_reset_seed 8 | from .datasets import * 9 | from .samplers import InfiniteSampler, YoloBatchSampler 10 | -------------------------------------------------------------------------------- /.github/workflows/format_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | set -e 4 | 5 | export PYTHONPATH=$PWD:$PYTHONPATH 6 | 7 | flake8 yolox exps tools || flake8_ret=$? 8 | if [ "$flake8_ret" ]; then 9 | exit $flake8_ret 10 | fi 11 | echo "All flake check passed!" 12 | isort --check-only -rc yolox exps || isort_ret=$? 13 | if [ "$isort_ret" ]; then 14 | exit $isort_ret 15 | fi 16 | echo "All isort check passed!" 17 | -------------------------------------------------------------------------------- /demo/ncnn/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | google() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.5.0' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | google() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /exps/default/yolox_l.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | import os 6 | 7 | from yolox.exp import Exp as MyExp 8 | 9 | 10 | class Exp(MyExp): 11 | def __init__(self): 12 | super(Exp, self).__init__() 13 | self.depth = 1.0 14 | self.width = 1.0 15 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 16 | -------------------------------------------------------------------------------- /exps/default/yolox_m.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | import os 6 | 7 | from yolox.exp import Exp as MyExp 8 | 9 | 10 | class Exp(MyExp): 11 | def __init__(self): 12 | super(Exp, self).__init__() 13 | self.depth = 0.67 14 | self.width = 0.75 15 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 16 | -------------------------------------------------------------------------------- /exps/default/yolox_s.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | import os 6 | 7 | from yolox.exp import Exp as MyExp 8 | 9 | 10 | class Exp(MyExp): 11 | def __init__(self): 12 | super(Exp, self).__init__() 13 | self.depth = 0.33 14 | self.width = 0.50 15 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 16 | -------------------------------------------------------------------------------- /exps/default/yolox_x.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | import os 6 | 7 | from yolox.exp import Exp as MyExp 8 | 9 | 10 | class Exp(MyExp): 11 | def __init__(self): 12 | super(Exp, self).__init__() 13 | self.depth = 1.33 14 | self.width = 1.25 15 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 16 | -------------------------------------------------------------------------------- /yolox/layers/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii Inc. All rights reserved. 4 | 5 | # import torch first to make jit op work without `ImportError of libc10.so` 6 | import torch # noqa 7 | 8 | from .jit_ops import FastCOCOEvalOp, JitOp 9 | 10 | try: 11 | from .fast_coco_eval_api import COCOeval_opt 12 | except ImportError: # exception will be raised when users build yolox from source 13 | pass 14 | -------------------------------------------------------------------------------- /yolox/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Megvii Inc. All rights reserved. 3 | 4 | from .allreduce_norm import * 5 | from .boxes import * 6 | from .checkpoint import load_ckpt, save_checkpoint 7 | from .compat import meshgrid 8 | from .demo_utils import * 9 | from .dist import * 10 | from .ema import * 11 | from .logger import WandbLogger, setup_logger 12 | from .lr_scheduler import LRScheduler 13 | from .metric import * 14 | from .mlflow_logger import MlflowLogger 15 | from .model_utils import * 16 | from .setup_env import * 17 | from .visualize import * 18 | -------------------------------------------------------------------------------- /yolox/data/datasets/voc_classes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | # VOC_CLASSES = ( '__background__', # always index 0 6 | VOC_CLASSES = ( 7 | "aeroplane", 8 | "bicycle", 9 | "bird", 10 | "boat", 11 | "bottle", 12 | "bus", 13 | "car", 14 | "cat", 15 | "chair", 16 | "cow", 17 | "diningtable", 18 | "dog", 19 | "horse", 20 | "motorbike", 21 | "person", 22 | "pottedplant", 23 | "sheep", 24 | "sofa", 25 | "train", 26 | "tvmonitor", 27 | ) 28 | -------------------------------------------------------------------------------- /hubconf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | """ 5 | Usage example: 6 | import torch 7 | model = torch.hub.load("Megvii-BaseDetection/YOLOX", "yolox_s") 8 | model = torch.hub.load("Megvii-BaseDetection/YOLOX", "yolox_custom", 9 | exp_path="exp.py", ckpt_path="ckpt.pth") 10 | """ 11 | dependencies = ["torch"] 12 | 13 | from yolox.models import ( # isort:skip # noqa: F401, E402 14 | yolox_tiny, 15 | yolox_nano, 16 | yolox_s, 17 | yolox_m, 18 | yolox_l, 19 | yolox_x, 20 | yolov3, 21 | yolox_custom 22 | ) 23 | -------------------------------------------------------------------------------- /demo/OpenVINO/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | set(CMAKE_CXX_STANDARD 14) 3 | 4 | project(yolox_openvino_demo) 5 | 6 | find_package(OpenCV REQUIRED) 7 | find_package(InferenceEngine REQUIRED) 8 | find_package(ngraph REQUIRED) 9 | 10 | include_directories( 11 | ${OpenCV_INCLUDE_DIRS} 12 | ${CMAKE_CURRENT_SOURCE_DIR} 13 | ${CMAKE_CURRENT_BINARY_DIR} 14 | ) 15 | 16 | add_executable(yolox_openvino yolox_openvino.cpp) 17 | 18 | target_link_libraries( 19 | yolox_openvino 20 | ${InferenceEngine_LIBRARIES} 21 | ${NGRAPH_LIBRARIES} 22 | ${OpenCV_LIBS} 23 | ) -------------------------------------------------------------------------------- /demo/ncnn/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "29.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.megvii.yoloXncnn" 9 | archivesBaseName = "$applicationId" 10 | 11 | ndk { 12 | moduleName "ncnn" 13 | abiFilters "armeabi-v7a", "arm64-v8a" 14 | } 15 | minSdkVersion 24 16 | } 17 | 18 | externalNativeBuild { 19 | cmake { 20 | version "3.10.2" 21 | path file('src/main/jni/CMakeLists.txt') 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | configuration: docs/conf.py 11 | 12 | # Optionally build your docs in additional formats such as PDF 13 | formats: 14 | - pdf 15 | 16 | # Optionally set the version of Python and requirements required to build your docs 17 | python: 18 | version: "3.7" 19 | install: 20 | - requirements: docs/requirements-doc.txt 21 | - requirements: requirements.txt 22 | -------------------------------------------------------------------------------- /exps/default/yolox_tiny.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | import os 6 | 7 | from yolox.exp import Exp as MyExp 8 | 9 | 10 | class Exp(MyExp): 11 | def __init__(self): 12 | super(Exp, self).__init__() 13 | self.depth = 0.33 14 | self.width = 0.375 15 | self.input_size = (416, 416) 16 | self.mosaic_scale = (0.5, 1.5) 17 | self.random_size = (10, 20) 18 | self.test_size = (416, 416) 19 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 20 | self.enable_mixup = False 21 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [isort] 2 | line_length = 100 3 | multi_line_output = 3 4 | balanced_wrapping = True 5 | known_standard_library = setuptools 6 | known_third_party = tqdm,loguru,tabulate,psutil 7 | known_data_processing = cv2,numpy,scipy,PIL,matplotlib 8 | known_datasets = pycocotools 9 | known_deeplearning = torch,torchvision,caffe2,onnx,apex,timm,thop,torch2trt,tensorrt,openvino,onnxruntime 10 | known_myself = yolox 11 | sections = FUTURE,STDLIB,THIRDPARTY,data_processing,datasets,deeplearning,myself,FIRSTPARTY,LOCALFOLDER 12 | no_lines_before=STDLIB,THIRDPARTY,datasets 13 | default_section = FIRSTPARTY 14 | 15 | [flake8] 16 | max-line-length = 100 17 | max-complexity = 18 18 | exclude = __init__.py 19 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Welcome to YOLOX's documentation! 3 | ====================================== 4 | 5 | .. image:: ../assets/logo.png 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | :caption: Quick Run 10 | 11 | quick_run 12 | model_zoo 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | :caption: Tutorials 17 | 18 | train_custom_data 19 | 20 | .. toctree:: 21 | :maxdepth: 2 22 | :caption: Deployment 23 | 24 | demo/trt_py_readme 25 | demo/trt_cpp_readme 26 | demo/megengine_cpp_readme 27 | demo/megengine_py_readme 28 | demo/ncnn_android_readme 29 | demo/ncnn_cpp_readme 30 | demo/onnx_readme 31 | demo/openvino_py_readme 32 | demo/openvino_cpp_readme 33 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = . 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * some extra css to make markdown look similar between github/sphinx 4 | */ 5 | 6 | /* 7 | * Below is for install.md: 8 | */ 9 | .rst-content code { 10 | white-space: pre; 11 | border: 0px; 12 | } 13 | 14 | .rst-content th { 15 | border: 1px solid #e1e4e5; 16 | } 17 | 18 | .rst-content th p { 19 | /* otherwise will be default 24px for regular paragraph */ 20 | margin-bottom: 0px; 21 | } 22 | 23 | .rst-content .line-block { 24 | /* otherwise will be 24px */ 25 | margin-bottom: 0px; 26 | } 27 | 28 | div.section > details { 29 | padding-bottom: 1em; 30 | } 31 | -------------------------------------------------------------------------------- /demo/ncnn/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /demo/ncnn/android/app/src/main/java/com/megvii/yoloXncnn/YOLOXncnn.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) Megvii, Inc. and its affiliates. All rights reserved. 2 | 3 | package com.megvii.yoloXncnn; 4 | 5 | import android.content.res.AssetManager; 6 | import android.graphics.Bitmap; 7 | 8 | public class YOLOXncnn 9 | { 10 | public native boolean Init(AssetManager mgr); 11 | 12 | public class Obj 13 | { 14 | public float x; 15 | public float y; 16 | public float w; 17 | public float h; 18 | public String label; 19 | public float prob; 20 | } 21 | 22 | public native Obj[] Detect(Bitmap bitmap, boolean use_gpu); 23 | 24 | static { 25 | System.loadLibrary("yoloXncnn"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /demo/ncnn/android/app/src/main/java/com/megvii/yoloXncnn/yoloXncnn.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) Megvii, Inc. and its affiliates. All rights reserved. 2 | 3 | package com.megvii.yoloXncnn; 4 | 5 | import android.content.res.AssetManager; 6 | import android.graphics.Bitmap; 7 | 8 | public class YOLOXncnn 9 | { 10 | public native boolean Init(AssetManager mgr); 11 | 12 | public class Obj 13 | { 14 | public float x; 15 | public float y; 16 | public float w; 17 | public float h; 18 | public String label; 19 | public float prob; 20 | } 21 | 22 | public native Obj[] Detect(Bitmap bitmap, boolean use_gpu); 23 | 24 | static { 25 | System.loadLibrary("yoloXncnn"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /exps/example/custom/yolox_s.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | import os 5 | 6 | from yolox.exp import Exp as MyExp 7 | 8 | 9 | class Exp(MyExp): 10 | def __init__(self): 11 | super(Exp, self).__init__() 12 | self.depth = 0.33 13 | self.width = 0.50 14 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 15 | 16 | # Define yourself dataset path 17 | self.data_dir = "datasets/coco128" 18 | self.train_ann = "instances_train2017.json" 19 | self.val_ann = "instances_val2017.json" 20 | 21 | self.num_classes = 71 22 | 23 | self.max_epoch = 300 24 | self.data_num_workers = 4 25 | self.eval_interval = 1 26 | -------------------------------------------------------------------------------- /datasets/README.md: -------------------------------------------------------------------------------- 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. 25 | -------------------------------------------------------------------------------- /demo/MegEngine/python/README.md: -------------------------------------------------------------------------------- 1 | # YOLOX-Python-MegEngine 2 | 3 | Python version of YOLOX object detection base on [MegEngine](https://github.com/MegEngine/MegEngine). 4 | 5 | ## Tutorial 6 | 7 | ### Step1: install requirements 8 | 9 | ``` 10 | python3 -m pip install megengine -f https://megengine.org.cn/whl/mge.html 11 | ``` 12 | 13 | ### Step2: convert checkpoint weights from torch's path file 14 | 15 | ``` 16 | python3 convert_weights.py -w yolox_s.pth -o yolox_s_mge.pkl 17 | ``` 18 | 19 | ### Step3: run demo 20 | 21 | This part is the same as torch's python demo, but no need to specify device. 22 | 23 | ``` 24 | python3 demo.py image -n yolox-s -c yolox_s_mge.pkl --path ../../../assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result 25 | ``` 26 | 27 | ### [Optional]Step4: dump model for cpp inference 28 | 29 | > **Note**: result model is dumped with `optimize_for_inference` and `enable_fuse_conv_bias_nonlinearity`. 30 | 31 | ``` 32 | python3 dump.py -n yolox-s -c yolox_s_mge.pkl --dump_path yolox_s.mge 33 | ``` 34 | -------------------------------------------------------------------------------- /demo/MegEngine/python/models/yolox.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- encoding: utf-8 -*- 3 | # Copyright (c) Megvii Inc. All rights reserved. 4 | 5 | import megengine.module as M 6 | 7 | from .yolo_head import YOLOXHead 8 | from .yolo_pafpn import YOLOPAFPN 9 | 10 | 11 | class YOLOX(M.Module): 12 | """ 13 | YOLOX model module. The module list is defined by create_yolov3_modules function. 14 | The network returns loss values from three YOLO layers during training 15 | and detection results during test. 16 | """ 17 | 18 | def __init__(self, backbone=None, head=None): 19 | super().__init__() 20 | if backbone is None: 21 | backbone = YOLOPAFPN() 22 | if head is None: 23 | head = YOLOXHead(80) 24 | 25 | self.backbone = backbone 26 | self.head = head 27 | 28 | def forward(self, x): 29 | # fpn output content features of [dark3, dark4, dark5] 30 | fpn_outs = self.backbone(x) 31 | assert not self.training 32 | outputs = self.head(fpn_outs) 33 | 34 | return outputs 35 | -------------------------------------------------------------------------------- /yolox/tools/__init__.py: -------------------------------------------------------------------------------- 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" 11 | 12 | if _TOOLS_PATH.is_dir(): 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."): 20 | return 21 | project_name = name.split(".")[-1] + ".py" 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()) 28 | -------------------------------------------------------------------------------- /yolox/exp/default/__init__.py: -------------------------------------------------------------------------------- 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 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" 12 | 13 | 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(abc.MetaPathFinder): 18 | 19 | def find_spec(self, name, path, target=None): 20 | if not name.startswith("yolox.exp.default"): 21 | return 22 | project_name = name.split(".")[-1] + ".py" 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()) 29 | -------------------------------------------------------------------------------- /exps/default/yolov3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | # Copyright (c) Megvii, Inc. and its affiliates. 4 | 5 | import os 6 | 7 | import torch.nn as nn 8 | 9 | from yolox.exp import Exp as MyExp 10 | 11 | 12 | class Exp(MyExp): 13 | def __init__(self): 14 | super(Exp, self).__init__() 15 | self.depth = 1.0 16 | self.width = 1.0 17 | self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] 18 | 19 | def get_model(self, sublinear=False): 20 | def init_yolo(M): 21 | for m in M.modules(): 22 | if isinstance(m, nn.BatchNorm2d): 23 | m.eps = 1e-3 24 | m.momentum = 0.03 25 | if "model" not in self.__dict__: 26 | from yolox.models import YOLOX, YOLOFPN, YOLOXHead 27 | backbone = YOLOFPN() 28 | head = YOLOXHead(self.num_classes, self.width, in_channels=[128, 256, 512], act="lrelu") 29 | self.model = YOLOX(backbone, head) 30 | self.model.apply(init_yolo) 31 | self.model.head.initialize_biases(1e-2) 32 | 33 | return self.model 34 | -------------------------------------------------------------------------------- /demo/ncnn/android/README.md: -------------------------------------------------------------------------------- 1 | # YOLOX-Android-ncnn 2 | 3 | Andoird app of YOLOX object detection base on [ncnn](https://github.com/Tencent/ncnn) 4 | 5 | 6 | ## Tutorial 7 | 8 | ### Step1 9 | 10 | Download ncnn-android-vulkan.zip from [releases of ncnn](https://github.com/Tencent/ncnn/releases). This repo uses 11 | [20210525 release](https://github.com/Tencent/ncnn/releases/download/20210525/ncnn-20210525-android-vulkan.zip) for building. 12 | 13 | ### Step2 14 | 15 | After downloading, please extract your zip file. Then, there are two ways to finish this step: 16 | * put your extracted directory into **app/src/main/jni** 17 | * change the **ncnn_DIR** path in **app/src/main/jni/CMakeLists.txt** to your extracted directory 18 | 19 | ### Step3 20 | Download example param and bin file from [onedrive](https://megvii-my.sharepoint.cn/:u:/g/personal/gezheng_megvii_com/ESXBH_GSSmFMszWJ6YG2VkQB5cWDfqVWXgk0D996jH0rpQ?e=qzEqUh) or [github](https://github.com/Megvii-BaseDetection/storage/releases/download/0.0.1/yolox_s_ncnn.tar.gz). Unzip the file to **app/src/main/assets**. 21 | 22 | ### Step4 23 | Open this project with Android Studio, build it and enjoy! 24 | 25 | ## Reference 26 | 27 | * [ncnn-android-yolov5](https://github.com/nihui/ncnn-android-yolov5) 28 | -------------------------------------------------------------------------------- /docs/freeze_module.md: -------------------------------------------------------------------------------- 1 | # Freeze module 2 | 3 | This page guide users to freeze module in YOLOX. 4 | Exp controls everything in YOLOX, so let's start from creating an Exp object. 5 | 6 | ## 1. Create your own expermiment object 7 | 8 | We take an example of YOLOX-S model on COCO dataset to give a more clear guide. 9 | 10 | Import the config you want (or write your own Exp object inherit from `yolox.exp.BaseExp`). 11 | ```python 12 | from yolox.exp.default.yolox_s import Exp as MyExp 13 | ``` 14 | 15 | ## 2. Override `get_model` method 16 | 17 | Here is a simple code to freeze backbone (FPN not included) of module. 18 | ```python 19 | class Exp(MyExp): 20 | 21 | def get_model(self): 22 | from yolox.utils import freeze_module 23 | model = super().get_model() 24 | freeze_module(model.backbone.backbone) 25 | return model 26 | ``` 27 | if you only want to freeze FPN, `freeze_module(model.backbone)` might help. 28 | 29 | ## 3. Train 30 | Suppose that the path of your Exp is `/path/to/my_exp.py`, use the following command to train your model. 31 | ```bash 32 | python3 -m yolox.tools.train -f /path/to/my_exp.py 33 | ``` 34 | For more details of training, run the following command. 35 | ```bash 36 | python3 -m yolox.tools.train --help 37 | ``` 38 | -------------------------------------------------------------------------------- /demo/TensorRT/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | project(yolox) 4 | 5 | add_definitions(-std=c++11) 6 | 7 | option(CUDA_USE_STATIC_CUDA_RUNTIME OFF) 8 | set(CMAKE_CXX_STANDARD 11) 9 | set(CMAKE_BUILD_TYPE Debug) 10 | 11 | find_package(CUDA REQUIRED) 12 | 13 | include_directories(${PROJECT_SOURCE_DIR}/include) 14 | # include and link dirs of cuda and tensorrt, you need adapt them if yours are different 15 | # cuda 16 | include_directories(/data/cuda/cuda-10.2/cuda/include) 17 | link_directories(/data/cuda/cuda-10.2/cuda/lib64) 18 | # cudnn 19 | include_directories(/data/cuda/cuda-10.2/cudnn/v8.0.4/include) 20 | link_directories(/data/cuda/cuda-10.2/cudnn/v8.0.4/lib64) 21 | # tensorrt 22 | include_directories(/data/cuda/cuda-10.2/TensorRT/v7.2.1.6/include) 23 | link_directories(/data/cuda/cuda-10.2/TensorRT/v7.2.1.6/lib) 24 | 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED") 26 | 27 | find_package(OpenCV) 28 | include_directories(${OpenCV_INCLUDE_DIRS}) 29 | 30 | add_executable(yolox ${PROJECT_SOURCE_DIR}/yolox.cpp) 31 | target_link_libraries(yolox nvinfer) 32 | target_link_libraries(yolox cudart) 33 | target_link_libraries(yolox ${OpenCV_LIBS}) 34 | 35 | add_definitions(-O2 -pthread) 36 | 37 | -------------------------------------------------------------------------------- /demo/ncnn/android/app/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 |