From 83b11bc1ca7227497928a57b56653b76501b1368 Mon Sep 17 00:00:00 2001 From: lvhan028 Date: Wed, 3 Aug 2022 23:33:27 -0700 Subject: [PATCH] [Enhancement] Improve get_started documents and bump version to 0.7.0 (#813) * simplify commands in get_started * add installation commands for Windows * fix typo * limit markdown and sphinx_markdown_tables version * adopt html
tag * bump mmdeploy version * bump mmdeploy version * update get_started * update get_started * use python3.8 instead of python3.7 * remove duplicate section * resolve issue #856 * update according to review results * add reference to prebuilt_package_windows.md * fix error when build sdk demos --- CMakeLists.txt | 2 +- docker/CPU/Dockerfile | 7 +- docker/GPU/Dockerfile | 5 +- docs/en/01-how-to-build/android.md | 23 +- docs/en/01-how-to-build/jetsons.md | 12 +- docs/en/01-how-to-build/linux-x86_64.md | 16 +- docs/en/01-how-to-build/windows.md | 25 +- .../02-how-to-run/prebuilt_package_windows.md | 42 +-- docs/en/get_started.md | 323 ++++++++-------- docs/zh_cn/01-how-to-build/android.md | 23 +- docs/zh_cn/01-how-to-build/jetsons.md | 14 +- docs/zh_cn/01-how-to-build/linux-x86_64.md | 16 +- docs/zh_cn/01-how-to-build/windows.md | 25 +- .../02-how-to-run/prebuilt_package_windows.md | 42 +-- docs/zh_cn/get_started.md | 356 +++++++++--------- mmdeploy/version.py | 2 +- requirements/docs.txt | 4 +- .../packaging/mmdeploy_python/version.py | 2 +- 18 files changed, 419 insertions(+), 520 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 104cc36cd8..cfde11ec04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ endif () message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") cmake_minimum_required(VERSION 3.14) -project(MMDeploy VERSION 0.6.0) +project(MMDeploy VERSION 0.7.0) set(CMAKE_CXX_STANDARD 17) diff --git a/docker/CPU/Dockerfile b/docker/CPU/Dockerfile index 1734256c50..f076f26e95 100644 --- a/docker/CPU/Dockerfile +++ b/docker/CPU/Dockerfile @@ -93,6 +93,7 @@ RUN git clone https://github.com/open-mmlab/mmdeploy.git &&\ ENV LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:/opt/intel/openvino/deployment_tools/ngraph/lib:/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64:${LD_LIBRARY_PATH}" RUN cd mmdeploy && rm -rf build/CM* && mkdir -p build && cd build && cmake .. \ -DMMDEPLOY_BUILD_SDK=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DCMAKE_CXX_COMPILER=g++-7 \ -DONNXRUNTIME_DIR=${ONNXRUNTIME_DIR} \ -Dncnn_DIR=/root/workspace/ncnn/build/install/lib/cmake/ncnn \ @@ -102,9 +103,5 @@ RUN cd mmdeploy && rm -rf build/CM* && mkdir -p build && cd build && cmake .. \ -DMMDEPLOY_TARGET_BACKENDS="ort;ncnn;openvino" \ -DMMDEPLOY_CODEBASES=all &&\ cmake --build . -- -j$(nproc) && cmake --install . &&\ - cd install/example && mkdir -p build && cd build &&\ - cmake .. -DMMDeploy_DIR=/root/workspace/mmdeploy/build/install/lib/cmake/MMDeploy \ - -DInferenceEngine_DIR=/opt/intel/openvino/deployment_tools/inference_engine/share \ - -Dncnn_DIR=/root/workspace/ncnn/build/install/lib/cmake/ncnn &&\ - cmake --build . && export SPDLOG_LEVEL=warn &&\ + export SPDLOG_LEVEL=warn &&\ if [ -z ${VERSION} ] ; then echo "Built MMDeploy master for CPU devices successfully!" ; else echo "Built MMDeploy version v${VERSION} for CPU devices successfully!" ; fi diff --git a/docker/GPU/Dockerfile b/docker/GPU/Dockerfile index c16845254f..fa93192896 100644 --- a/docker/GPU/Dockerfile +++ b/docker/GPU/Dockerfile @@ -79,6 +79,7 @@ RUN cd /root/workspace/mmdeploy &&\ mkdir -p build && cd build &&\ cmake .. \ -DMMDEPLOY_BUILD_SDK=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DCMAKE_CXX_COMPILER=g++ \ -Dpplcv_DIR=/root/workspace/ppl.cv/cuda-build/install/lib/cmake/ppl \ -DTENSORRT_DIR=${TENSORRT_DIR} \ @@ -88,9 +89,7 @@ RUN cd /root/workspace/mmdeploy &&\ -DMMDEPLOY_TARGET_BACKENDS="ort;trt" \ -DMMDEPLOY_CODEBASES=all &&\ make -j$(nproc) && make install &&\ - cd install/example && mkdir -p build && cd build &&\ - cmake -DMMDeploy_DIR=/root/workspace/mmdeploy/build/install/lib/cmake/MMDeploy .. &&\ - make -j$(nproc) && export SPDLOG_LEVEL=warn &&\ + export SPDLOG_LEVEL=warn &&\ if [ -z ${VERSION} ] ; then echo "Built MMDeploy master for GPU devices successfully!" ; else echo "Built MMDeploy version v${VERSION} for GPU devices successfully!" ; fi ENV LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:${BACKUP_LD_LIBRARY_PATH}" diff --git a/docs/en/01-how-to-build/android.md b/docs/en/01-how-to-build/android.md index cf2c0f5ae7..0285f9cf27 100644 --- a/docs/en/01-how-to-build/android.md +++ b/docs/en/01-how-to-build/android.md @@ -7,8 +7,7 @@ - [Install Dependencies for SDK](#install-dependencies-for-sdk) - [Build MMDeploy](#build-mmdeploy) - [Build Options Spec](#build-options-spec) - - [Build SDK](#build-sdk) - - [Build Demo](#build-demo) + - [Build SDK and Demos](#build-sdk-and-demos) ______________________________________________________________________ @@ -174,7 +173,7 @@ make -j$(nproc) install -#### Build SDK +#### Build SDK and Demos MMDeploy provides a recipe as shown below for building SDK with ncnn as inference engine for android. @@ -186,6 +185,7 @@ MMDeploy provides a recipe as shown below for building SDK with ncnn as inferenc cmake .. \ -DMMDEPLOY_BUILD_SDK=ON \ -DMMDEPLOY_BUILD_SDK_JAVA_API=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DOpenCV_DIR=${OPENCV_ANDROID_SDK_DIR}/sdk/native/jni/abi-${ANDROID_ABI} \ -Dncnn_DIR=${NCNN_DIR}/build_${ANDROID_ABI}/install/lib/cmake/ncnn \ -DMMDEPLOY_TARGET_BACKENDS=ncnn \ @@ -198,20 +198,3 @@ MMDeploy provides a recipe as shown below for building SDK with ncnn as inferenc make -j$(nproc) && make install ``` - -#### Build Demo - -```Bash -export ANDROID_ABI=arm64-v8a - -cd ${MMDEPLOY_DIR}/build_${ANDROID_ABI}/install/example -mkdir -p build && cd build -cmake .. \ - -DOpenCV_DIR=${OPENCV_ANDROID_SDK_DIR}/sdk/native/jni/abi-${ANDROID_ABI} \ - -Dncnn_DIR=${NCNN_DIR}/build_${ANDROID_ABI}/install/lib/cmake/ncnn \ - -DMMDeploy_DIR=${MMDEPLOY_DIR}/build_${ANDROID_ABI}/install/lib/cmake/MMDeploy \ - -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI=${ANDROID_ABI} \ - -DANDROID_PLATFORM=android-30 -make -j$(nproc) -``` diff --git a/docs/en/01-how-to-build/jetsons.md b/docs/en/01-how-to-build/jetsons.md index 60b0173ea0..2accf7534a 100644 --- a/docs/en/01-how-to-build/jetsons.md +++ b/docs/en/01-how-to-build/jetsons.md @@ -251,13 +251,14 @@ It takes about 5 minutes to install model converter on a Jetson Nano. So, please ### Install C/C++ Inference SDK -1. Build SDK Libraries +Build SDK Libraries and its demo as below: ```shell mkdir -p build && cd build cmake .. \ -DMMDEPLOY_BUILD_SDK=ON \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \ -DMMDEPLOY_TARGET_BACKENDS="trt" \ -DMMDEPLOY_CODEBASES=all \ @@ -269,15 +270,6 @@ make -j$(nproc) && make install It takes about 9 minutes to build SDK libraries on a Jetson Nano. So, please be patient until the installation is complete. ``` -2. Build SDK demos - -```shell -cd ${MMDEPLOY_DIR}/build/install/example -mkdir -p build && cd build -cmake .. -DMMDeploy_DIR=${MMDEPLOY_DIR}/build/install/lib/cmake/MMDeploy -make -j$(nproc) -``` - ### Run a Demo #### Object Detection demo diff --git a/docs/en/01-how-to-build/linux-x86_64.md b/docs/en/01-how-to-build/linux-x86_64.md index bdcc684c09..126a192427 100644 --- a/docs/en/01-how-to-build/linux-x86_64.md +++ b/docs/en/01-how-to-build/linux-x86_64.md @@ -11,8 +11,7 @@ - [Build Model Converter](#build-model-converter) - [Build Custom Ops](#build-custom-ops) - [Install Model Converter](#install-model-converter) - - [Build SDK](#build-sdk) - - [Build Demo](#build-demo) + - [Build SDK and Demo](#build-sdk-and-demo) ______________________________________________________________________ @@ -395,7 +394,7 @@ pip install -e . To use optional dependencies, install them manually with `pip install -r requirements/optional.txt` or specify desired extras when calling `pip` (e.g. `pip install -e .[optional]`). Valid keys for the extras field are: `all`, `tests`, `build`, `optional`. -### Build SDK +### Build SDK and Demo MMDeploy provides two recipes as shown below for building SDK with ONNXRuntime and TensorRT as inference engines respectively. You can also activate other engines after the model. @@ -409,6 +408,7 @@ You can also activate other engines after the model. -DCMAKE_CXX_COMPILER=g++-7 \ -DMMDEPLOY_BUILD_SDK=ON \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_TARGET_DEVICES=cpu \ -DMMDEPLOY_TARGET_BACKENDS=ort \ -DMMDEPLOY_CODEBASES=all \ @@ -426,6 +426,7 @@ You can also activate other engines after the model. -DCMAKE_CXX_COMPILER=g++-7 \ -DMMDEPLOY_BUILD_SDK=ON \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \ -DMMDEPLOY_TARGET_BACKENDS=trt \ -DMMDEPLOY_CODEBASES=all \ @@ -435,12 +436,3 @@ You can also activate other engines after the model. make -j$(nproc) && make install ``` - -### Build Demo - -```Bash -cd ${MMDEPLOY_DIR}/build/install/example -mkdir -p build && cd build -cmake .. -DMMDeploy_DIR=${MMDEPLOY_DIR}/build/install/lib/cmake/MMDeploy -make -j$(nproc) -``` diff --git a/docs/en/01-how-to-build/windows.md b/docs/en/01-how-to-build/windows.md index 8df92127c0..5154fc328b 100644 --- a/docs/en/01-how-to-build/windows.md +++ b/docs/en/01-how-to-build/windows.md @@ -12,14 +12,11 @@ - [Build Model Converter](#build-model-converter) - [Build Custom Ops](#build-custom-ops) - [Install Model Converter](#install-model-converter) - - [Build SDK](#build-sdk) - - [Build Demo](#build-demo) + - [Build SDK and Demos](#build-sdk-and-demos) - [Note](#note) ______________________________________________________________________ -Currently, MMDeploy only provides build-from-source method for windows platform. Prebuilt package will be released in the future. - ## Build From Source All the commands listed in the following chapters are verified on **Windows 10**. @@ -315,7 +312,7 @@ pip install -e . To use optional dependencies, install them manually with `pip install -r requirements/optional.txt` or specify desired extras when calling `pip` (e.g. `pip install -e .[optional]`). Valid keys for the extras field are: `all`, `tests`, `build`, `optional`. -#### Build SDK +#### Build SDK and Demos MMDeploy provides two recipes as shown below for building SDK with ONNXRuntime and TensorRT as inference engines respectively. You can also activate other engines after the model. @@ -328,6 +325,8 @@ You can also activate other engines after the model. cd build cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` -DMMDEPLOY_BUILD_SDK=ON ` + -DMMDEPLOY_BUILD_EXAMPLES=ON ` + -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON ` -DMMDEPLOY_TARGET_DEVICES="cpu" ` -DMMDEPLOY_TARGET_BACKENDS="ort" ` -DMMDEPLOY_CODEBASES="all" ` @@ -345,6 +344,8 @@ You can also activate other engines after the model. cd build cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` -DMMDEPLOY_BUILD_SDK=ON ` + -DMMDEPLOY_BUILD_EXAMPLES=ON ` + -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON ` -DMMDEPLOY_TARGET_DEVICES="cuda" ` -DMMDEPLOY_TARGET_BACKENDS="trt" ` -DMMDEPLOY_CODEBASES="all" ` @@ -356,20 +357,6 @@ You can also activate other engines after the model. cmake --install . --config Release ``` -#### Build Demo - -```PowerShell -cd $env:MMDEPLOY_DIR\build\install\example -mkdir build -ErrorAction SilentlyContinue -cd build -cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` - -DMMDeploy_DIR="$env:MMDEPLOY_DIR/build/install/lib/cmake/MMDeploy" - -cmake --build . --config Release -- /m - -$env:path = "$env:MMDEPLOY_DIR/build/install/bin;" + $env:path -``` - ### Note 1. Release / Debug libraries can not be mixed. If MMDeploy is built with Release mode, all its dependent thirdparty libraries have to be built in Release mode too and vice versa. diff --git a/docs/en/02-how-to-run/prebuilt_package_windows.md b/docs/en/02-how-to-run/prebuilt_package_windows.md index f14f17889b..30ad795a14 100644 --- a/docs/en/02-how-to-run/prebuilt_package_windows.md +++ b/docs/en/02-how-to-run/prebuilt_package_windows.md @@ -21,7 +21,7 @@ ______________________________________________________________________ -This tutorial takes `mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1.zip` and `mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip` as examples to show how to use the prebuilt packages. +This tutorial takes `mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1.zip` and `mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip` as examples to show how to use the prebuilt packages. The directory structure of the prebuilt package is as follows, where the `dist` folder is about model converter, and the `sdk` folder is related to model inference. @@ -80,9 +80,9 @@ In order to use `ONNX Runtime` backend, you should also do the following steps. 5. Install `mmdeploy` (Model Converter) and `mmdeploy_python` (SDK Python API). ```bash - # download mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1.zip - pip install .\mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\dist\mmdeploy-0.6.0-py38-none-win_amd64.whl - pip install .\mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\python\mmdeploy_python-0.6.0-cp38-none-win_amd64.whl + # download mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1.zip + pip install .\mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\dist\mmdeploy-0.7.0-py38-none-win_amd64.whl + pip install .\mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\python\mmdeploy_python-0.7.0-cp38-none-win_amd64.whl ``` :point_right: If you have installed it before, please uninstall it first. @@ -107,9 +107,9 @@ In order to use `TensorRT` backend, you should also do the following steps. 5. Install `mmdeploy` (Model Converter) and `mmdeploy_python` (SDK Python API). ```bash - # download mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip - pip install .\mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\dist\mmdeploy-0.6.0-py38-none-win_amd64.whl - pip install .\mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\python\mmdeploy_python-0.6.0-cp38-none-win_amd64.whl + # download mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip + pip install .\mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\dist\mmdeploy-0.7.0-py38-none-win_amd64.whl + pip install .\mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\python\mmdeploy_python-0.7.0-cp38-none-win_amd64.whl ``` :point_right: If you have installed it before, please uninstall it first. @@ -138,7 +138,7 @@ After preparation work, the structure of the current working directory should be ``` .. -|-- mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1 +|-- mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1 |-- mmclassification |-- mmdeploy `-- resnet18_8xb32_in1k_20210831-fbbb1da6.pth @@ -186,7 +186,7 @@ After installation of mmdeploy-tensorrt prebuilt package, the structure of the c ``` .. -|-- mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 +|-- mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 |-- mmclassification |-- mmdeploy `-- resnet18_8xb32_in1k_20210831-fbbb1da6.pth @@ -249,8 +249,8 @@ The structure of current working directory: ``` . -|-- mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 -|-- mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1 +|-- mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 +|-- mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1 |-- mmclassification |-- mmdeploy |-- resnet18_8xb32_in1k_20210831-fbbb1da6.pth @@ -294,13 +294,13 @@ The following describes how to use the SDK's Python API for inference #### ONNXRuntime ```bash -python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\mmclassification\demo\demo.JPEG +python .\mmdeploy\demo\python\image_classification.py cpu .\work_dir\onnx\resnet\ .\mmclassification\demo\demo.JPEG ``` #### TensorRT ``` - python .\mmdeploy\demo\python\image_classification.py .\work_dir\trt\resnet\ .\mmclassification\demo\demo.JPEG --device-name cuda + python .\mmdeploy\demo\python\image_classification.py cuda .\work_dir\trt\resnet\ .\mmclassification\demo\demo.JPEG ``` ### C SDK @@ -311,7 +311,7 @@ The following describes how to use the SDK's C API for inference 1. Build examples - Under `mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\example` directory + Under `mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\example` directory ``` // Path should be modified according to the actual location @@ -319,7 +319,7 @@ The following describes how to use the SDK's C API for inference cd build cmake .. -A x64 -T v142 ` -DOpenCV_DIR=C:\Deps\opencv\build\x64\vc15\lib ` - -DMMDeploy_DIR=C:\workspace\mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\lib\cmake\MMDeploy ` + -DMMDeploy_DIR=C:\workspace\mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\lib\cmake\MMDeploy ` -DONNXRUNTIME_DIR=C:\Deps\onnxruntime\onnxruntime-win-gpu-x64-1.8.1 cmake --build . --config Release @@ -329,7 +329,7 @@ The following describes how to use the SDK's C API for inference :point_right: The purpose is to make the exe find the relevant dll - If choose to add environment variables, add the runtime libraries path of `mmdeploy` (`mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\bin`) to the `PATH`. + If choose to add environment variables, add the runtime libraries path of `mmdeploy` (`mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\bin`) to the `PATH`. If choose to copy the dynamic libraries, copy the dll in the bin directory to the same level directory of the just compiled exe (build/Release). @@ -337,7 +337,7 @@ The following describes how to use the SDK's C API for inference It is recommended to use `CMD` here. - Under `mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\\sdk\\example\\build\\Release` directory: + Under `mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\\sdk\\example\\build\\Release` directory: ``` .\image_classification.exe cpu C:\workspace\work_dir\onnx\resnet\ C:\workspace\mmclassification\demo\demo.JPEG @@ -347,7 +347,7 @@ The following describes how to use the SDK's C API for inference 1. Build examples - Under `mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example` directory + Under `mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example` directory ``` // Path should be modified according to the actual location @@ -355,7 +355,7 @@ The following describes how to use the SDK's C API for inference cd build cmake .. -A x64 -T v142 ` -DOpenCV_DIR=C:\Deps\opencv\build\x64\vc15\lib ` - -DMMDeploy_DIR=C:\workspace\mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8 2.3.0\sdk\lib\cmake\MMDeploy ` + -DMMDeploy_DIR=C:\workspace\mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8 2.3.0\sdk\lib\cmake\MMDeploy ` -DTENSORRT_DIR=C:\Deps\tensorrt\TensorRT-8.2.3.0 ` -DCUDNN_DIR=C:\Deps\cudnn\8.2.1 cmake --build . --config Release @@ -365,7 +365,7 @@ The following describes how to use the SDK's C API for inference :point_right: The purpose is to make the exe find the relevant dll - If choose to add environment variables, add the runtime libraries path of `mmdeploy` (`mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\bin`) to the `PATH`. + If choose to add environment variables, add the runtime libraries path of `mmdeploy` (`mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\bin`) to the `PATH`. If choose to copy the dynamic libraries, copy the dll in the bin directory to the same level directory of the just compiled exe (build/Release). @@ -373,7 +373,7 @@ The following describes how to use the SDK's C API for inference It is recommended to use `CMD` here. - Under `mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example\\build\\Release` directory + Under `mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example\\build\\Release` directory ``` .\image_classification.exe cuda C:\workspace\work_dir\trt\resnet C:\workspace\mmclassification\demo\demo.JPEG diff --git a/docs/en/get_started.md b/docs/en/get_started.md index 77375deadb..e5a004c5c9 100644 --- a/docs/en/get_started.md +++ b/docs/en/get_started.md @@ -4,8 +4,6 @@ MMDeploy provides useful tools for deploying OpenMMLab models to various platfor With the help of them, you can not only do model deployment using our pre-defined pipelines but also customize your own deployment pipeline. -In the following chapters, we will describe the general routine and demonstrate a "hello-world" example - deploying Faster R-CNN model from [MMDetection](https://github.com/open-mmlab/mmdetection) to NVIDIA TensorRT. - ## Introduction In MMDeploy, the deployment pipeline can be illustrated by a sequential modules, i.e., Model Converter, MMDeploy Model and Inference SDK. @@ -36,8 +34,7 @@ In order to do an end-to-end model deployment, MMDeploy requires Python 3.6+ and **Step 1.** Create a conda environment and activate it. ```shell -export PYTHON_VERSION=3.7 -conda create --name mmdeploy python=${PYTHON_VERSION} -y +conda create --name mmdeploy python=3.8 -y conda activate mmdeploy ``` @@ -46,18 +43,17 @@ conda activate mmdeploy On GPU platforms: ```shell - export PYTORCH_VERSION=1.8.0 - export TORCHVISION_VERSION=0.9.0 - export CUDA_VERSION=11.1 - conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cudatoolkit=${CUDA_VERSION} -c pytorch -c conda-forge +conda install pytorch=={pytorch_version} torchvision=={torchvision_version} cudatoolkit={cudatoolkit_version} -c pytorch -c conda-forge ``` On CPU platforms: ```shell -export PYTORCH_VERSION=1.8.0 -export TORCHVISION_VERSION=0.9.0 -conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cpuonly -c pytorch +conda install pytorch=={pytorch_version} torchvision=={torchvision_version} cpuonly -c pytorch +``` + +```{note} +On GPU platform, please ensure that {cudatoolkit_version} matches your host CUDA toolkit version. Otherwise, it probably brings in conflicts when deploying model with TensorRT. ``` ## Installation @@ -67,125 +63,150 @@ We recommend that users follow our best practices installing MMDeploy. **Step 0.** Install [MMCV](https://github.com/open-mmlab/mmcv). ```shell - export MMCV_VERSION=1.5.0 - export CUDA_STRING="${CUDA_VERSION/./""}" - python -m pip install mmcv-full==${MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/cu${CUDA_STRING}/torch${PYTORCH_VERSION}/index.html +pip install -U openmim +mim install mmcv-full ``` -**Step 1.** Install MMDeploy. - -Since v0.5.0, MMDeploy provides prebuilt packages, which can be found from [here](https://github.com/open-mmlab/mmdeploy/releases). -You can download them according to your target platform and device. - -Take the MMDeploy-TensorRT package on NVIDIA for example: +**Step 1.** Install MMDeploy and inference engine + +We recommend using MMDeploy precompiled package as our best practice. +You can download them from [here](https://github.com/open-mmlab/mmdeploy/releases) according to your target platform and device. + +The supported platform and device matrix is presented as following: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OS-ArchDeviceONNX RuntimeTensorRT
Linux-x86_64CPUYN/A
CUDANY
Windows-x86_64CPUYN/A
CUDANY
+ +**Note: if MMDeploy prebuilt package doesn't meet your target platforms or devices, please [build MMDeploy from source](./01-how-to-build/build_from_source.md)** + +Take the latest precompiled package as example, you can install it as follows: + +
+Linux-x86_64, CPU, ONNX Runtime 1.8.1 ```shell -export MMDEPLOY_VERSION=0.5.0 -export TENSORRT_VERSION=8.2.3.0 -export PYTHON_VERSION=3.7 -export PYTHON_STRING="${PYTHON_VERSION/./""}" - -wget https://github.com/open-mmlab/mmdeploy/releases/download/v${MMDEPLOY_VERSION}/mmdeploy-${MMDEPLOY_VERSION}-linux-x86_64-cuda${CUDA_VERSION}-tensorrt${TENSORRT_VERSION}.tar.gz -tar -zxvf mmdeploy-${MMDEPLOY_VERSION}-linux-x86_64-cuda${CUDA_VERSION}-tensorrt${TENSORRT_VERSION}.tar.gz -cd mmdeploy-${MMDEPLOY_VERSION}-linux-x86_64-cuda${CUDA_VERSION}-tensorrt${TENSORRT_VERSION} -python -m pip install dist/mmdeploy-*-py${PYTHON_STRING}*.whl -python -m pip install sdk/python/mmdeploy_python-*-cp${PYTHON_STRING}*.whl -export LD_LIBRARY_PATH=$(pwd)/sdk/lib:$LD_LIBRARY_PATH +# install MMDeploy +wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.7.0/mmdeploy-0.7.0-linux-x86_64-onnxruntime1.8.1.tar.gz +tar -zxvf mmdeploy-0.7.0-linux-x86_64-onnxruntime1.8.1.tar.gz +cd mmdeploy-0.7.0-linux-x86_64-onnxruntime1.8.1 +pip install dist/mmdeploy-0.7.0-py3-none-linux_x86_64.whl +pip install sdk/python/mmdeploy_python-0.7.0-cp38-none-linux_x86_64.whl cd .. +# install inference engine: ONNX Runtime +pip install onnxruntime==1.8.1 +wget https://github.com/microsoft/onnxruntime/releases/download/v1.8.1/onnxruntime-linux-x64-1.8.1.tgz +tar -zxvf onnxruntime-linux-x64-1.8.1.tgz +export ONNXRUNTIME_DIR=$(pwd)/onnxruntime-linux-x64-1.8.1 +export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH ``` -```{note} -If MMDeploy prebuilt package doesn meet your target platforms or devices, please build MMDeploy from its source by following the build documents -``` - -**step 2.** Install the inference backend +
-Based on the above MMDeploy-TensorRT package, we need to download and install [TensorRT](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-tar), including [cuDNN](https://developer.nvidia.com/cudnn). - -**Be aware that TensorRT version and cuDNN version must matches your CUDA Toolkit version** - -The following shows an example of installing TensorRT 8.2.3.0 and cuDNN 8.2: +
+Linux-x86_64, CUDA 11.x, TensorRT 8.2.3.0 ```shell -export TENSORRT_VERSION=8.2.3.0 -CUDA_MAJOR="${CUDA_VERSION/\.*/""}" - -# !!! Download tensorrt package from NVIDIA that matches your CUDA Toolkit version to the current working directory -tar -zxvf TensorRT-${TENSORRT_VERSION}*cuda-${CUDA_MAJOR}*.tar.gz -python -m pip install TensorRT-${TENSORRT_VERSION}/python/tensorrt-*-cp${PYTHON_STRING}*.whl -python -m pip install pycuda -export TENSORRT_DIR=$(pwd)/TensorRT-${TENSORRT_VERSION} +# install MMDeploy +wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.7.0/mmdeploy-0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0.tar.gz +tar -zxvf mmdeploy-v0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0.tar.gz +cd mmdeploy-0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0 +pip install dist/mmdeploy-0.7.0-py3-none-linux_x86_64.whl +pip install sdk/python/mmdeploy_python-0.7.0-cp38-none-linux_x86_64.whl +cd .. +# install inference engine: TensorRT +# !!! Download TensorRT-8.2.3.0 CUDA 11.x tar package from NVIDIA, and extract it to the current directory +pip install TensorRT-8.2.3.0/python/tensorrt-8.2.3.0-cp38-none-linux_x86_64.whl +pip install pycuda +export TENSORRT_DIR=$(pwd)/TensorRT-8.2.3.0 export LD_LIBRARY_PATH=${TENSORRT_DIR}/lib:$LD_LIBRARY_PATH - -# !!! Download cuDNN package from NVIDIA that matches your CUDA Toolkit and TensorRT version to the current working directory -tar -zxvf cudnn-${CUDA_MAJOR}.*-linux-x64*.tgz +# !!! Download cuDNN 8.2.1 CUDA 11.x tar package from NVIDIA, and extract it to the current directory export CUDNN_DIR=$(pwd)/cuda export LD_LIBRARY_PATH=$CUDNN_DIR/lib64:$LD_LIBRARY_PATH ``` -In the next chapters, we are going to present our 'Hello, world' example based on the above settings. +
-For the installation of all inference backends supported by MMDeploy right now, please refer to: +
+Windows-x86_64 +
-- [ONNX Runtime](05-supported-backends/onnxruntime.md) -- [TensorRT](05-supported-backends/tensorrt.md) -- [PPL.NN](05-supported-backends/pplnn.md) -- [ncnn](05-supported-backends/ncnn.md) -- [OpenVINO](05-supported-backends/openvino.md) -- [LibTorch](05-supported-backends/torchscript.md) +Please learn its prebuilt package from [this](./02-how-to-run/prebuilt_package_windows.md) guide. ## Convert Model -After the installation, you can enjoy the model deployment journey starting from converting PyTorch model to backend model. +After the installation, you can enjoy the model deployment journey starting from converting PyTorch model to backend model by running `tools/deploy.py`. Based on the above settings, we provide an example to convert the Faster R-CNN in [MMDetection](https://github.com/open-mmlab/mmdetection) to TensorRT as below: ```shell -# clone mmdeploy repo. We are going to use the pre-defined pipeline config from the source code -git clone --recursive https://github.com/open-mmlab/mmdeploy.git -python -m pip install -r mmdeploy/requirements/runtime.txt -export MMDEPLOY_DIR=$(pwd)/mmdeploy +# clone mmdeploy to get the deployment config. `--recursive` is not necessary +git clone https://github.com/open-mmlab/mmdeploy.git # clone mmdetection repo. We have to use the config file to build PyTorch nn module -python -m pip install mmdet==2.24.0 git clone https://github.com/open-mmlab/mmdetection.git -export MMDET_DIR=$(pwd)/mmdetection +cd mmdetection +pip install -v -e . +cd .. # download Faster R-CNN checkpoint -export CHECKPOINT_DIR=$(pwd)/checkpoints -wget -P ${CHECKPOINT_DIR} https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth - -# set working directory, where the mmdeploy model is saved -export WORK_DIR=$(pwd)/mmdeploy_models +wget -P checkpoints https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth # run the command to start model conversion -python ${MMDEPLOY_DIR}/tools/deploy.py \ - ${MMDEPLOY_DIR}/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ - ${MMDET_DIR}/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ - ${CHECKPOINT_DIR}/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ - ${MMDET_DIR}/demo/demo.jpg \ - --work-dir ${WORK_DIR} \ - --device cuda:0 \ +python mmdeploy/tools/deploy.py \ + mmdeploy/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ + mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ + checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ + mmdetection/demo/demo.jpg \ + --work-dir mmdeploy_model/faster-rcnn \ + --device cuda \ --dump-info ``` -`${MMDEPLOY_DIR}/tools/deploy.py` does everything you need to convert a model. Read [how_to_convert_model](./02-how-to-run/convert_model.md) for more details. The converted model and its meta info will be found in the path specified by `--work-dir`. And they make up of MMDeploy Model that can be fed to MMDeploy SDK to do model inference. -`detection_tensorrt_dynamic-320x320-1344x1344.py` is a config file that contains all arguments you need to customize the conversion pipeline. The name is formed as: +For more details about model conversion, you can read [how_to_convert_model](./02-how-to-run/convert_model.md). If you want to customize the conversion pipeline, you can edit the config file by following [this](./02-how-to-run/write_config.md) tutorial. -```bash -_-[backend options]_.py +```{tip} +If MMDeploy-ONNXRuntime prebuild package is installed, you can convert the above model to onnx model and perform ONNX Runtime inference +just by 'changing detection_tensorrt_dynamic-320x320-1344x1344.py' to 'detection_onnxruntime_dynamic.py' and making '--device' as 'cpu'. ``` -If you want to customize the conversion pipeline, you can edit the config file by following [this](./02-how-to-run/write_config.md) tutorial. - ## Inference Model -After model conversion, we can perform inference both by Model Converter and Inference SDK. - -The former is developed by Python, while the latter is mainly written by C/C++. +After model conversion, we can perform inference not only by Model Converter but also by Inference SDK. ### Inference by Model Converter @@ -194,43 +215,50 @@ Take the previous converted Faster R-CNN tensorrt model for example, ```python from mmdeploy.apis import inference_model -import os - -model_cfg = os.getenv('MMDET_DIR') + '/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' -deploy_cfg = os.getenv('MMDEPLOY_DIR') + '/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py' -backend_files = [os.getenv('WORK_DIR') + '/end2end.engine'] - -result = inference_model(model_cfg, deploy_cfg, backend_files, img=img, device=device) +result = inference_model( + model_cfg='mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', + deploy_cfg='mmdeploy/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py', + backend_files=['mmdeploy_model/faster-rcnn/end2end.engine'], + img='mmdetection/demo/demo.jpg', + device='cuda:0') ``` -The data type and data layout is exactly the same with the OpenMMLab PyTorch model inference results. - ```{note} -You can certainly use the infernce backend API directly to do inference. But since MMDeploy has being developed several custom operators, it's necessary to load them first before calling the infernce backend API. +'backend_files' in this API refers to backend engine file path, which MUST be put in a list, since some inference engines like OpenVINO and ncnn separate the network structure and its weights into two files. ``` ### Inference by SDK -You can use SDK API to do model inference with the mmdeploy model generated by Model Converter. +You can directly run MMDeploy demo programs in the precompiled package to get inference results. + +```shell +cd mmdeploy-0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0 +# run python demo +python sdk/example/python/object_detection.py cuda ../mmdeploy_model/faster-rcnn ../mmdetection/demo/demo.jpg +# run C/C++ demo +export LD_LIBRARY_PATH=$(pwd)/sdk/lib:$LD_LIBRARY_PATH +./sdk/bin/object_detection cuda ../mmdeploy_model/faster-rcnn ../mmdetection/demo/demo.jpg +``` + +```{note} +In the above command, the input model is SDK Model path. It is NOT engine file path but actually the path passed to --work-dir. It not only includes engine files but also meta information like 'deploy.json' and 'pipeline.json'. +``` -In the following section, we will provide examples of deploying the converted Faster R-CNN model talked above with different FFI. +In the next section, we will provide examples of deploying the converted Faster R-CNN model talked above with SDK different FFI (Foreign Function Interface). #### Python API ```python from mmdeploy_python import Detector -import os import cv2 -# get mmdeploy model path of faster r-cnn -model_path = os.getenv('WORK_DIR') -# use mmdetection demo image as an input image -image_path = '/'.join((os.getenv('MMDET_DIR'), 'demo/demo.jpg')) - -img = cv2.imread(image_path) -detector = Detector(model_path, 'cuda', 0) -bboxes, labels, _ = detector([img])[0] +img = cv2.imread('mmdetection/demo/demo.jpg') +# create a detector +detector = Detector(model_path='mmdeploy_models/faster-rcnn', device_name='cuda', device_id=0) +# run the inference +bboxes, labels, _ = detector(img) +# Filter the result according to threshold indices = [i for i in range(len(bboxes))] for index, bbox, label_id in zip(indices, bboxes, labels): [left, top, right, bottom], score = bbox[0:4].astype(int), bbox[4] @@ -243,73 +271,45 @@ cv2.imwrite('output_detection.png', img) You can find more examples from [here](https://github.com/open-mmlab/mmdeploy/tree/master/demo/python). -```{note} -If you build MMDeploy from source, please add ${MMDEPLOY_DIR}/build/lib to the environment variable PYTHONPATH. -Otherwise, you will run into an error like ’ModuleNotFoundError: No module named 'mmdeploy_python' -``` +#### C++ API -#### C API +Using SDK C++ API should follow next pattern, -Using SDK C API should follow next pattern, - -```{mermaid} -graph LR - A[create inference handle] --> B(read image) - B --> C(apply handle) - C --> D[deal with inference result] - D -->E[destroy result buffer] - E -->F[destroy handle] -``` +![image](https://user-images.githubusercontent.com/4560679/182554739-7fff57fc-5c84-44ed-b139-4749fae27404.png) Now let's apply this procedure on the above Faster R-CNN model. ```C++ #include #include -#include "detector.h" +#include "mmdeploy/detector.hpp" int main() { const char* device_name = "cuda"; int device_id = 0; - - // get mmdeploy model path of faster r-cnn - std::string model_path = std::getenv("WORK_DIR"); - // use mmdetection demo image as an input image - std::string image_path = std::getenv("MMDET_DIR") + "/demo/demo.jpg"; - - // create inference handle - mmdeploy_detector_t detector{}; - int status{}; - status = mmdeploy_detector_create_by_path(model_path, device_name, device_id, &detector); - assert(status == MMDEPLOY_SUCCESS); - - // read image + std::string model_path = "mmdeploy_model/faster-rcnn"; + std::string image_path = "mmdetection/demo/demo.jpg"; + + // 1. load model + mmdeploy::Model model(model_path); + // 2. create predictor + mmdeploy::Detector detector(model, mmdeploy::Device{device_name, device_id}); + // 3. read image cv::Mat img = cv::imread(image_path); - assert(img.data); - - // apply handle and get the inference result - mmdeploy_mat_t mat{img.data, img.rows, img.cols, 3, MMDEPLOY_PIXEL_FORMAT_BGR, MMDEPLOY_DATA_TYPE_UINT8}; - mmdeploy_detection_t *bboxes{}; - int *res_count{}; - status = mmdeploy_detector_apply(detector, &mat, 1, &bboxes, &res_count); - assert (status == MMDEPLOY_SUCCESS); - - // deal with the result. Here we choose to visualize it - for (int i = 0; i < *res_count; ++i) { - const auto &box = bboxes[i].bbox; + // 4. inference + auto dets = detector.Apply(img); + // 5. deal with the result. Here we choose to visualize it + for (int i = 0; i < dets.size(); ++i) { + const auto& box = dets[i].bbox; + fprintf(stdout, "box %d, left=%.2f, top=%.2f, right=%.2f, bottom=%.2f, label=%d, score=%.4f\n", + i, box.left, box.top, box.right, box.bottom, dets[i].label_id, dets[i].score); if (bboxes[i].score < 0.3) { continue; } cv::rectangle(img, cv::Point{(int)box.left, (int)box.top}, cv::Point{(int)box.right, (int)box.bottom}, cv::Scalar{0, 255, 0}); } - cv::imwrite("output_detection.png", img); - - // destroy result buffer - mmdeploy_detector_release_result(bboxes, res_count, 1); - // destroy inference handle - mmdeploy_detector_destroy(detector); return 0; } ``` @@ -318,16 +318,13 @@ When you build this example, try to add MMDeploy package in your CMake project a ```Makefile find_package(MMDeploy REQUIRED) -mmdeploy_load_static(${YOUR_AWESOME_TARGET} MMDeployStaticModules) -mmdeploy_load_dynamic(${YOUR_AWESOME_TARGET} MMDeployDynamicModules) -target_link_libraries(${YOUR_AWESOME_TARGET} PRIVATE MMDeployLibs) +target_link_libraries(${name} PRIVATE mmdeploy ${OpenCV_LIBS}) ``` -For more SDK C API usages, please read these [samples](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csrc). - -#### C# API +For more SDK C++ API usages, please read these [samples](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csrc). -Due to limitations on space, we will not present a specific example. But you can find all of them [here](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csharp). +For the rest C, C# and Java API usages, please read [C demos](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csrc), [C# demos](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csharp) and [Java demos](https://github.com/open-mmlab/mmdeploy/tree/master/demo/java) respectively. +We'll talk about them more in our next release. ## Evaluate Model diff --git a/docs/zh_cn/01-how-to-build/android.md b/docs/zh_cn/01-how-to-build/android.md index 4e55384e2a..40828a9b77 100644 --- a/docs/zh_cn/01-how-to-build/android.md +++ b/docs/zh_cn/01-how-to-build/android.md @@ -7,8 +7,7 @@ - [安装 MMDeploy SDK 依赖](#安装-mmdeploy-sdk-依赖) - [编译 MMDeploy](#编译-mmdeploy) - [编译选项说明](#编译选项说明) - - [编译 SDK](#编译-sdk) - - [编译 Demo](#编译-demo) + - [编译 SDK 和 Demos](#编译-sdk-和-demos) ______________________________________________________________________ @@ -175,7 +174,7 @@ make -j$(nproc) install -#### 编译 SDK +#### 编译 SDK 和 Demos 下文展示构建SDK的样例,用 ncnn 作为推理引擎。 @@ -186,6 +185,7 @@ make -j$(nproc) install mkdir -p build_${ANDROID_ABI} && cd build_${ANDROID_ABI} cmake .. \ -DMMDEPLOY_BUILD_SDK=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_BUILD_SDK_JAVA_API=ON \ -DOpenCV_DIR=${OPENCV_ANDROID_SDK_DIR}/sdk/native/jni/abi-${ANDROID_ABI} \ -Dncnn_DIR=${NCNN_DIR}/build_${ANDROID_ABI}/install/lib/cmake/ncnn \ @@ -199,20 +199,3 @@ make -j$(nproc) install make -j$(nproc) && make install ``` - -#### 编译 Demo - -```Bash -export ANDROID_ABI=arm64-v8a - -cd ${MMDEPLOY_DIR}/build_${ANDROID_ABI}/install/example -mkdir -p build && cd build -cmake .. \ - -DOpenCV_DIR=${OPENCV_ANDROID_SDK_DIR}/sdk/native/jni/abi-${ANDROID_ABI} \ - -Dncnn_DIR=${NCNN_DIR}/build_${ANDROID_ABI}/install/lib/cmake/ncnn \ - -DMMDeploy_DIR=${MMDEPLOY_DIR}/build_${ANDROID_ABI}/install/lib/cmake/MMDeploy \ - -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI=${ANDROID_ABI} \ - -DANDROID_PLATFORM=android-30 -make -j$(nproc) -``` diff --git a/docs/zh_cn/01-how-to-build/jetsons.md b/docs/zh_cn/01-how-to-build/jetsons.md index 596e05e14c..c952da8980 100644 --- a/docs/zh_cn/01-how-to-build/jetsons.md +++ b/docs/zh_cn/01-how-to-build/jetsons.md @@ -227,13 +227,14 @@ pip install -v -e . 如果你不需要使用 MMDeploy C/C++ Inference SDK 则可以跳过本步骤。 -1. 编译 SDK Libraries +1. 编译 SDK Libraries 和 Demos ```shell mkdir -p build && cd build cmake .. \ -DMMDEPLOY_BUILD_SDK=ON \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \ -DMMDEPLOY_TARGET_BACKENDS="trt" \ -DMMDEPLOY_CODEBASES=all \ @@ -241,16 +242,7 @@ pip install -v -e . make -j$(nproc) && make install ``` -2. 编译 SDK demos - - ```shell - cd ${MMDEPLOY_DIR}/build/install/example - mkdir -p build && cd build - cmake .. -DMMDeploy_DIR=${MMDEPLOY_DIR}/build/install/lib/cmake/MMDeploy - make -j$(nproc) - ``` - -3. 运行 demo +2. 运行 demo 以目标检测为例: diff --git a/docs/zh_cn/01-how-to-build/linux-x86_64.md b/docs/zh_cn/01-how-to-build/linux-x86_64.md index e421b11bd6..42dd18235d 100644 --- a/docs/zh_cn/01-how-to-build/linux-x86_64.md +++ b/docs/zh_cn/01-how-to-build/linux-x86_64.md @@ -12,8 +12,7 @@ - [编译安装 Model Converter](#编译安装-model-converter) - [编译自定义算子](#编译自定义算子) - [安装 Model Converter](#安装-model-converter) - - [编译SDK](#编译sdk) - - [编译 Demo](#编译-demo) + - [编译 SDK 和 Demos](#编译-sdk-和-demos) ______________________________________________________________________ @@ -391,7 +390,7 @@ pip install -e . - 有些依赖项是可选的。运行 `pip install -e .` 将进行最小化依赖安装。 如果需安装其他可选依赖项,请执行`pip install -r requirements/optional.txt`, 或者 `pip install -e .[optional]`。其中,`[optional]`可以替换为:`all`、`tests`、`build` 或 `optional`。 -#### 编译SDK +#### 编译 SDK 和 Demos 下文展示2个构建SDK的样例,分别用 ONNXRuntime 和 TensorRT 作为推理引擎。您可以参考它们,激活其他的推理引擎。 @@ -403,6 +402,7 @@ pip install -e . cmake .. \ -DCMAKE_CXX_COMPILER=g++-7 \ -DMMDEPLOY_BUILD_SDK=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ -DMMDEPLOY_TARGET_DEVICES=cpu \ -DMMDEPLOY_TARGET_BACKENDS=ort \ @@ -420,6 +420,7 @@ pip install -e . cmake .. \ -DCMAKE_CXX_COMPILER=g++-7 \ -DMMDEPLOY_BUILD_SDK=ON \ + -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ -DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \ -DMMDEPLOY_TARGET_BACKENDS=trt \ @@ -430,12 +431,3 @@ pip install -e . make -j$(nproc) && make install ``` - -#### 编译 Demo - -```Bash -cd ${MMDEPLOY_DIR}/build/install/example -mkdir -p build && cd build -cmake .. -DMMDeploy_DIR=${MMDEPLOY_DIR}/build/install/lib/cmake/MMDeploy -make -j$(nproc) -``` diff --git a/docs/zh_cn/01-how-to-build/windows.md b/docs/zh_cn/01-how-to-build/windows.md index 07e6e5a91d..0257a2fd7a 100644 --- a/docs/zh_cn/01-how-to-build/windows.md +++ b/docs/zh_cn/01-how-to-build/windows.md @@ -12,14 +12,11 @@ - [编译安装 Model Converter](#编译安装-model-converter) - [编译自定义算子](#编译自定义算子) - [安装 Model Converter](#安装-model-converter) - - [编译 SDK](#编译-sdk) - - [编译 Demo](#编译-demo) + - [编译 SDK 和 Demos](#编译-sdk-和-demos) - [注意事项](#注意事项) ______________________________________________________________________ -目前,MMDeploy 在 Windows 平台下仅提供源码编译安装方式。未来会提供预编译包方式。 - ## 源码安装 下述安装方式,均是在 **Windows 10** 下进行,使用 **PowerShell Preview** 版本。 @@ -307,7 +304,7 @@ pip install -e . - 有些依赖项是可选的。运行 `pip install -e .` 将进行最小化依赖安装。 如果需安装其他可选依赖项,请执行`pip install -r requirements/optional.txt`, 或者 `pip install -e .[optional]`。其中,`[optional]`可以替换为:`all`、`tests`、`build` 或 `optional`。 -#### 编译 SDK +#### 编译 SDK 和 Demos 下文展示2个构建SDK的样例,分别用 ONNXRuntime 和 TensorRT 作为推理引擎。您可以参考它们,并结合前文 SDK 的编译选项说明,激活其他的推理引擎。 @@ -319,6 +316,8 @@ pip install -e . cd build cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` -DMMDEPLOY_BUILD_SDK=ON ` + -DMMDEPLOY_BUILD_EXAMPLES=ON ` + -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON ` -DMMDEPLOY_TARGET_DEVICES="cpu" ` -DMMDEPLOY_TARGET_BACKENDS="ort" ` -DMMDEPLOY_CODEBASES="all" ` @@ -336,6 +335,8 @@ pip install -e . cd build cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` -DMMDEPLOY_BUILD_SDK=ON ` + -DMMDEPLOY_BUILD_EXAMPLES=ON ` + -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON ` -DMMDEPLOY_TARGET_DEVICES="cuda" ` -DMMDEPLOY_TARGET_BACKENDS="trt" ` -DMMDEPLOY_CODEBASES="all" ` @@ -347,20 +348,6 @@ pip install -e . cmake --install . --config Release ``` -#### 编译 Demo - -```PowerShell -cd $env:MMDEPLOY_DIR\build\install\example -mkdir build -ErrorAction SilentlyContinue -cd build -cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` - -DMMDeploy_DIR="$env:MMDEPLOY_DIR/build/install/lib/cmake/MMDeploy" - -cmake --build . --config Release -- /m - -$env:path = "$env:MMDEPLOY_DIR/build/install/bin;" + $env:path -``` - ### 注意事项 1. Release / Debug 库不能混用。MMDeploy 要是编译 Release 版本,所有第三方依赖都要是 Release 版本。反之亦然。 diff --git a/docs/zh_cn/02-how-to-run/prebuilt_package_windows.md b/docs/zh_cn/02-how-to-run/prebuilt_package_windows.md index 3bef241310..4b84f403f3 100644 --- a/docs/zh_cn/02-how-to-run/prebuilt_package_windows.md +++ b/docs/zh_cn/02-how-to-run/prebuilt_package_windows.md @@ -23,7 +23,7 @@ ______________________________________________________________________ 目前,`MMDeploy`在`Windows`平台下提供`TensorRT`以及`ONNX Runtime`两种预编译包,可以从[Releases](https://github.com/open-mmlab/mmdeploy/releases)获取。 -本篇教程以`mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1.zip`和`mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip`为例,展示预编译包的使用方法。 +本篇教程以`mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1.zip`和`mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip`为例,展示预编译包的使用方法。 为了方便使用者快速上手,本教程以分类模型(mmclassification)为例,展示两种预编译包的使用方法。 @@ -88,9 +88,9 @@ ______________________________________________________________________ 5. 安装`mmdeploy`(模型转换)以及`mmdeploy_python`(模型推理Python API)的预编译包 ```bash - # 先下载 mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1.zip - pip install .\mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\dist\mmdeploy-0.6.0-py38-none-win_amd64.whl - pip install .\mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\python\mmdeploy_python-0.6.0-cp38-none-win_amd64.whl + # 先下载 mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1.zip + pip install .\mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\dist\mmdeploy-0.7.0-py38-none-win_amd64.whl + pip install .\mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\python\mmdeploy_python-0.7.0-cp38-none-win_amd64.whl ``` :point_right: 如果之前安装过,需要先卸载后再安装。 @@ -115,9 +115,9 @@ ______________________________________________________________________ 5. 安装`mmdeploy`(模型转换)以及`mmdeploy_python`(模型推理Python API)的预编译包 ```bash - # 先下载 mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip - pip install .\mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\dist\mmdeploy-0.6.0-py38-none-win_amd64.whl - pip install .\mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\python\mmdeploy_python-0.6.0-cp38-none-win_amd64.whl + # 先下载 mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0.zip + pip install .\mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\dist\mmdeploy-0.7.0-py38-none-win_amd64.whl + pip install .\mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\python\mmdeploy_python-0.7.0-cp38-none-win_amd64.whl ``` :point_right: 如果之前安装过,需要先卸载后再安装 @@ -146,7 +146,7 @@ ______________________________________________________________________ ``` .. -|-- mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1 +|-- mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1 |-- mmclassification |-- mmdeploy `-- resnet18_8xb32_in1k_20210831-fbbb1da6.pth @@ -194,7 +194,7 @@ export2SDK(deploy_cfg, model_cfg, work_dir, pth=model_checkpoint) ``` .. -|-- mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 +|-- mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 |-- mmclassification |-- mmdeploy `-- resnet18_8xb32_in1k_20210831-fbbb1da6.pth @@ -257,8 +257,8 @@ export2SDK(deploy_cfg, model_cfg, work_dir, pth=model_checkpoint) ``` . -|-- mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 -|-- mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1 +|-- mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0 +|-- mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1 |-- mmclassification |-- mmdeploy |-- resnet18_8xb32_in1k_20210831-fbbb1da6.pth @@ -308,7 +308,7 @@ result = inference_model(model_cfg, deploy_cfg, backend_files, img, device) 推理代码 ```bash -python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\mmclassification\demo\demo.JPEG +python .\mmdeploy\demo\python\image_classification.py cpu .\work_dir\onnx\resnet\ .\mmclassification\demo\demo.JPEG ``` #### TensorRT @@ -316,7 +316,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ 推理代码 ``` - python .\mmdeploy\demo\python\image_classification.py .\work_dir\trt\resnet\ .\mmclassification\demo\demo.JPEG --device-name cuda + python .\mmdeploy\demo\python\image_classification.py cuda .\work_dir\trt\resnet\ .\mmclassification\demo\demo.JPEG ``` ### C SDK @@ -327,7 +327,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ 1. 编译 examples - 在`mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\example`目录下 + 在`mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\example`目录下 ``` // 部分路径根据实际位置进行修改 @@ -335,7 +335,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ cd build cmake .. -A x64 -T v142 ` -DOpenCV_DIR=C:\Deps\opencv\build\x64\vc15\lib ` - -DMMDeploy_DIR=C:\workspace\mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\lib\cmake\MMDeploy ` + -DMMDeploy_DIR=C:\workspace\mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\lib\cmake\MMDeploy ` -DONNXRUNTIME_DIR=C:\Deps\onnxruntime\onnxruntime-win-gpu-x64-1.8.1 cmake --build . --config Release @@ -345,7 +345,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ :point_right: 目的是使exe运行时可以正确找到相关dll - 若选择添加环境变量,则将`mmdeploy`的运行时库路径(`mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\sdk\bin`)添加到PATH,可参考onnxruntime的添加过程。 + 若选择添加环境变量,则将`mmdeploy`的运行时库路径(`mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\sdk\bin`)添加到PATH,可参考onnxruntime的添加过程。 若选择拷贝动态库,而将bin目录中的dll拷贝到刚才编译出的exe(build/Release)的同级目录下。 @@ -353,7 +353,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ 这里建议使用cmd,这样如果exe运行时如果找不到相关的dll的话会有弹窗 - 在mmdeploy-0.6.0-windows-amd64-onnxruntime1.8.1\\sdk\\example\\build\\Release目录下: + 在mmdeploy-0.7.0-windows-amd64-onnxruntime1.8.1\\sdk\\example\\build\\Release目录下: ``` .\image_classification.exe cpu C:\workspace\work_dir\onnx\resnet\ C:\workspace\mmclassification\demo\demo.JPEG @@ -363,7 +363,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ 1. 编译 examples - 在mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example目录下 + 在mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example目录下 ``` // 部分路径根据所在硬盘的位置进行修改 @@ -371,7 +371,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ cd build cmake .. -A x64 -T v142 ` -DOpenCV_DIR=C:\Deps\opencv\build\x64\vc15\lib ` - -DMMDeploy_DIR=C:\workspace\mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8 2.3.0\sdk\lib\cmake\MMDeploy ` + -DMMDeploy_DIR=C:\workspace\mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8 2.3.0\sdk\lib\cmake\MMDeploy ` -DTENSORRT_DIR=C:\Deps\tensorrt\TensorRT-8.2.3.0 ` -DCUDNN_DIR=C:\Deps\cudnn\8.2.1 cmake --build . --config Release @@ -381,7 +381,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ :point_right: 目的是使exe运行时可以正确找到相关dll - 若选择添加环境变量,则将`mmdeploy`的运行时库路径(`mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\bin`)添加到PATH,可参考onnxruntime的添加过程。 + 若选择添加环境变量,则将`mmdeploy`的运行时库路径(`mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\sdk\bin`)添加到PATH,可参考onnxruntime的添加过程。 若选择拷贝动态库,而将bin目录中的dll拷贝到刚才编译出的exe(build/Release)的同级目录下。 @@ -389,7 +389,7 @@ python .\mmdeploy\demo\python\image_classification.py .\work_dir\onnx\resnet\ .\ 这里建议使用cmd,这样如果exe运行时如果找不到相关的dll的话会有弹窗 - 在mmdeploy-0.6.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example\\build\\Release目录下: + 在mmdeploy-0.7.0-windows-amd64-cuda11.1-tensorrt8.2.3.0\\sdk\\example\\build\\Release目录下: ``` .\image_classification.exe cuda C:\workspace\work_dir\trt\resnet C:\workspace\mmclassification\demo\demo.JPEG diff --git a/docs/zh_cn/get_started.md b/docs/zh_cn/get_started.md index aefe20902d..c0e2e84d88 100644 --- a/docs/zh_cn/get_started.md +++ b/docs/zh_cn/get_started.md @@ -4,8 +4,6 @@ MMDeploy 提供了一系列工具,帮助您更轻松的将 OpenMMLab 下的算 您可以使用我们设计的流程一“部”到位,也可以定制您自己的转换流程。 -在接下来的章节中,我们将会向您展示 MMDeploy 的模型部署方式。并在 NVIDIA 设备上,以 [MMDetection](https://github.com/open-mmlab/mmdetection) Faster R-CNN 模型为例,演示 MMDeploy 的基本使用方法。 - ## 流程简介 MMDeploy 定义的模型部署流程,如下图所示: @@ -19,7 +17,7 @@ MMDeploy 定义的模型部署流程,如下图所示: ### MMDeploy 模型(MMDeploy Model) -模型转换结果的集合。它不仅包括后端模型,还包括模型的元信息。这些信息将用于推理 SDK 中。 +也称 SDK Model。它是模型转换结果的集合。不仅包括后端模型,还包括模型的元信息。这些信息将用于推理 SDK 中。 ### 推理 SDK(Inference SDK) @@ -27,208 +25,239 @@ MMDeploy 定义的模型部署流程,如下图所示: ## 准备工作 -对于端到端的模型转换和推理,MMDeploy 依赖 Python 3.6+ 以及 PyTorch 1.5+。 +对于端到端的模型转换和推理,MMDeploy 依赖 Python 3.6+ 以及 PyTorch 1.8+。 **第一步**:从[官网](https://docs.conda.io/en/latest/miniconda.html)下载并安装 Miniconda **第二步**:创建并激活 conda 环境 ```shell -export PYTHON_VERSION=3.7 -conda create --name mmdeploy python=${PYTHON_VERSION} -y +conda create --name mmdeploy python=3.8 -y conda activate mmdeploy ``` **第三步**: 参考[官方文档](https://pytorch.org/get-started/locally/)并安装 PyTorch -Model Converter 的 torch2onnx 功能依赖它。 - -在 GPU 环境下(这里我们以 Ubuntu 18.04 CUDA 11.1 为基础),您可以使用如下方式安装 PyTorch 1.8: +在 GPU 环境下: ```shell -export PYTHON_VERSION=3.7 -export PYTORCH_VERSION=1.8.0 -export TORCHVISION_VERSION=0.9.0 -export CUDA_VERSION=11.1 - -conda create -n mmdeploy python=${PYTHON_VERSION} -y -conda activate mmdeploy - -conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cudatoolkit=${CUDA_VERSION} -c pytorch -c conda-forge +conda install pytorch=={pytorch_version} torchvision=={torchvision_version} cudatoolkit={cudatoolkit_version} -c pytorch -c conda-forge ``` -在 CPU 环境下,您可以执行: +在 CPU 环境下: ```shell -export PYTORCH_VERSION=1.8.0 -export TORCHVISION_VERSION=0.9.0 -conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cpuonly -c pytorch +conda install pytorch=={pytorch_version} torchvision=={torchvision_version} cpuonly -c pytorch +``` + +```{note} +在 GPU 环境下,请务必保证 {cudatoolkit_version} 和主机的 CUDA Toolkit 版本一致,避免在使用 TensorRT 时,可能引起的版本冲突问题。 ``` ## 安装 MMDeploy -**第一步**: 安装 mmcv-full +**第一步**:通过 [MIM](https://github.com/open-mmlab/mim) 安装 [MMCV](https://github.com/open-mmlab/mmcv) ```shell -export MMCV_VERSION=1.5.0 -export CUDA_STRING="${CUDA_VERSION/./""}" - -python -m pip install mmcv-full==${MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/cu${CUDA_STRING}/torch${PYTORCH_VERSION}/index.html +pip install -U openmim +mim install mmcv-full ``` -**第二步**: 安装 MMDeploy - -从 v0.5.0 之后,MMDeploy 开始提供预编译包。您可以根据目标软硬件平台,从[这里](https://github.com/open-mmlab/mmdeploy/releases)选择并下载预编译包。 - -在 NVIDIA 设备上,我们推荐使用 MMDeploy-TensoRT 预编译包: +**第二步**: 安装 MMDeploy 和 推理引擎 + +我们推荐用户使用预编译包安装和体验 MMDeploy 功能。请根据目标软硬件平台,从[这里](https://github.com/open-mmlab/mmdeploy/releases) 选择最新版本下载并安装。 + +目前,MMDeploy 的预编译包支持的平台和设备矩阵如下: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OS-ArchDeviceONNX RuntimeTensorRT
Linux-x86_64CPUYN/A
CUDANY
Windows-x86_64CPUYN/A
CUDANY
+ +**注:对于不在上述表格中的软硬件平台,请参考[源码安装文档](./01-how-to-build/build_from_source.md),正确安装和配置 MMDeploy。** + +以最新的预编译包为例,你可以参考以下命令安装: + +
+Linux-x86_64, CPU, ONNX Runtime 1.8.1 ```shell -export MMDEPLOY_VERSION=0.5.0 -export TENSORRT_VERSION=8.2.3.0 -export PYTHON_VERSION=3.7 -export PYTHON_STRING="${PYTHON_VERSION/./""}" - -wget https://github.com/open-mmlab/mmdeploy/releases/download/v${MMDEPLOY_VERSION}/mmdeploy-${MMDEPLOY_VERSION}-linux-x86_64-cuda${CUDA_VERSION}-tensorrt${TENSORRT_VERSION}.tar.gz -tar -zxvf mmdeploy-${MMDEPLOY_VERSION}-linux-x86_64-cuda${CUDA_VERSION}-tensorrt${TENSORRT_VERSION}.tar.gz -cd mmdeploy-${MMDEPLOY_VERSION}-linux-x86_64-cuda${CUDA_VERSION}-tensorrt${TENSORRT_VERSION} -python -m pip install dist/mmdeploy-*-py${PYTHON_STRING}*.whl -python -m pip install sdk/python/mmdeploy_python-*-cp${PYTHON_STRING}*.whl -export LD_LIBRARY_PATH=$(pwd)/sdk/lib:$LD_LIBRARY_PATH +# 安装 MMDeploy ONNX Runtime 自定义算子库和推理 SDK +wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.7.0/mmdeploy-0.7.0-linux-x86_64-onnxruntime1.8.1.tar.gz +tar -zxvf mmdeploy-0.7.0-linux-x86_64-onnxruntime1.8.1.tar.gz +cd mmdeploy-0.7.0-linux-x86_64-onnxruntime1.8.1 +pip install dist/mmdeploy-0.7.0-py3-none-linux_x86_64.whl +pip install sdk/python/mmdeploy_python-0.7.0-cp38-none-linux_x86_64.whl cd .. +# 安装推理引擎 ONNX Runtime +pip install onnxruntime==1.8.1 +wget https://github.com/microsoft/onnxruntime/releases/download/v1.8.1/onnxruntime-linux-x64-1.8.1.tgz +tar -zxvf onnxruntime-linux-x64-1.8.1.tgz +export ONNXRUNTIME_DIR=$(pwd)/onnxruntime-linux-x64-1.8.1 +export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH ``` -```{note} -如果 MMDeploy 没有您所需要的目标软硬件平台的预编译包,请参考源码安装文档,正确安装和配置 -``` - -**第三步**: 安装预编译包要求的推理后端 +
-在本例中,我们需要安装 TensorRT(含 cuDNN)推理引擎。因在 NVIDIA 官网下载软件包,必须要登录认证,所以请预先登录并下载所需的 [TensorRT](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-tar) 和 [cuDNN](https://developer.nvidia.com/cudnn)。**请注意: TensorRT 版本、cuDNN 版本要和 CUDA 版本匹配** - -下载完毕后,您可以参考如下方法安装。这里,我们以 TensorRT 8.2.3.0、cuDNN 8.2 为例: +
+Linux-x86_64, CUDA 11.x, TensorRT 8.2.3.0 ```shell -export TENSORRT_VERSION=8.2.3.0 -CUDA_MAJOR="${CUDA_VERSION/\.*/""}" - -# !!! 从 NVIDIA 官网下载 与 cuda toolkit 匹配的 tensorrt 到当前的工作目录 -tar -zxvf TensorRT-${TENSORRT_VERSION}*cuda-${CUDA_MAJOR}*.tar.gz -python -m pip install TensorRT-${TENSORRT_VERSION}/python/tensorrt-*-cp${PYTHON_STRING}*.whl -python -m pip install pycuda -export TENSORRT_DIR=$(pwd)/TensorRT-${TENSORRT_VERSION} +# 安装 MMDeploy TensorRT 自定义算子库和推理 SDK +wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.7.0/mmdeploy-0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0.tar.gz +tar -zxvf mmdeploy-v0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0.tar.gz +cd mmdeploy-0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0 +pip install dist/mmdeploy-0.7.0-py3-none-linux_x86_64.whl +pip install sdk/python/mmdeploy_python-0.7.0-cp38-none-linux_x86_64.whl +cd .. +# 安装推理引擎 TensorRT +# !!! 从 NVIDIA 官网下载 TensorRT-8.2.3.0 CUDA 11.x 安装包并解压到当前目录 +pip install TensorRT-8.2.3.0/python/tensorrt-8.2.3.0-cp38-none-linux_x86_64.whl +pip install pycuda +export TENSORRT_DIR=$(pwd)/TensorRT-8.2.3.0 export LD_LIBRARY_PATH=${TENSORRT_DIR}/lib:$LD_LIBRARY_PATH - - -# !!! 从 NVIDIA 官网下载与 cuda toolkit,tensorrt 匹配的 cudnn 到当前的工作目录 -tar -zxvf cudnn-${CUDA_MAJOR}.*-linux-x64*.tgz +# !!! 从 NVIDIA 官网下载 cuDNN 8.2.1 CUDA 11.x 安装包并解压到当前目录 export CUDNN_DIR=$(pwd)/cuda export LD_LIBRARY_PATH=$CUDNN_DIR/lib64:$LD_LIBRARY_PATH ``` -在接下来的章节中,我们均以此环境为基础,演示 MMDeploy 的功能。 +
-目前,对于 MMDeploy 支持各种推理后端的安装方法,您可以查阅以下文档: +
+Windows-x86_64 +
-- [ONNX Runtime](../en/05-supported-backends/onnxruntime.md) -- [TensorRT](../en/05-supported-backends/tensorrt.md) -- [PPL.NN](../en/05-supported-backends/pplnn.md) -- [ncnn](../en/05-supported-backends/ncnn.md) -- [OpenVINO](../en/05-supported-backends/openvino.md) -- [LibTorch](../en/05-supported-backends/torchscript.md) +请阅读 [这里](./02-how-to-run/prebuilt_package_windows.md),了解 MMDeploy 预编译包在 Windows 平台下的使用方法。 ## 模型转换 -在准备工作就绪后,我们可以使用 MMDeploy 中的工具 `deploy.py`,将 OpenMMLab 的 PyTorch 模型转换成推理后端支持的格式。 +在准备工作就绪后,我们可以使用 MMDeploy 中的工具 `tools/deploy.py`,将 OpenMMLab 的 PyTorch 模型转换成推理后端支持的格式。 +对于`tools/deploy.py` 的使用细节,请参考 [如何转换模型](./02-how-to-run/convert_model.md)。 -以 [MMDetection](https://github.com/open-mmlab/mmdetection) 中的 `Faster R-CNN` 为例,我们可以使用如下命令,将 PyTorch 模型转换成可部署在 NVIDIA GPU 上的 TenorRT 模型: +以 [MMDetection](https://github.com/open-mmlab/mmdetection) 中的 `Faster R-CNN` 为例,我们可以使用如下命令,将 PyTorch 模型转换为 TenorRT 模型,从而部署到 NVIDIA GPU 上. ```shell # 克隆 mmdeploy 仓库。转换时,需要使用 mmdeploy 仓库中的配置文件,建立转换流水线 git clone --recursive https://github.com/open-mmlab/mmdeploy.git -python -m pip install -r mmdeploy/requirements/runtime.txt -export MMDEPLOY_DIR=$(pwd)/mmdeploy -# 克隆 mmdetection 仓库。转换时,需要使用 mmdetection 仓库中的模型配置文件,构建 PyTorch nn module -python -m pip install mmdet==2.24.0 +# 安装 mmdetection。转换时,需要使用 mmdetection 仓库中的模型配置文件,构建 PyTorch nn module git clone https://github.com/open-mmlab/mmdetection.git -export MMDET_DIR=$(pwd)/mmdetection +cd mmdetection +pip install -v -e . +cd .. # 下载 Faster R-CNN 模型权重 -export CHECKPOINT_DIR=$(pwd)/checkpoints -wget -P ${CHECKPOINT_DIR} https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth - -# 设置工作路径 -export WORK_DIR=$(pwd)/mmdeploy_models/faster-rcnn +wget -P checkpoints https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth # 执行转换命令,实现端到端的转换 -python ${MMDEPLOY_DIR}/tools/deploy.py \ - ${MMDEPLOY_DIR}/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ - ${MMDET_DIR}/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ - ${CHECKPOINT_DIR}/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ - ${MMDET_DIR}/demo/demo.jpg \ - --work-dir ${WORK_DIR} \ - --device cuda:0 \ +python mmdeploy/tools/deploy.py \ + mmdeploy/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ + mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ + checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ + mmdetection/demo/demo.jpg \ + --work-dir mmdeploy_model/faster-rcnn \ + --device cuda \ --dump-info ``` -`${MMDEPLOY_DIR}/tools/deploy.py` 是一个方便模型转换的工具。您可以阅读 [如何转换模型](./02-how-to-run/convert_model.md) 了解更多细节。 +转换结果被保存在 `--work-dir` 指向的文件夹中。**该文件夹中不仅包含推理后端模型,还包括推理元信息。这些内容的整体被定义为 SDK Model。推理 SDK 将用它进行模型推理。** -`detection_tensorrt_dynamic-320x320-1344x1344.py` 是一个参数配置文件。该文件的命名遵循如下规则: - -```bash -<任务名>_<推理后端>-[后端特性]_<动态模型支持>.py +```{tip} +在安装了 MMDeploy-ONNXRuntime 预编译包后,把上述转换命令中的detection_tensorrt_dynamic-320x320-1344x1344.py 换成 detection_onnxruntime_dynamic.py,并修改 --device 为 cpu, +即可以转出 onnx 模型,并用 ONNXRuntime 进行推理 ``` -可以很容易的通过文件名来确定最适合的那个配置文件。如果您希望定制自己的转换配置,可以参考[如何编写配置文件](./02-how-to-run/write_config.md)修改参数。 - ## 模型推理 -在转换完成后,您既可以使用 Model Converter 进行推理,也可以使用 Inference SDK。前者使用 Python 开发,后者主要使用 C/C++ 开发。 +在转换完成后,你既可以使用 Model Converter 进行推理,也可以使用 Inference SDK。 ### 使用 Model Converter 的推理 API Model Converter 屏蔽了推理后端接口的差异,对其推理 API 进行了统一封装,接口名称为 `inference_model`。 -以上文中 Faster R-CNN 的 TensorRT 模型为例,您可以使用如下方式进行模型推理工作: +以上文中 Faster R-CNN 的 TensorRT 模型为例,你可以使用如下方式进行模型推理工作: ```python from mmdeploy.apis import inference_model -import os - -model_cfg = os.getenv('MMDET_DIR') + '/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' -deploy_cfg = os.getenv('MMDEPLOY_DIR') + '/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py' -backend_files = [os.getenv('WORK_DIR') + '/end2end.engine'] - -result = inference_model(model_cfg, deploy_cfg, backend_files, img=img, device=device) +result = inference_model( + model_cfg='mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', + deploy_cfg='mmdeploy/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py', + backend_files=['mmdeploy_model/faster-rcnn/end2end.engine'], + img='mmdetection/demo/demo.jpg', + device='cuda:0') ``` -`inference_model`会创建一个对后端模型的封装,通过该封装进行推理。推理的结果会保持与 OpenMMLab 中原模型同样的格式。 - ```{note} -MMDeploy 转出的后端模型,您可以直接使用后端 API 进行推理。不过,因为 MMDeploy 拥有 TensorRT、ONNX Runtime 等自定义算子, -您需要先加载对应的自定义算子库,然后再使用后端 API。 +接口中的 model_path 指的是推理引擎文件的路径,比如例子当中end2end.engine文件的路径。路径必须放在 list 中,因为有的推理引擎模型结构和权重是分开存储的。 ``` ### 使用推理 SDK -您也可以使用 MMDeploy SDK 进行推理。以上文中转出的 Faster R-CNN TensorRT 模型为例,接下来的章节将介绍如何使用 SDK 的 FFI 进行模型推理。 +你可以直接运行预编译包中的 demo 程序,输入 SDK Model 和图像,进行推理,并查看推理结果。 + +```shell +cd mmdeploy-0.7.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0 +# 运行 python demo +python sdk/example/python/object_detection.py cuda ../mmdeploy_model/faster-rcnn ../mmdetection/demo/demo.jpg +# 运行 C/C++ demo +export LD_LIBRARY_PATH=$(pwd)/sdk/lib:$LD_LIBRARY_PATH +./sdk/bin/object_detection cuda ../mmdeploy_model/faster-rcnn ../mmdetection/demo/demo.jpg +``` + +```{note} +以上述命令中,输入模型是 SDK Model 的路径(也就是 Model Converter 中 --work-dir 参数),而不是推理引擎文件的路径。 +因为 SDK 不仅要获取推理引擎文件,还需要推理元信息(deploy.json, pipeline.json)。它们合在一起,构成 SDK Model,存储在 --work-dir 下 +``` + +除了 demo 程序,预编译包还提供了 SDK 多语言接口。你可以根据自己的项目需求,选择合适的语言接口, +把 MMDeploy SDK 集成到自己的项目中,进行二次开发。 #### Python API +对于检测功能,你也可以参考如下代码,集成 MMDeploy SDK Python API 到自己的项目中: + ```python from mmdeploy_python import Detector -import os import cv2 -# 获取转换后的 mmdeploy model 路径 -model_path = os.getenv('WORK_DIR') -# 从 mmdetection repo 中,获取 demo.jpg 路径 -image_path = '/'.join((os.getenv('MMDET_DIR'), 'demo/demo.jpg')) - -img = cv2.imread(image_path) -detector = Detector(model_path, 'cuda', 0) -bboxes, labels, _ = detector([img])[0] +# 读取图片 +img = cv2.imread('mmdetection/demo/demo.jpg') +# 创建检测器 +detector = Detector(model_path='mmdeploy_models/faster-rcnn', device_name='cuda', device_id=0) +# 执行推理 +bboxes, labels, _ = detector(img) +# 使用阈值过滤推理结果,并绘制到原图中 indices = [i for i in range(len(bboxes))] for index, bbox, label_id in zip(indices, bboxes, labels): [left, top, right, bottom], score = bbox[0:4].astype(int), bbox[4] @@ -237,78 +266,50 @@ for index, bbox, label_id in zip(indices, bboxes, labels): cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0)) cv2.imwrite('output_detection.png', img) - ``` -更多模型的 SDK Python API 应用样例,请查阅[这里](https://github.com/open-mmlab/mmdeploy/tree/master/demo/python)。 - -```{note} -如果您使用源码安装方式, 请把 ${MMDEPLOY_DIR}/build/lib 加入到环境变量 PYTHONPATH 中。 -否则会遇到错误’ModuleNotFoundError: No module named 'mmdeploy_python' -``` +更多示例,请查阅[这里](https://github.com/open-mmlab/mmdeploy/tree/master/demo/python)。 -#### C API +#### C++ API -使用 C API 进行模型推理的流程符合下面的模式: - -```{mermaid} -graph LR - A[创建推理句柄] --> B(读取图像) - B --> C(应用句柄进行推理) - C --> D[处理推理结果] - D -->E[销毁结果] - E -->F[销毁推理句柄] -``` +使用 C++ API 进行模型推理的流程符合下面的模式: +![image](https://user-images.githubusercontent.com/4560679/182554486-2bf0ff80-9e82-4a0f-bccc-5e1860444302.png) 以下是这个流程的具体应用过程: ```C++ #include #include -#include "detector.h" +#include "mmdeploy/detector.hpp" int main() { const char* device_name = "cuda"; int device_id = 0; - // 获取转换后的 mmdeploy model 路径 - std::string model_path = std::getenv("WORK_DIR"); - // 从 mmdetection repo 中,获取 demo.jpg 路径 - std::string image_path = std::getenv("MMDET_DIR") + "/demo/demo.jpg"; - - // 创建推理句柄 - mmdeploy_detector_t detector{}; - int status{}; - status = mmdeploy_detector_create_by_path(model_path, device_name, device_id, &detector); - assert(status == MMDEPLOY_SUCCESS); + // mmdeploy SDK model,以上文中转出的 faster r-cnn 模型为例 + std::string model_path = "mmdeploy_model/faster-rcnn"; + std::string image_path = "mmdetection/demo/demo.jpg"; - // 读取图像 + // 1. 读取模型 + mmdeploy::Model model(model_path); + // 2. 创建预测器 + mmdeploy::Detector detector(model, mmdeploy::Device{device_name, device_id}); + // 3. 读取图像 cv::Mat img = cv::imread(image_path); - assert(img.data); - - // 应用句柄进行推理 - mmdeploy_mat_t mat{img.data, img.rows, img.cols, 3, MMDEPLOY_PIXEL_FORMAT_BGR, MMDEPLOY_DATA_TYPE_UINT8}; - mmdeploy_detection_t *bboxes{}; - int *res_count{}; - status = mmdeploy_detector_apply(detector, &mat, 1, &bboxes, &res_count); - assert (status == MMDEPLOY_SUCCESS); - - // 处理推理结果: 此处我们选择可视化推理结果 - for (int i = 0; i < *res_count; ++i) { - const auto &box = bboxes[i].bbox; + // 4. 应用预测器推理 + auto dets = detector.Apply(img); + // 5. 处理推理结果: 此处我们选择可视化推理结果 + for (int i = 0; i < dets.size(); ++i) { + const auto& box = dets[i].bbox; + fprintf(stdout, "box %d, left=%.2f, top=%.2f, right=%.2f, bottom=%.2f, label=%d, score=%.4f\n", + i, box.left, box.top, box.right, box.bottom, dets[i].label_id, dets[i].score); if (bboxes[i].score < 0.3) { continue; } cv::rectangle(img, cv::Point{(int)box.left, (int)box.top}, cv::Point{(int)box.right, (int)box.bottom}, cv::Scalar{0, 255, 0}); } - cv::imwrite("output_detection.png", img); - - // 销毁结果 - mmdeploy_detector_release_result(bboxes, res_count, 1); - // 销毁推理句柄 - mmdeploy_detector_destroy(detector); return 0; } ``` @@ -317,27 +318,24 @@ int main() { ```Makefile find_package(MMDeploy REQUIRED) -mmdeploy_load_static(${YOUR_AWESOME_TARGET} MMDeployStaticModules) -mmdeploy_load_dynamic(${YOUR_AWESOME_TARGET} MMDeployDynamicModules) -target_link_libraries(${YOUR_AWESOME_TARGET} PRIVATE MMDeployLibs) +target_link_libraries(${name} PRIVATE mmdeploy ${OpenCV_LIBS}) ``` 编译时,使用 -DMMDeploy_DIR,传入MMDeloyConfig.cmake所在的路径。它在预编译包中的sdk/lib/cmake/MMDeloy下。 -更多模型的 SDK C API 应用样例,请查阅[此处](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csrc)。 - -#### C# API +更多示例,请查阅[此处](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csrc)。 -因篇幅所限,本文不展示具体案例。请参考[这里](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csharp),了解 SDK C# API 的用法。 +对于 C API、C# API、Java API 的使用方法,请分别阅读代码[C demos](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csrc), [C# demos](https://github.com/open-mmlab/mmdeploy/tree/master/demo/csharp) 和 [Java demos](https://github.com/open-mmlab/mmdeploy/tree/master/demo/java)。 +我们将在后续版本中详细讲述它们的用法。 ## 模型精度评估 为了测试部署模型的精度,推理效率,我们提供了 `tools/test.py` 来帮助完成相关工作。以上文中的部署模型为例: ```bash -python ${MMDEPLOY_DIR}/tools/test.py \ - ${MMDEPLOY_DIR}/configs/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ - ${MMDET_DIR}/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ - --model ${BACKEND_MODEL_FILES} \ +python mmdeploy/tools/test.py \ + mmdeploy/configs/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ + mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ + --model mmdeploy_model/faster-rcnn/end2end.engine \ --metrics ${METRICS} \ --device cuda:0 ``` diff --git a/mmdeploy/version.py b/mmdeploy/version.py index 4e017cb170..db8cd827e1 100644 --- a/mmdeploy/version.py +++ b/mmdeploy/version.py @@ -1,7 +1,7 @@ # Copyright (c) OpenMMLab. All rights reserved. from typing import Tuple -__version__ = '0.6.0' +__version__ = '0.7.0' short_version = __version__ diff --git a/requirements/docs.txt b/requirements/docs.txt index a61666c3ee..bdffca9613 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -1,11 +1,11 @@ docutils==0.16.0 m2r==0.2.1 -markdown<3.4.0 +markdown>=3.4.0 mistune==0.8.4 myst-parser -e git+https://github.com/open-mmlab/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme recommonmark sphinx==4.0.2 sphinx-copybutton -sphinx_markdown_tables +sphinx_markdown_tables>=0.0.16 sphinxcontrib-mermaid diff --git a/tools/package_tools/packaging/mmdeploy_python/version.py b/tools/package_tools/packaging/mmdeploy_python/version.py index 26a449087c..806f4defe8 100644 --- a/tools/package_tools/packaging/mmdeploy_python/version.py +++ b/tools/package_tools/packaging/mmdeploy_python/version.py @@ -1,2 +1,2 @@ # Copyright (c) OpenMMLab. All rights reserved. -__version__ = '0.6.0' +__version__ = '0.7.0'