Skip to content

Commit 161e6b0

Browse files
authored
add detr (wang-xinyu#606)
* add detr * Update README.md
1 parent 7b85cfd commit 161e6b0

File tree

7 files changed

+1903
-0
lines changed

7 files changed

+1903
-0
lines changed

detr/CMakeLists.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 2.6)
2+
3+
project(detr)
4+
5+
add_definitions(-std=c++11)
6+
7+
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
8+
set(CMAKE_CXX_STANDARD 11)
9+
set(CMAKE_BUILD_TYPE Debug)
10+
11+
find_package(CUDA REQUIRED)
12+
13+
include_directories(${PROJECT_SOURCE_DIR}/include)
14+
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
15+
# cuda
16+
include_directories(/usr/local/cuda-10.2/include)
17+
link_directories(/usr/local/cuda-10.2/lib64)
18+
# tensorrt
19+
include_directories(/home/jushi/TensorRT-7.2.1.6/include)
20+
link_directories(/home/jushi/TensorRT-7.2.1.6/lib)
21+
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
23+
24+
find_package(OpenCV)
25+
include_directories(${OpenCV_INCLUDE_DIRS})
26+
27+
add_executable(detr ${PROJECT_SOURCE_DIR}/detr.cpp)
28+
target_link_libraries(detr nvinfer)
29+
target_link_libraries(detr cudart)
30+
target_link_libraries(detr ${OpenCV_LIBS})
31+
32+
add_definitions(-O2 -pthread)
33+

detr/README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# DETR
2+
3+
The Pytorch implementation is [facebookresearch/detr](https://github.com/facebookresearch/detr).
4+
5+
For details see [End-to-End Object Detection with Transformers](https://ai.facebook.com/research/publications/end-to-end-object-detection-with-transformers).
6+
7+
## Test Environment
8+
9+
- GTX2080Ti / Ubuntu16.04 / cuda10.2 / cudnn8.0.4 / TensorRT7.2.1 / OpenCV4.2
10+
- GTX2080Ti / win10 / cuda10.2 / cudnn8.0.4 / TensorRT7.2.1 / OpenCV4.2 / VS2017
11+
12+
## How to Run
13+
14+
1. generate .wts from pytorch with .pth
15+
16+
```
17+
// git clone https://github.com/facebookresearch/detr.git
18+
// go to facebookresearch/detr
19+
// download https://dl.fbaipublicfiles.com/detr/detr-r50-e632da11.pth
20+
// download https://raw.githubusercontent.com/freedenS/TestImage/main/demo.jpg
21+
// copy tensorrtx/detr/gen_wts.py and demo.jpg into facebookresearch/detr
22+
python gen_wts.py
23+
// a file 'detr.wts' will be generated.
24+
```
25+
26+
2. build tensorrtx/detr and run
27+
28+
```
29+
// put detr.wts into tensorrtx/detr
30+
// go to tensorrtx/detr
31+
// update parameters in detr.cpp if your model is trained on custom dataset.The parameters are corresponding to config in detr.
32+
mkdir build
33+
cd build
34+
cmake ..
35+
make
36+
sudo ./detr -s [.wts] // serialize model to plan file
37+
sudo ./detr -d [.engine] [image folder] // deserialize and run inference, the images in [image folder] will be processed
38+
// For example
39+
sudo ./detr -s ../detr.wts detr.engine
40+
sudo ./detr -d detr.engine ../samples
41+
```
42+
43+
3. check the images generated, as follows. _demo.jpg and so on.
44+
45+
## NOTE
46+
47+
- tensorrt use fixed input size, if the size of your data is different from the engine, you need to adjust your data and the result.
48+
- image preprocessing with c++ is a little different with python(opencv vs PIL)
49+
50+
51+
## Latency
52+
53+
average cost of doInference(in detr.cpp) from second time with batch=1 under the ubuntu environment above
54+
55+
| | fp32 | fp16 | int8 |
56+
| ---- | ------- | ------- | ---- |
57+
| R50 | 19.57ms | 9.424ms | TODO |
58+

0 commit comments

Comments
 (0)