- This is a project that provides a way to serve a TensorRT detection model using gRPC for communication.
- Currently the service only supports the model run under TensorRT framework, for the model running under
Detectron2(PyTorch)has not been implemented yet. - Dynamic shape is not enabled. If the size of your input image is different than what it was when building TensorRT engine, performance degradation is expecteing.
- The goal of this project is make DL group build environment, deploy model, develop feature and debug more easily.
| Model | Framework | Dataset |
|---|---|---|
| RGBDMaskRCNN | TensorRT | Karnak |
| RGBMaskRCNN | Torch | Honghe |
| RGBDMaskRCNN | Torch | Karnak |
-
Pull from container registry
docker pull registry.dorabot.com/evan/deep_detection:latest- Note that this docker image contains:
detectron2from https://gitlab.dorabot.com/vision/learning/detectron2/-/tree/feature/rgbd_maskrcnnTensorRT-8.4.2.4from https://gitlab.dorabot.com/Evan/tensorrt-8.4.2.4Torch==1.9.0&&TorchVision==0.10.0withCUDA 11.1
- Note that this docker image contains:
-
Build through
Dockerfilecd docker/ mkdir torch190cu111 && torch190cu111 `wget https://download.pytorch.org/whl/cu111/torch-1.9.0%2Bcu111-cp39-cp39-linux_x86_64.whl` `wget https://download.pytorch.org/whl/cu111/torchvision-0.10.0%2Bcu111-cp38-cp38-linux_x86_64.whl` cd ../ ./buildimage.sh
- Due to the way TensorRT generates
.engine, the.engineis likely not allowed to use across machines, so you need to generate.engineyourself and place intomodel_repositorybefore start the server if TensorRT feature is required. - For the steps of building TensorRT engine, please refer to this project.This project is not documented though. For understanding the basic pipeline of generating
TensorRT Engine, please refer to following .py file in order:export_model.pyfor converting pth to onnx.create_onnx.pyfor some additional plugin(roi align, nms, anchor generator) to make graph complete.build_engine.pyfor making TensorRT Engine,infer.pyfor running inference on PythonAPI from TensorRT.- For quick start, you can checkout and execute the files in the order of
export_model.sh,detectron2onnxtrt.shandbuild_engine.sh, in these three scripts, there some of params you need to configure on your own.
docker run --gpus all -d -p 50051:50051 \
-v [PATH_TO_NODE_CONFIG_FILE]:/home/bot/deep_detection/model_repository/[PATH_MAPS_NODE_CONFIG_FILE] \
-e NODE_CONFIG_FILE=model_repository/[PATH_MAPS_NODE_CONFIG_FILE] \
[DOCKER_IMAGE:TAG]
Note for -v and -e they both serve same purpose and does not have any default value, that being said you should always take care of this argument everytime you start the container.
Here's an example for quick start:
docker run --gpus all -d -p 50051:50051 \
-v /home/bot/deep_detection/model_repository/rgb_maskrcnn_torch/honghe/node_config.json:/home/bot/deep_detection/model_repository/rgb_maskrcnn_torch/honghe/node_config.json \
-e NODE_CONFIG_FILE=/home/bot/deep_detection/model_repository/rgb_maskrcnn_torch/honghe/node_config.json \
registry.dorabot.com/evan/deep_detection:latest
You can:
- ues
docker logs {CONTAINER_ID}to check if model is initialized or - use
-v {YOUR_LOCAL_PATH}:/home/bot/deep_detection/logsto check the logging message of server.
- Call the service(Running this both locally or inside container should work)
Note that
./client.sh {IMAGE_DIR_OR_FILE} {VIZ}{IMAGE_DIR_OR_FILE}could either be the folder or single image, if it's folder, it should be the root of color_image or (color_image, depth_image) depends on whether the depth data is used or not, otherwise it should be the full path of image.{VIZ}would store the result of visualization.- Although we have provided some example in
test_imgs, normally you should use-vto map your own data into container.
Here's an example for quick start:
./client.sh test_imgs/rgb/honghe
-
- Conda
-
Create conda env
conda create -n [YOUR_ENV_NMAE] python=3.8 -
Install torch and torchvision
- Install from source
python3 -m pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html- Install from this project
cd docker python3 -m pip install --no-cache-dir torch190cu111/*.whl -
Install packages
python3 -m pip install --no-cache-dir -r requirements.txt -
Install TensorRT
git clone git@gitlab.dorabot.com:Evan/tensorrt-8.4.2.4.git cd tensorrt-8.4.2.4 python3 -m pip install --no-cache-dir python/tensorrt-8.4.2.4-cp38-none-linux_x86_64.whl python3 -m pip install --no-cache-dir graphsurgeon/graphsurgeon-0.4.6-py2.py3-none-any.whl python3 -m pip install --no-cache-dir onnx_graphsurgeon/onnx_graphsurgeon-0.3.12-py2.py3-none-any.whl python3 -m pip install --no-cache-dir graphsurgeon/graphsurgeon-0.4.6-py2.py3-none-any.whl python3 -m pip install --no-cache-dir onnx_graphsurgeon/onnx_graphsurgeon-0.3.12-py2.py3-none-any.whl # Set up env var, export PATH=${PATH:+${PATH}}:[YOUR_TENSORRT_EXEC_PATH] # to run trtexec export LD_LIBRARY_PATH=[YOUR_TENSORRT_LIB_PATH]${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
- The
Pythonversion should match the version ofTensorRTpackage you installed insteps4. The suggested version and tested version isPython3.8 - The project has been tested with:
Conda=4.12.0Python=3.8Torch==1.9.0+cu111&&TorchVision==0.10.0+cu111CUDA=11.1CUDNN=8.0.5DRIVER=515.65.01TensorRT=8.4.2.4
-
- Conda
-
./launch.sh {PATH_NODE_CONFIG_FILE}Note that
{PATH_NODE_CONFIG_FILE}controls how everything works, you must put everything related to model is the same folder as{PATH_NODE_CONFIG_FILE}cd {dirname of {PATH_NODE_CONFIG_FILE}} tree . ├── categories.txt ├── depallet_50.yaml ├── model_best@2499.pth └── node_config.jsonwhere
node_config.json:{ "DETECTION_TYPE": "RGBDMaskRCNNTorchServicer", "MODEL_WEIGHT": "model_best@2499.pth", "CONFIG_FILE": "depallet_50.yaml", "MIN_SIZE": 416, "SCORE_THRESH_TEST": 0.8, "CATEGORY_FILE": "categories.txt" }Again, You need to put
"MODEL_WEIGHT","CONFIG_FILE"and"CATEGORY_FILE"in the same level asnode_config.json. -
./client.sh {IMAGE_DIR_OR_FILE} {VIZ}Note that
{IMAGE_DIR_OR_FILE}could either be the folder or single image, if it's folder, it should be the root of color_image or (color_image, depth_image) depends on whether the depth data is used or not, otherwise it should be the full path of image.{VIZ}would store the result of visualization.
-
All proto files are placed in
protos, you can add or update if needed, you then need to recompile proto files usingcompile.shinprotos, the generated.pywould be placed intoproto_build. -
You need to set
MAX_MESSAGE_LENGTHfor both client-side and server-side if your task is dense prediction or the input resolution is large. -
This projcet contains three main parts:
- server(
core/server)- In this secession, it would build the server based on the the variable
DETECTION_TYPEin yournode_config_file. - You must define
Callin your custom server, usually this function implements how you dopreprocess,inferenceandpostprocess.
- In this secession, it would build the server based on the the variable
- preprocess(
core/preprocess) - inference (
core/inference) - postprocess(
core/postprocess)- In this secession, you need to convert
detection_resulttogRPCmessage
- In this secession, you need to convert
- server(
- Support multiple calls at the same time.