Skip to content

Commit

Permalink
🆕 support yolov7
Browse files Browse the repository at this point in the history
  • Loading branch information
Linaom1214 committed Jul 8, 2022
1 parent fd8c9c6 commit 5433b4d
Show file tree
Hide file tree
Showing 8 changed files with 1,180 additions and 5 deletions.
59 changes: 54 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
# YOLOv6、 YOLOX、 YOLOV5、 TensorRT Python/C++ API
## Update 2022.7.3 support TRT int8 post-training quantization
# YOLO Series TensorRT Python/C++

## Support
YOLOv7、YOLOv6、 YOLOX、 YOLOV5、

## Prepare TRT Python
## Update
- 2022.7.8 support YOLOV7
- 2022.7.3 support TRT int8 post-training quantization

## Prepare TRT Env
`Python`
```
pip install --upgrade setuptools pip --user
pip install nvidia-pyindex
pip install --upgrade nvidia-tensorrt
pip install pycuda
```
`C++`

[By Docker](https://github.com/NVIDIA/TensorRT/blob/main/docker/ubuntu-20.04.Dockerfile)

## Quick Start

Here is a Python Demo mybe help you quickly understand this repo [Link](https://aistudio.baidu.com/aistudio/projectdetail/4263301?contributionType=1&shared=1)

## YOLOv7 [C++, Python Support]

![](yolov7/3_yolov7.jpg)

```shell
https://github.com/WongKinYiu/yolov7.git
```
修改代码:将 yolo.py 对应行修改如下:
https://github.com/WongKinYiu/yolov7/blob/5f1b78ad614b45c5a98e7afdd295e20033d5ad3c/models/yolo.py#L57

```python
return x if self.training else (torch.cat(z, 1), ) if not self.export else (torch.cat(z, 1), x)
```

### 导出onnx
```shell
python models/export.py --weights ../yolov7.pt --grid
```

### 转化为TensorRT Engine

```
python export.py -o onnx-name -e trt-name -p fp32/16/int8
```
### 测试

```
cd yolov7
python trt.py
```

### C++

C++ [Demo](yolov7/cpp/README.md)





## YOLOv6 [C++, Python Support]

| model | input | | FPS | Device | Language |
Expand All @@ -22,7 +71,7 @@ Here is a Python Demo mybe help you quickly understand this repo [Link](https://
| yolov6s | 640*640 | FP32 | 330FPS | 1080Ti | C++ |
| yolov6s | 640*640 | FP32 | 300FPS | 1080Ti | Python |

[bilibili](https://www.bilibili.com/video/BV1x3411w7T6?share_source=copy_web)
[YOLOv6 bilibili](https://www.bilibili.com/video/BV1x3411w7T6?share_source=copy_web)

![](yolov6/3_yolov6.jpg)
```shell
Expand Down Expand Up @@ -117,4 +166,4 @@ python export.py -o onnx-name -e trt-name -p fp32/16/int8
```
cd yolov5
python trt.py
```
```
Binary file added yolov7/3_yolov7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions yolov7/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 2.6)

project(yolov7)

add_definitions(-std=c++11)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
# add_definitions("-Wall -g")
find_package(CUDA REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)
# tensorrt
include_directories(/usr/include/x86_64-linux-gnu/)
link_directories(/usr/lib/x86_64-linux-gnu/)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")

find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(yolov7 ${PROJECT_SOURCE_DIR}/yolov7.cpp)
target_link_libraries(yolov7 nvinfer)
target_link_libraries(yolov7 cudart)
target_link_libraries(yolov7 ${OpenCV_LIBS})

add_definitions(-O2 -pthread)
58 changes: 58 additions & 0 deletions yolov7/cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# YOLOV7-TensorRT in C++

## Step 1: 准备TRT序列化引擎

```shell
https://github.com/WongKinYiu/yolov7.git
```
### 导出onnx
```shell
python models/export.py --weights ../yolov7.pt --grid
```

### 转化为TensorRT Engine

```
python export.py -o onnx-name -e trt-name -p fp32/16/int8
```
### 测试

```
cd yolov7
python trt.py
```

## Step 2: C++

Please follow the [TensorRT Installation Guide](https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html) to install TensorRT.

And you should set the TensorRT path and CUDA path in CMakeLists.txt.

If you train your custom dataset, you may need to modify the value of `num_class`.

```c++
const int num_class = 80;
```

Install opencv with ```sudo apt-get install libopencv-dev``` (we don't need a higher version of opencv like v3.3+).

build the demo:

```shell
mkdir build
cd build
cmake ..
make
```

Then run the demo:

```shell
./yolov7 ../model_trt.engine -i ../../../../assets/dog.jpg
```

or

```shell
./yolov7 <path/to/your/engine_file> -i <path/to/image>
```
Binary file added yolov7/cpp/det_res.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5433b4d

Please sign in to comment.