Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DataXujing/Co-DETR-TensorRT

Repository files navigation

Co-DETR TensorRT Mo Xing Duan Dao Duan Jia Su Tui Li De C++Shi Xian

Xu Jing

0. Huan Jing Pei Zhi Shuo Ming

  • Ubuntu16.04Xia An Zhuang mmdetection, mmdeploy, Qi Yi Lai mmcvHe mmengine
# mmdetection==3.3.0
git clone -b 3.3.0 https://github.com/open-mmlab/mmdetection
pip install -v -e .

# mmcv
pip install mmcv==2.0.0

# mmdeploy
# https://github.com/TommyZihao/MMDeploy_Tutorials
git clone -b 1.3.1 https://github.com/open-mmlab/mmdeploy --recursive
# Bian Yi Bing An Zhuang MMDeploy(Hao Shi Da Yue Shi Fen Zhong )
python tools/scripts/build_ubuntu_x64_ort.py
  • windows TensorRTDe Huan Jing
    • TensorRT 8.5
    • cuda 11.0, cudnn
    • vs2017
    • cmake version 3.22.1
    • opencv

1.Co-DETR Zhuan ONNX

1.Xiu Gai Mo Xing Pei Zhi Wen Jian ,Guan Bi Ce Shi Guo Cheng Zhong De soft-nms(Hou Mian Yong EfficientNMS PluginDai Ti )

# mmdetection/projects/CO-DETR/configs/codino/co_dino_5scale_swin_l_16xb1_16e_o365tococo.py
#mmdetection/projects/CO-DETR/configs/codino/co_dino_5scale_r50_lsj_8xb2_1x_coco.py

test_cfg=[
# # Deferent from the DINO, we use the NMS.
dict(
max_per_img=300,
# NMS can improve the mAP by 0.2.
# nms=dict(type='soft_nms', iou_threshold=0.8)), # Guan Diao testGuo Cheng Zhong De soft nms
),

2.Xiu Gai mmdeployZhong Guan Yu onnxDe Dao Chu Pei Zhi

# mmdeploy/configs/_base_/onnx_config.py
onnx_config = dict(
type='onnx',
export_params=True,
keep_initializers_as_inputs=False,
opset_version=11, # opset Ban Ben
save_file='end2end.onnx', #Zhuan Chu onnxDe Bao Cun Ming Zi
input_names=['input'], # inputDe Ming Zi
output_names=['output'], # outputDe Ming Zi
input_shape=None,
optimize=True)
# mmdeploy/configs/mmdet/_base_/base_static.py

_base_ = ['../../_base_/onnx_config.py']

onnx_config = dict(output_names=['dets', 'labels'], input_shape=[640,640]) # static inputDe Da Xiao She Zhi Wei 640x640
codebase_config = dict(
type='mmdet',
task='ObjectDetection',
model_type='end2end',
post_processing=dict(
score_threshold=0.05,
confidence_threshold=0.005, # for YOLOv3
iou_threshold=0.5,
max_output_boxes_per_class=200,
pre_top_k=5000,
keep_top_k=100,
background_label_id=-1,
))

# co-dinoShi Yong Liao Duo Chi Du Xun Lian ,Zhe Li Wo Men Jiang test inputDe Chi Du She Wei 640x640,Jian Shao Ji Suan Liang

3.mmdeployZhuan onnx

python mmdeploy/tools/deploy.py \
mmdeploy/configs/mmdet/detection/detection_onnxruntime_stati c.py \
mmdetection/projects/CO-DETR/configs/codino/co_dino_5scale_s win_l_16xb1_16e_o365tococo.py \
mmdetection/checkpoints/co_dino_5scale_swin_large_16e_o365to coco-614254c9.pth \
mmdetection/demo/demo.jpg \
--work-dir mmdetection/checkpoints \
--device cpu
# Zhe Ge Guo Cheng Sheng Cheng Liao end2end.onnxDe ,Dan Shi onnxruntimeDe Shi Hou Huo Bao Cuo ,Bao Cuo De Yuan Yin Shi grid_samplerSuan Zi onnxruntimeHe tensorrtJun Bu Zhi Chi ,Shao Hou Hui Bian Yi tensorrt pluginJie Jue Gai Wei Wen Ti

4.Dui onnxJin Xing onnxsimHe fold constants

polygraphy surgeon sanitize end2end.onnx --fold-constants -o end2end_folded.onnx
python -m onnxsim end2end_folded.onnx end2end_folded_sim.onnx

Zhu Yi :

# Chang Liang Zhe Die He simplifierShe Ji Dao De Ku De Ban Ben
polygraphy==0.49.0
onnxruntime-gpu==1.19.2
onnx-simplifier=0.4.36

2. Windows Xia Dan Du Bian Yi mmdeployZhong Jin She Ji Co-DETRDe TensorRT Plugin

cmake_minimum_required(VERSION 2.6)

project(mmdeploy_plugins)

add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2")
add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX)

