MMDeploy-Benutzerhandbuch

MMDeploy-Benutzerhandbuch

Referenz :
Offizielles MMlab-Dokument
MMDeploy Deployment Actual Combat

1. Umgebungskonfiguration

1. Erstellen Sie die Conda-Umgebung von mmdeploy

conda create --name mmdeploy python=3.8 -y
conda activate mmdeploy
# pytorch安装
conda install pytorch=={pytorch_version} torchvision=={torchvision_version} cudatoolkit={cudatoolkit_version} -c pytorch -c conda-forge    

2. Installieren Sie MMCV

pip install -U openmim
mim install mmcv-full

3. Installieren Sie die MMDeploy-Operatorbibliothek und das Inferenz-SDK.
Die durch Export in den folgenden Installationsschritten importierten Umgebungsvariablen können in bashrc geschrieben werden oder ein lokales Skript schreiben und es wie erwähnt jedes Mal ausführen, wenn Sie die virtuelle Conda-Umgebung betreten später.

# 安装 MMDeploy ONNX Runtime 自定义算子库和推理 SDK
wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.8.0/mmdeploy-0.8.0-linux-x86_64-onnxruntime1.8.1.tar.gz
tar -zxvf mmdeploy-0.8.0-linux-x86_64-onnxruntime1.8.1.tar.gz
cd mmdeploy-0.8.0-linux-x86_64-onnxruntime1.8.1
pip install dist/mmdeploy-0.8.0-py3-none-linux_x86_64.whl
pip install sdk/python/mmdeploy_python-0.8.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
# 安装 MMDeploy TensorRT 自定义算子库和推理 SDK
wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.8.0/mmdeploy-0.8.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0.tar.gz
tar -zxvf mmdeploy-v0.8.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0.tar.gz
cd mmdeploy-0.8.0-linux-x86_64-cuda11.1-tensorrt8.2.3.0
pip install dist/mmdeploy-0.8.0-py3-none-linux_x86_64.whl
pip install sdk/python/mmdeploy_python-0.8.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 官网下载 cuDNN 8.2.1 CUDA 11.x 安装包并解压到当前目录
export CUDNN_DIR=$(pwd)/cuda
export LD_LIBRARY_PATH=$CUDNN_DIR/lib64:$LD_LIBRARY_PATH

4. Installieren und kompilieren Sie das MMDeploy-Projekt
注意下面的第二步

## 克隆 mmdeploy 仓库。转换时,需要使用 mmdeploy 仓库中的配置文件,建立转换流水线
git clone --recursive https://github.com/open-mmlab/mmdeploy.git
python -m pip install -r mmdeploy/requirements/runtime.txt  ## 注意,官方文档没有提到

## 编译Model Converter自定义算子库
cd mmdeploy
mkdir -p build && cd build
cmake -DCMAKE_CXX_COMPILER=g++ -DMMDEPLOY_TARGET_BACKENDS=trt -DONNXRUNTIME_DIR=${ONNXRUNTIME_DIR} ..  #服务器g++版本,9.4满足>7
make -j8 && make install

## 安装Model Converter
cd mmdeploy
pip install -e .

5. Installieren Sie mmdetection

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -v -e .
cd ..

2. Beispiel für die Modellkonvertierung

Schauen Sie sich einfach die offizielle Dokumentation an.

# 执行转换命令,实现端到端的转换,以下是我的实例
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 checkpoints/mmdeploy_model/faster-rcnn --device cuda:1 --dump-info

3. Fehlerbehebung

Q1 . ModuleNotFoundError: Kein Modul mit dem Namen „onnx“
A1 .

pip install onnx  -i https://pypi.douban.com/simple/

F2 . Importfehler: Der Name „create_calib_input_data“ kann nicht aus „mmdeploy.apis“ importiert werden.
A2 . Das offizielle Dokument erwähnt es nicht. Bitte installieren Sie es selbst

cd mmdeploy
python -m pip install -r mmdeploy/requirements/runtime.txt

F3 . TensorRT ist nicht verfügbar. Bitte installieren Sie TensorRT und erstellen Sie zuerst benutzerdefinierte TensorRT-Operationen. Andernfalls wurde das TRTBatchedNMS-Plugin nicht gefunden.
A3 . Die benutzerdefinierte Operatorbibliothek ist nicht installiert. Ich wähle hier das trt-Backend. Referenz: Compile Model Converter

# 先安装cmake>=3.14以上
wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.tar.gz
tar -xzvf cmake-3.20.0-linux-x86_64.tar.gz
sudo ln -sf $(pwd)/cmake-3.20.0-linux-x86_64/bin/* /usr/bin/
# 编译自定义算子库
cd mmdeploy
mkdir -p build && cd build
cmake -DCMAKE_CXX_COMPILER=g++ -DMMDEPLOY_TARGET_BACKENDS=trt -DONNXRUNTIME_DIR=${ONNXRUNTIME_DIR} ..  #服务器g++版本,9.4满足>7
make -j8 && make install

F4 : Beim Ausführen des Modellkonvertierungsskripts wird die Meldung angezeigt, dass kein Modul mit dem Namen „mmdeploy“ gefunden werden konnte.
A4 . Um mmdeploy zum Python-Suchpfad hinzuzufügen, können Sie den folgenden Inhalt in ~/.bashrc einfügen oder eine Skriptdatei schreiben und diese jedes Mal ausführen, wenn Sie die virtuelle Umgebung von openmmlab betreten.

#!/bin/bash
## onnxruntime
export ONNXRUNTIME_DIR=/workspace/Cuisc/onnxruntime-linux-x64-1.8.1
export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH

## TensorRT
export TENSORRT_DIR=/workspace/Cuisc/TensorRT-8.2.4.2
export LD_LIBRARY_PATH=${TENSORRT_DIR}/lib:$LD_LIBRARY_PATH

## CuDNN
export CUDNN_DIR=/workspace/Cuisc/cuda
export LD_LIBRARY_PATH=$CUDNN_DIR/lib64:$LD_LIBRARY_PATH

## MMDeploy
export PYTHONPATH=/workspace/Cuisc/mmdeploy:$PYTHONPATH

Acho que você gosta

Origin blog.csdn.net/weixin_36354875/article/details/127500332
Recomendado
Clasificación