Skip to content

Commit

Permalink
initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
xulei_tao committed Apr 29, 2021
0 parents commit 58c592c
Show file tree
Hide file tree
Showing 207 changed files with 31,749 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### 我爱996

#### 我们的工作共分为三部分:

##### 一、训练FasterRCNN模型

>详情请阅读tf-faster-rcnn中的README.md
##### 二、tf模型转换Onnx模型

>详情请阅读tf-faster-rcnn中的faster_rcnn模型转化.md
##### 三、TensorRT加速

>详情请阅读TensorRT-Base中的README.md


8 changes: 8 additions & 0 deletions TensorRT-Base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##ignore this file##
bin/Release/*
build/*
lib/Release/*
lib/*.so
mnist_onnx/model/model.onnx
faster_rcnn/model/VGG16_faster_rcnn_final.caffemodel
faster_rcnn/model/faster_rcnn.bin
26 changes: 26 additions & 0 deletions TensorRT-Base/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
// "/usr/local/opencv/include",
// "/usr/local/opencv/include/opencv",
// "/usr/local/opencv/include/opencv2",
// "/usr/local/cuda/include",
// "/opt/TensorRT-7.2.2.3/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
87 changes: 87 additions & 0 deletions TensorRT-Base/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"files.associations": {
"iosfwd": "cpp",
"iostream": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"numeric": "cpp",
"ratio": "cpp",
"cstring": "cpp",
"xstring": "cpp",
"cmath": "cpp",
"array": "cpp",
"atomic": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"ios": "cpp",
"locale": "cpp",
"queue": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"complex": "cpp",
"set": "cpp",
"bitset": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"filesystem": "cpp",
"mutex": "cpp",
"thread": "cpp",
"__nullptr": "cpp",
"bit": "cpp",
"compare": "cpp",
"concepts": "cpp",
"stack": "cpp",
"stop_token": "cpp"
}
}
76 changes: 76 additions & 0 deletions TensorRT-Base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# @file - CMakeLists.txt
# @author - wdn ([email protected])
# @brief - 工程编译文件
#
# @copyright Copyright (c) 2021, wdn. All rights reserved.

cmake_minimum_required(VERSION 3.0)

project("tensorrt_base")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

if(WIN32)
set(CUDA_ROOT_DIR "D:/Software/CUDA11.0/development")
set(TRT_ROOT_DIR "D:/Software/CUDA11.0/development")

# cuda
set(CUDA_INCLUDE_DIR ${CUDA_ROOT_DIR}/include)
set(CUDA_LIB_DIR ${CUDA_ROOT_DIR}/lib/x64)
file(GLOB CUDA_LIBRARIRS "${CUDA_ROOT_DIR}/lib/x64/*.lib")

# tensorrt
set(TRT_INCLUDE_DIR ${TRT_ROOT_DIR}/include)
set(TRT_LIB_DIR ${TRT_ROOT_DIR}/lib/x64)
file(GLOB TRT_LIBRARIRS "${TRT_ROOT_DIR}/lib/x64/*.lib")

else()


set(CUDA_ROOT_DIR "/usr/local/cuda")
set(TRT_ROOT_DIR "/opt/TensorRT-7.2.2.3")

# cuda
set(CUDA_INCLUDE_DIR ${CUDA_ROOT_DIR}/include)
set(CUDA_LIB_DIR ${CUDA_ROOT_DIR}/lib64)
file(GLOB CUDA_LIBRARIRS "${CUDA_ROOT_DIR}/lib64/*.so")

# tensorrt
set(TRT_INCLUDE_DIR ${TRT_ROOT_DIR}/include)
set(TRT_LIB_DIR ${TRT_ROOT_DIR}/lib)
file(GLOB TRT_LIBRARIRS "${TRT_ROOT_DIR}/lib/*.so")

endif()

if(WIN32)
# Socket limit is 16K(can be raised arbitrarily)
add_definitions(-DFD_SETSIZE=16384)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()

# opencv
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

include_directories(${CUDA_INCLUDE_DIR} ${TRT_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS})
include_directories(common plugin)
link_directories(${CUDA_LIB_DIR} ${TRT_LIB_DIR})

# 包含子项目。
add_subdirectory ("common")
add_subdirectory ("plugin")
add_subdirectory ("mnist_caffe")
add_subdirectory ("mnist_onnx")
add_subdirectory ("faster_rcnn")



113 changes: 113 additions & 0 deletions TensorRT-Base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# TensorRT Base

## 1.Description
该项目封装TensorRT加速深度学习模型,支持caffe和onnx格式模型。

主要来自TensorRT C++ sample及部分Github参考代码。

# 2.Environment

推荐使用Ubuntu运行

## 2.1 Ubuntu

* TensorRT 7+
* GUN工具(g++ 7.5.0)
* CMake工具(3.10+)

## 2.2 Windows

* TensorRT 7+
* Visual Studio 2017
* CMake工具(3.10+)

# 3.Directory

```
├── bin: 生成可执行文件目录
├── build: CMake工具构建目录
├── common: TensorRT基础类和一些共用函数,编译为库供调用
├── lib: 生成库目录
├── plugin: TensorRT plugin目录,用于存放自定义plugin
├── CMakeLists.txt: 根目录CMake配置文件
├── mnist_caffe: TensorRT解析caffe模型demo
├── mnist_onnx: TensorRT解析ONNX模型demo
└── faster_rcnn: TensoRT加速Faster RCNN算法
```

# 4.Running

修改根目录下CMakeLists.txt文件中`CUDA``TensorRT`目录,cudnn默认和CUDA安装在同一目录下。

```cmake
set(CUDA_ROOT_DIR "D:/Software/CUDA11.0/development")
set(TRT_ROOT_DIR "D:/Software/CUDA11.0/development")
```

运行以下命令

```shell
cd TensorRT-Base
mkdir build
cd build
cmake ..
make
```

编译完成后,在bin文件夹中会生成可执行文件,lib目录下会生成库文件,由于Windows环境下配置动态库较麻烦,默认生成静态库,可自己修改。

运行bin文件夹中可执行文件,即可加速深度学习模型,以faster rcnn demo为例

```shell
PS E:\TensorRT-Base> .\bin\Release\faster_rcnn.exe
[2021-04-25 20:48:32][ WARN ] : Dynamic size input setting invalid!
[2021-04-25 20:48:32][ DEBUG ] : deserialize engine from faster_rcnn/model/faster_rcnn.bin
[2021-04-25 20:48:38][ DEBUG ] : max batch size of deserialized engine: 1
[2021-04-25 20:48:38][ DEBUG ] : create execute context and malloc device memory...
[2021-04-25 20:48:38][ DEBUG ] : init engine...
[2021-04-25 20:48:38][ DEBUG ] : malloc device memory
[2021-04-25 20:48:38][ DEBUG ] : nbBingdings: 5
[2021-04-25 20:48:38][ DEBUG ] : input:
[2021-04-25 20:48:38][ DEBUG ] : binding bindIndex: 0, name: data, size in byte: 2250000
[2021-04-25 20:48:38][ DEBUG ] : binding dims with 3 dimemsion
[2021-04-25 20:48:38][ DEBUG ] : input:
[2021-04-25 20:48:38][ DEBUG ] : binding bindIndex: 1, name: im_info, size in byte: 12
[2021-04-25 20:48:38][ DEBUG ] : binding dims with 3 dimemsion
[2021-04-25 20:48:38][ DEBUG ] : output:
[2021-04-25 20:48:38][ DEBUG ] : binding bindIndex: 2, name: rois, size in byte: 4800
[2021-04-25 20:48:38][ DEBUG ] : binding dims with 3 dimemsion
[2021-04-25 20:48:38][ DEBUG ] : output:
[2021-04-25 20:48:38][ DEBUG ] : binding bindIndex: 3, name: bbox_pred, size in byte: 100800
[2021-04-25 20:48:38][ DEBUG ] : binding dims with 4 dimemsion
[2021-04-25 20:48:38][ DEBUG ] : output:
[2021-04-25 20:48:38][ DEBUG ] : binding bindIndex: 4, name: cls_prob, size in byte: 25200
[2021-04-25 20:48:38][ DEBUG ] : binding dims with 4 dimemsion
[2021-04-25 20:48:38][ WARN ] : output_bbox_pred: 25200
[2021-04-25 20:48:38][ WARN ] : output_cls_prob: 6300
[2021-04-25 20:48:38][ WARN ] : output_rois: 1200
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 aeroplane
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 bicycle
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 bird
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 boat
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 bottle
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 bus
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 car
[2021-04-25 20:48:38][ INFO ] : indices size is: 1 cat
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 chair
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 cow
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 diningtable
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 dog
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 horse
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 motorbike
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 person
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 pottedplant
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 sheep
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 sofa
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 train
[2021-04-25 20:48:38][ INFO ] : indices size is: 0 tvmonitor
```





1 change: 1 addition & 0 deletions TensorRT-Base/bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 生成可执行文件目录
24 changes: 24 additions & 0 deletions TensorRT-Base/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @file - common/CMakeLists.txt
# @author - wdn ([email protected])
# @brief - common编译文件
#
# Copyright (c) 2021, wdn. All rights reserved.

cmake_minimum_required (VERSION 3.0)

project ("common")

# aux_source_directory(. COMMON_SRC)
file(GLOB COMMON_SOURCE *.cpp )

# file(GLOB_RECURSE trt_source "helper.h" "helper.cpp" "logging.h" "timer.h")

add_library(common STATIC ${COMMON_SOURCE})

# 链接库
target_link_libraries(
common PRIVATE
trt_plugin
${CUDA_LIBRARIRS}
${TRT_LIBRARIRS}
)
Loading

0 comments on commit 58c592c

Please sign in to comment.