# YOLOX-CPP-MegEngine
Cpp file compile of YOLOX object detection base on [MegEngine](https://github.com/MegEngine/MegEngine).
## Tutorial
### Step1: install toolchain
* host: sudo apt install gcc/g++ (gcc/g++, which version >= 6) build-essential git git-lfs gfortran libgfortran-6-dev autoconf gnupg flex bison gperf curl zlib1g-dev gcc-multilib g++-multilib cmake
* cross build android: download [NDK](https://developer.android.com/ndk/downloads)
* after unzip download NDK, then export NDK_ROOT="path of NDK"
### Step2: build MegEngine
```shell
git clone https://github.com/MegEngine/MegEngine.git
# then init third_party
export megengine_root="path of MegEngine"
cd $megengine_root && ./third_party/prepare.sh && ./third_party/install-mkl.sh
# build example:
# build host without cuda:
./scripts/cmake-build/host_build.sh
# or build host with cuda:
./scripts/cmake-build/host_build.sh -c
# or cross build for android aarch64:
./scripts/cmake-build/cross_build_android_arm_inference.sh
# or cross build for android aarch64(with V8.2+fp16):
./scripts/cmake-build/cross_build_android_arm_inference.sh -f
# after build MegEngine, you need export the `MGE_INSTALL_PATH`
# host without cuda:
export MGE_INSTALL_PATH=${megengine_root}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_ON/Release/install
# or host with cuda:
export MGE_INSTALL_PATH=${megengine_root}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_ON/Release/install
# or cross build for android aarch64:
export MGE_INSTALL_PATH=${megengine_root}/build_dir/android/arm64-v8a/Release/install
```
* you can refs [build tutorial of MegEngine](https://github.com/MegEngine/MegEngine/blob/master/scripts/cmake-build/BUILD_README.md) to build other platform, eg, windows/macos/ etc!
### Step3: build OpenCV
```shell
git clone https://github.com/opencv/opencv.git
git checkout 3.4.15 (we test at 3.4.15, if test other version, may need modify some build)
```
- patch diff for android:
```
# ```
# diff --git a/CMakeLists.txt b/CMakeLists.txt
# index f6a2da5310..10354312c9 100644
# --- a/CMakeLists.txt
# +++ b/CMakeLists.txt
# @@ -643,7 +643,7 @@ if(UNIX)
# if(NOT APPLE)
# CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD)
# if(ANDROID)
# - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m log)
# + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m log z)
# elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD|NetBSD|DragonFly|OpenBSD|Haiku")
# set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} m pthread)
# elseif(EMSCRIPTEN)
# ```
```
- build for host
```shell
cd root_dir_of_opencv
mkdir -p build/install
cd build
cmake -DBUILD_JAVA=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$PWD/install
make install -j32
```
* build for android-aarch64
```shell
cd root_dir_of_opencv
mkdir -p build_android/install
cd build_android
cmake -DCMAKE_TOOLCHAIN_FILE="$NDK_ROOT/build/cmake/android.toolchain.cmake" -DANDROID_NDK="$NDK_ROOT" -DANDROID_ABI=arm64-v8a -DANDROID_NATIVE_API_LEVEL=21 -DBUILD_JAVA=OFF -DBUILD_ANDROID_PROJECTS=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$PWD/install ..
make install -j32
```
* after build OpenCV, you need export `OPENCV_INSTALL_INCLUDE_PATH ` and `OPENCV_INSTALL_LIB_PATH`
```shell
# host build:
export OPENCV_INSTALL_INCLUDE_PATH=${path of opencv}/build/install/include
export OPENCV_INSTALL_LIB_PATH=${path of opencv}/build/install/lib
# or cross build for android aarch64:
export OPENCV_INSTALL_INCLUDE_PATH=${path of opencv}/build_android/install/sdk/native/jni/include
export OPENCV_INSTALL_LIB_PATH=${path of opencv}/build_android/install/sdk/native/libs/arm64-v8a
```
### Step4: build test demo
```shell
run build.sh
# if host:
export CXX=g++
./build.sh
# or cross android aarch64
export CXX=aarch64-linux-android21-clang++
./build.sh
```
### Step5: run demo
> **Note**: two ways to get `yolox_s.mge` model file
>
> * reference to python demo's `dump.py` script.
> * wget https://github.com/Megvii-BaseDetection/storage/releases/download/0.0.1/yolox_s.mge
```shell
# if host:
LD_LIBRARY_PATH=$MGE_INSTALL_PATH/lib/:$OPENCV_INSTALL_LIB_PATH ./yolox yolox_s.mge ../../../assets/dog.jpg cuda/cpu/multithread <warmup_count> <thread_number>
# or cross android
adb push/scp $MGE_INSTALL_PATH/lib/libmegengine.so android_phone
adb push/scp $OPENCV_INSTALL_LIB_PATH/*.so android_phone
adb push/scp ./yolox yolox_s.mge android_phone
adb push/scp ../../../assets/dog.jpg android_phone
# login in android_phone by adb or ssh
# then run:
LD_LIBRARY_PATH=. ./yolox yolox_s.mge dog.jpg cpu/multithread <warmup_count> <thread_number> <use_fast_run> <use_weight_preprocess> <run_with_fp16>
# * <warmup_count> means warmup count, valid number >=0
# * <thread_number> means thread number, valid number >=1, only take effect `multithread` device
# * <use_fast_run> if >=1 , will use fastrun to choose best algo
# * <use_weight_preprocess> if >=1, will handle weight preprocess before exe
# * <run_with_fp16> if >=1, will run with fp16 mode
```
## Bechmark
* model info: yolox-s @ input(1,3,640,640)
* test devices
```
* x86_64 -- Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
* aarch64 -- xiamo phone mi9
* cuda -- 1080TI @ cuda-10.1-cudnn-v7.6.3-TensorRT-6.0.1.5.sh @ Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
```
| megengine @ tag1.4(fastrun + weight\_preprocess)/sec | 1 thread |
| ---------------------------------------------------- | -------- |
| x86\_64 | 0.516245 |
| aarch64(fp32+chw44) | 0.587857 |
| CUDA @ 1080TI/sec | 1 batch | 2 batch | 4 batch | 8 batch | 16 batch | 32 batch | 64 batch |
| ------------------- | ---------- | --------- | --------- | --------- | --------- | -------- | -------- |
| megengine(fp32+chw) | 0.00813703 | 0.0132893 | 0.0236633 | 0.0444699 | 0.0864917 | 0.16895 | 0.334248 |
## Acknowledgement
* [MegEngine](https://github.com/MegEngine/MegEngine)
* [OpenCV](https://github.com/opencv/opencv)
* [NDK](https://developer.android.com/ndk)
* [CMAKE](https://cmake.org/)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于YOLOX的旋转目标检测算法python源码+项目说明.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于YOLOX的旋转目标检测算法python源码+项目说明.zip (339个子文件)
gradlew.bat 2KB
maskApi.c 8KB
setup.cfg 615B
poly_nms.cpp 272KB
poly_overlaps.cpp 247KB
cocoeval.cpp 20KB
yolox_openvino.cpp 18KB
yolox.cpp 17KB
yolox.cpp 16KB
yoloXncnn_jni.cpp 14KB
yolox.cpp 13KB
gason.cpp 9KB
gasonMex.cpp 9KB
polyiou.cpp 4KB
vision.cpp 524B
custom.css 556B
poly_overlaps_kernel.cu 13KB
poly_nms_kernel.cu 11KB
polyiou_wrap.cxx 268KB
.gitattributes 66B
.gitignore 3KB
.gitignore 318B
.gitignore 6B
build.gradle 496B
build.gradle 335B
settings.gradle 15B
gradlew 5KB
logging.h 16KB
cocoeval.h 3KB
gason.h 3KB
maskApi.h 2KB
polyiou.h 202B
poly_nms.hpp 298B
poly_overlaps.hpp 106B
polyiou.i 258B
demo.ipynb 10.97MB
pycocoDemo.ipynb 1.71MB
pycocoEvalDemo.ipynb 4KB
gradle-wrapper.jar 53KB
MainActivity.java 8KB
yoloXncnn.java 566B
dog.jpg 160KB
instances_val2017.json 19.06MB
CocoApi.lua 10KB
MaskApi.lua 10KB
cocoDemo.lua 791B
init.lua 498B
env.lua 436B
CocoEval.m 22KB
CocoUtils.m 16KB
CocoApi.m 13KB
MaskApi.m 5KB
getPrmDflt.m 3KB
gason.m 2KB
evalDemo.m 2KB
cocoDemo.m 1KB
Makefile 629B
Makefile 199B
Makefile 56B
train_custom_data.md 7KB
README.md 6KB
megengine_cpp_readme.md 6KB
README.md 4KB
openvino_py_readme.md 4KB
openvino_cpp_readme.md 4KB
README.md 4KB
README.md 4KB
onnx_readme.md 4KB
README.md 3KB
README.md 3KB
ncnn_cpp_readme.md 3KB
quick_run.md 3KB
model_zoo.md 3KB
README.md 3KB
README.md 1KB
trt_py_readme.md 1KB
README.md 1KB
trt_cpp_readme.md 1KB
README.md 1KB
ncnn_android_readme.md 1KB
README.md 868B
megengine_py_readme.md 868B
README.md 767B
README.md 68B
gasonMex.mexa64 37KB
gasonMex.mexmaci64 40KB
yolox.param 17KB
P1088.png 5.03MB
P0770.png 4.03MB
P0706.png 2.62MB
P0053__1__0___397.png 2.49MB
P0551__1__0___354.png 2.14MB
P0086__1__133___0.png 2.12MB
P0622__1__0___0.png 2.11MB
P1506__1__2355___768.png 2.1MB
demo.png 2.09MB
P1854__1__9216___3072.png 2.09MB
P1478__1__768___0.png 2.08MB
P0199__1__0___555.png 2.05MB
P1960__1__460___0.png 2MB
共 339 条
- 1
- 2
- 3
- 4
资源评论
土豆片片
- 粉丝: 1802
- 资源: 5647
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功