Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yolov5-obb tensorrt deployment #558

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.10)

project(yolov5_obb)

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)

find_package(CUDA REQUIRED)

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



include_directories(${PROJECT_SOURCE_DIR}/include)
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})

find_package(CUDA REQUIRED)
message(STATUS " libraries: ${CUDA_LIBRARIES}")
message(STATUS " include path: ${CUDA_INCLUDE_DIRS}")
include_directories(${CUDA_INCLUDE_DIRS})
enable_language(CUDA)

# 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 -g -D_MWAITXINTRIN_H_INCLUDED")#-Wfatal-errors
cuda_add_library(myplugins SHARED yololayer.cu)
target_link_libraries(myplugins nvinfer cudart)


cuda_add_executable(yolov5_gen yolov5_gen.cpp)

target_link_libraries(yolov5_gen nvinfer)
target_link_libraries(yolov5_gen cudart)
target_link_libraries(yolov5_gen myplugins)
target_link_libraries(yolov5_gen ${OpenCV_LIBS})

cuda_add_executable(yolov5_use yolov5_use.cpp)

target_link_libraries(yolov5_use nvinfer)
target_link_libraries(yolov5_use cudart)
target_link_libraries(yolov5_use myplugins)
target_link_libraries(yolov5_use ${OpenCV_LIBS})


if(UNIX)
add_definitions(-O2 -pthread)
endif(UNIX)


86 changes: 30 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,44 @@
# Yolov5 for Oriented Object Detection
![图片](./docs/detection.png)
![train_batch0.jpg](./docs/train_batch6.jpg)
![results.png](./docs/results.png)
# yolov5_for_oriented_object_detection

The code for the implementation of “[Yolov5](https://github.com/ultralytics/yolov5) + [Circular Smooth Label](https://arxiv.org/abs/2003.05597v2)”.
The Pytorch implementation is [yolov5_obb](https://github.com/hukaixuan19970627/yolov5_obb )

# Results and Models
The results on **DOTA_subsize1024_gap200_rate1.0** test-dev set are shown in the table below. (**password: yolo**)
actually ,This repo is based on [yolov5](https://github.com/ultralytics/yolov5/tree/v6.0/) and only used at Linux PC (partial dependency install hardly at windows PC)

|Model<br><sup>(download link) |Size<br><sup>(pixels) | TTA<br><sup>(multi-scale/<br>rotate testing) | OBB mAP<sup>test<br><sup>0.5<br>DOTAv1.0 | OBB mAP<sup>test<br><sup>0.5<br>DOTAv1.5 | OBB mAP<sup>test<br><sup>0.5<br>DOTAv2.0 | Speed<br><sup>CPU b1<br>(ms)|Speed<br><sup>2080Ti b1<br>(ms) |Speed<br><sup>2080Ti b16<br>(ms) |params<br><sup>(M) |FLOPs<br><sup>@640 (B)
| ---- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
|yolov5m [[baidu](https://pan.baidu.com/s/1UPNaMuQ_gNce9167FZx8-w)/[google](https://drive.google.com/file/d/1NMgxcN98cmBg9_nVK4axxqfiq4pYh-as/view?usp=sharing)] |1024 | × |**77.3** |**73.2** |**58.0** |**328.2** |**16.9** |**11.3** |**21.6** |**50.5**
|yolov5s [[baidu](https://pan.baidu.com/s/1Lqw42xlSZxZn-2gNniBpmw?pwd=yolo)] |1024 | × |**76.8** |- |- |- |**15.6** | - |**7.5** |**17.5**
|yolov5n [[baidu](https://pan.baidu.com/s/1Lqw42xlSZxZn-2gNniBpmw?pwd=yolo)] |1024 | × |**73.3** |- |- |- |**15.2** | - |**2.0** |**5.0**
## How to Run, yolov5s as example

1. generate .wts from pytorch with .pt

<details>
<summary>Table Notes (click to expand / **点我看更多**)</summary>
```
// clone code according to above #Different versions of yolov5
train and gen best.pt at runs/train/exp[]/weights/
cp gen_wts.py {yolov5_obb}
python gen_wts.py -w runs/train/exp[]/weights/best.pt -o yolov5s.wts
// a file 'yolov5s.wts' will be generated.
```

* All checkpoints are trained to 300 epochs with [COCO pre-trained checkpoints](https://github.com/ultralytics/yolov5/releases/tag/v6.0), default settings and hyperparameters.
* **mAP<sup>test dota</sup>** values are for single-model single-scale on [DOTA](https://captain-whu.github.io/DOTA/index.html)(1024,1024,200,1.0) dataset.<br>Reproduce Example:
```shell
python val.py --data 'data/dotav15_poly.yaml' --img 1024 --conf 0.01 --iou 0.4 --task 'test' --batch 16 --save-json --name 'dotav15_test_split'
python tools/TestJson2VocClassTxt.py --json_path 'runs/val/dotav15_test_split/best_obb_predictions.json' --save_path 'runs/val/dotav15_test_split/obb_predictions_Txt'
python DOTA_devkit/ResultMerge_multi_process.py --scrpath 'runs/val/dotav15_test_split/obb_predictions_Txt' --dstpath 'runs/val/dotav15_test_split/obb_predictions_Txt_Merged'
zip the poly format results files and submit it to https://captain-whu.github.io/DOTA/evaluation.html
```
* **Speed** averaged over DOTAv1.5 val_split_subsize1024_gap200 images using a 2080Ti gpu. NMS + pre-process times is included.<br>Reproduce by `python val.py --data 'data/dotav15_poly.yaml' --img 1024 --task speed --batch 1`
2. build **tensorr engine **

```
// update CLASS_NUM in yololayer.h
// caution:CLASS_NUM= your classes +180(180 for angle classes)
mkdir build
cd build
cp {yolov5_obb}/yolov5s.wts ../yolov5s.wts
cmake ..
make
sudo ./yolov5_gen -s [.wts] [.engine] [n/s/m/l/x] // serialize model to plan file
// For example yolov5s
sudo ./yolov5_gen -s ../yolov5s.wts ../yolov5s.engine s
```

</details>
3. use **tensorr engine**

# [Updates](./docs/ChangeLog.md)
- [2022/1/7] : **Faster and stronger**, some bugs fixed, yolov5 base version updated.

```
sudo ./yolov5_use ../../yolov5s.engine ../../images/mytest.png
```

# Installation
Please refer to [install.md](./docs/install.md) for installation and dataset preparation.
![image-20220402142552499](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220402142552499.png)

# Getting Started
This repo is based on [yolov5](https://github.com/ultralytics/yolov5).

And this repo has been rebuilt, Please see [GetStart.md](./docs/GetStart.md) for the Oriented Detection latest basic usage.

# Acknowledgements
I have used utility functions from other wonderful open-source projects. Espeicially thank the authors of:

* [ultralytics/yolov5](https://github.com/ultralytics/yolov5).
* [Thinklab-SJTU/CSL_RetinaNet_Tensorflow](https://github.com/Thinklab-SJTU/CSL_RetinaNet_Tensorflow).
* [jbwang1997/OBBDetection](https://github.com/jbwang1997/OBBDetection)
* [CAPTAIN-WHU/DOTA_devkit](https://github.com/CAPTAIN-WHU/DOTA_devkit)
## More detailed explanation
想要了解相关实现的细节和原理可以看我的知乎文章:
* [自己改建YOLOv5旋转目标的踩坑记录](https://www.zhihu.com/column/c_1358464959123390464).

## 有问题反馈
在使用中有任何问题,建议先按照[install.md](./docs/install.md)检查环境依赖项,再按照[GetStart.md](./docs/GetStart.md)检查使用流程是否正确,善用搜索引擎和github中的issue搜索框,可以极大程度上节省你的时间。

若遇到的是新问题,可以用以下联系方式跟我交流,为了提高沟通效率,请尽可能地提供相关信息以便我复现该问题。

* 知乎(@[略略略](https://www.zhihu.com/people/lue-lue-lue-3-92-86))
* 代码问题提issues,其他问题请知乎上联系

## 关于作者

```javascript
Name : "胡凯旋"
describe myself:"咸鱼一枚"

Loading