find_package(CUDA REQUIRED)

#if(WIN32)
#enable_language(CUDA)
#endif(WIN32)

# cuda
set(cuda_inc "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/include")
set(cuda_lib "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/lib/x64")
include_directories(${cuda_inc})
link_directories(${cuda_lib})
#cub
set(CUB_ROOT_DIR "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/include/cub")
include_directories(${CUB_ROOT_DIR})
# tensorrt
set(tensorrt_inc "D:/trt_install/TensorRT-8.5.1.7/include")
set(tensorrt_lib "D:/trt_install/TensorRT-8.5.1.7/lib")
include_directories(${tensorrt_inc})
link_directories(${tensorrt_lib})
# opencv
#include_directories("${PROJECT_SOURCE_DIR}/third_party/CV460_64/include")
#set(opencv_lib "${PROJECT_SOURCE_DIR}/third_party/CV460_64/lib/opencv_world460.lib")

# common files,Lai Yuan Yu mmdeploy
include_directories(common)

file(GLOB grid_sampler_src ${PROJECT_SOURCE_DIR}/grid_sampler/*.cpp ${PROJECT_SOURCE_DIR}/grid_sampler/*.cu)
cuda_add_library(trtgrid_sampler SHARED ${grid_sampler_src})
#cuda_add_library(trtgrid_sampler STATIC ${grid_sampler_src})
target_link_libraries(trtgrid_sampler nvinfer cudart)


file(GLOB topk_src ${PROJECT_SOURCE_DIR}/gather_topk/*.cpp ${PROJECT_SOURCE_DIR}/gather_topk/*.cu)
cuda_add_library(trtgather_topk SHARED ${topk_src})
#cuda_add_library(trtgather_topk STATIC ${topk_src})
target_link_libraries(trtgather_topk nvinfer cudart)


if(UNIX)
add_definitions(-O2 -pthread)
endif(UNIX)
  1. Da Kai vs studio 2017De Zhong Duan x64 Native Tools Command ...,cdDao Xiang Mu De Mu Lu Jin Xing Bian Yi

2.windowsXia Bian Yi TensorRT Plugin

mkdir build && cd build
cmake -G "NMake Makefiles" ..
nmake

Zai buildWen Jian Jia Xia Sheng Cheng Liao trtgrid_sampler.dllHe trtgather_topk.dll,Xia Mian Wo Men Hui Shi Yong trtgrid_sampler.dllDe plugin .

3.Co-DETR ONNX GraphXiu Gai He Bian Ji

Yuan Shi Dao Chu De Bu Bao Han nmsDe graph

Zhi Xing Bian Ji onnx graphDe Jiao Ben :

python co_detr_add_nms.py

Mo Xing Jie Gou Bian Wei :

4.WindowsXia Xu Lie Hua Co-DETR TensorRT engine

trtexec --onnx=end2end_foled_sim_nms.onnx --saveEngine=test_1.plan --workspace=60000 --verbose --plugins=./trtgrid_sampler.dll

5.mmdetectionZhong Co-DETRMo Xing Qian Chu Li Shi Xian De Fen Xi He C++Zhong Xie

mmdetection 3.3.0 co-dinoDe Qian Chu Li :

  • opencvDu Ru BGRTu Xiang

  • Deng Bi Li Suo Fang ,Chang Bian Suo Fang Dao 640,Suo Fang Fang Fa bilinear

  • normalize:

    mean=[123.675, 116.28, 103.53], # RGB
    std=[58.395, 57.12, 57.375], #RGB
  • BGR2RGB

  • Duan Bian You Xia Jiao Tian Chong Wei 0

C++Shi Xian Ru Xia :

//mmdetection3.3.0 co-detrQian Chu Li
void codetr::preprocess(cv::Mat &img, float data[]) {
int w, h, x, y;
float r_w = INPUT_W / (img.cols*1.0);
float r_h = INPUT_H / (img.rows*1.0);
if (r_h > r_w) {
w = INPUT_W;
h = r_w * img.rows;
}
else {
w = r_h * img.cols;
h = INPUT_H;
}
cv::Mat re(h, w, CV_8UC3);
cv::resize(img, re, re.size(), 0, 0, cv::INTER_LINEAR);
cv::Mat out(INPUT_H, INPUT_W, CV_8UC3, cv::Scalar(103, 116, 123)); //(0,0,0)Xiang Su Tian Chong
re.copyTo(out(cv::Rect(0, 0, re.cols, re.rows))); //You Xia Jiao

int i = 0;
for (int row = 0; row < INPUT_H; ++row) {
uchar* uc_pixel = out.data + row * out.step;
for (int col = 0; col < INPUT_W; ++col) {
data[i] = ((float)uc_pixel[2] - 123.675)/58.395; //R
data[i + INPUT_H * INPUT_W] = ((float)uc_pixel[1] - 116.28) / 57.12; //G
data[i + 2 * INPUT_H * INPUT_W] = ((float)uc_pixel[0] - 103.53)/ 57.375; //B

uc_pixel += 3;
++i;
}
}
}

6.Co-DETR TensorRT C++Shi Xian He Ce Shi

Zhu Yi C++Jia Zai Zi Ji Ding Yi De Plugin

bool didInitPlugins = initLibNvInferPlugins(nullptr, "");
void* handle_grid_sampler = LoadLibrary(L"trtgrid_sampler.dll");

TensorRT C++De Tui Li Demo:

bus.jpg zidane.jpg

7. LinuxRu He Bian Yi Gai Cheng Xu

  • Wo Ti Gong Liao Zai LinuxXia Bian Yi Co-DETRJin Xing Duan Dao Duan Tui Li De Dai Ma ,Qing Can Kao linux_cc/,Qi Zhong pluginWei grid_sampler pluginDe Bian Yi , co_detrWei Co-DETRDe TensorRTDiao Yong .

[!NOTE]\

  • Co-DETR TensorRTDe Shi Xian ,Keng Que Shi Bi Jiao Duo ,Can Kao De Wang Luo Zi Yuan Ji Ben Mei You
  • Wo Men Jiang soft-nmsSuan Zi Shan Chu ,Ti Huan Wei TensorRT EfficientNMS Plugin
  • Wo Men Zai windowsXia Bian Yi Liao TensorRT Plugin grid_sampler

Zui Zhong Cheng Gong Shi Xian Liao Co-DETRDe Duan Dao Duan De TensorRT Mo Xing Tui Li Yi Gou Ji Suan Jia Su Tui Li !

About

Quan Wang Shou Fa ,mmdetection Co-DETR TensorRTDuan Dao Duan Tui Li Jia Su

Resources

Readme

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors