-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* The v5-cls model supports TensorRT10 * The v5-cls model supports TensorRT10 Python API * add YOLOv5-cls readme * pre-commit and modify trtx download branch * pre-commit
- Loading branch information
Showing
20 changed files
with
2,572 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(yolov5) | ||
|
||
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 Debug) | ||
|
||
# TODO(Call for PR): make cmake compatible with Windows | ||
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc) | ||
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 | ||
# TODO(Call for PR): make TRT path configurable from command line | ||
include_directories(/workspace/shared/TensorRT-10.2.0.19/include/) | ||
link_directories(/workspace/shared/TensorRT-10.2.0.19/lib/) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}/src/) | ||
include_directories(${PROJECT_SOURCE_DIR}/plugin/) | ||
file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.cu) | ||
file(GLOB_RECURSE PLUGIN_SRCS ${PROJECT_SOURCE_DIR}/plugin/*.cu) | ||
|
||
add_library(myplugins SHARED ${PLUGIN_SRCS}) | ||
target_link_libraries(myplugins nvinfer cudart) | ||
|
||
find_package(OpenCV) | ||
include_directories(${OpenCV_INCLUDE_DIRS}) | ||
|
||
add_executable(yolov5_cls yolov5_cls.cpp ${SRCS}) | ||
target_link_libraries(yolov5_cls nvinfer) | ||
target_link_libraries(yolov5_cls cudart) | ||
target_link_libraries(yolov5_cls ${OpenCV_LIBS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
## Introduce | ||
|
||
Yolov5 model supports TensorRT-10. | ||
|
||
## Environment | ||
|
||
CUDA: 11.8 | ||
CUDNN: 8.9.1.23 | ||
TensorRT: TensorRT-10.2.0.19 | ||
|
||
## Support | ||
|
||
* [x] YOLOv5-cls support FP32/FP16/INT8 and Python/C++ API | ||
|
||
## Config | ||
|
||
* Choose the YOLOv5 sub-model n/s/m/l/x/n6/s6/m6/l6/x6 from command line arguments. | ||
* Other configs please check [src/config.h](src/config.h) | ||
|
||
## Build and Run | ||
|
||
1. generate .wts from pytorch with .pt, or download .wts from model zoo | ||
|
||
```shell | ||
git clone -b v7.0 https://github.com/ultralytics/yolov5.git | ||
git clone -b trt10 https://github.com/wang-xinyu/tensorrtx.git | ||
cd yolov5/ | ||
wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n.pt | ||
cp [PATH-TO-TENSORRTX]/yolov5/gen_wts.py . | ||
python gen_wts.py -w yolov5n.pt -o yolov5n.wts | ||
# A file 'yolov5n.wts' will be generated. | ||
``` | ||
|
||
2. build tensorrtx/yolov5/yolov5_trt10 and run | ||
|
||
#### Classification | ||
|
||
```shell | ||
cd [PATH-TO-TENSORRTX]/yolov5/yolov5_trt10 | ||
# Update kNumClass in src/config.h if your model is trained on custom dataset | ||
mkdir build | ||
cd build | ||
cp [PATH-TO-ultralytics-yolov5]/yolov5s.wts . | ||
cmake .. | ||
make | ||
|
||
# Download ImageNet labels | ||
wget https://github.com/joannzhang00/ImageNet-dataset-classes-labels/blob/main/imagenet_classes.txt | ||
|
||
# Build and serialize TensorRT engine | ||
./yolov5_cls -s yolov5n-cls.wts yolov5n-cls.engine [n/s/m/l/x] | ||
|
||
# Run inference | ||
./yolov5_cls -d yolov5n-cls.engine ../../images | ||
# The results are displayed in the console | ||
``` | ||
|
||
3. Optional, load and run the tensorrt model in Python | ||
```shell | ||
// Install python-tensorrt, pycuda, etc. | ||
// Ensure the yolov5n-cls.engine | ||
python yolov5_cls_trt.py | ||
``` | ||
|
||
## INT8 Quantization | ||
1. Prepare calibration images, you can randomly select 1000s images from your train set. For coco, you can also download my calibration images `coco_calib` from [GoogleDrive](https://drive.google.com/drive/folders/1s7jE9DtOngZMzJC1uL307J2MiaGwdRSI?usp=sharing) or [BaiduPan](https://pan.baidu.com/s/1GOm_-JobpyLMAqZWCDUhKg) pwd: a9wh | ||
2. unzip it in yolov5_trt10/build | ||
3. set the macro `USE_INT8` in src/config.h and make again | ||
4. serialize the model and test | ||
|
||
## More Information | ||
See the readme in [home page.](https://github.com/wang-xinyu/tensorrtx) |
Oops, something went wrong.