Skip to content

Commit 96da069

Browse files
author
dujw
committed
add hard decode pybind
1 parent dfe904a commit 96da069

File tree

348 files changed

+53114
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+53114
-153
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ tutorial/2.0CenterNet_from_torch_trt/0_to_1_python_to_cuda/cpp_cuda_centernet/wo
6060
__pycache__
6161
/tools/process_so.sh
6262
/tools/proc2.sh
63-
/python/trtpy.egg-info
63+
/python/pytrt.egg-info
6464
/python/dist
6565
/python/build
6666
/workspace/formtest.ipynb

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"valarray": "cpp",
7777
"bit": "cpp",
7878
"__functional_base": "cpp",
79-
"locale": "cpp"
79+
"locale": "cpp",
80+
"__atomic": "cpp"
8081
},
8182
"workbench.tree.expandMode": "doubleClick"
8283
}

CMakeLists.txt

+30-23
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/workspace)
88
set(HAS_PYTHON OFF)
99

1010
# 如果要支持python则设置python路径
11-
set(PythonRoot "/data/datav/newbb/lean/anaconda3/envs/torch1.8")
11+
set(PythonRoot "/datav/software/anaconda3/envs/base")
1212
set(PythonName "python3.9")
1313

1414
# 如果你是不同显卡,请设置为显卡对应的号码参考这里:https://developer.nvidia.com/zh-cn/cuda-gpus#compute
1515
#set(CUDA_GEN_CODE "-gencode=arch=compute_75,code=sm_75")
1616

1717
# 如果你的opencv找不到,可以自己指定目录
18-
set(OpenCV_DIR "/data/datav/expstation/lean/opencv4.2.0/lib/cmake/opencv4/")
18+
set(OpenCV_DIR "/datav/lean/opencv-4.2.0/lib/cmake/opencv4/")
1919

20-
set(CUDA_TOOLKIT_ROOT_DIR "/data/sxai/lean/cuda-10.2")
21-
set(CUDNN_DIR "/data/sxai/lean/cudnn8.2.2.26")
22-
set(TENSORRT_DIR "/data/sxai/lean/TensorRT-8.0.1.6-cuda10.2-cudnn8.2")
20+
set(CUDA_TOOLKIT_ROOT_DIR "/datav/lean/cuda-11.2")
21+
set(CUDNN_DIR "/datav/lean/cudnn8.2.4.15-cuda11.4")
22+
set(TENSORRT_DIR "/datav/lean/TensorRT-8.2.3.0-cuda11.4-cudnn8.2")
2323

2424
# set(CUDA_TOOLKIT_ROOT_DIR "/data/sxai/lean/cuda-10.2")
2525
# set(CUDNN_DIR "/data/sxai/lean/cudnn7.6.5.32-cuda10.2")
@@ -30,7 +30,7 @@ set(TENSORRT_DIR "/data/sxai/lean/TensorRT-8.0.1.6-cuda10.2-cudnn8.2")
3030
# set(TENSORRT_DIR "/data/sxai/lean/TensorRT-7.2.1.6")
3131

3232
# 因为protobuf,需要用特定版本,所以这里指定路径
33-
set(PROTOBUF_DIR "/data/sxai/lean/protobuf3.11.4")
33+
set(PROTOBUF_DIR "/datav/lean/protobuf3.11.4")
3434

3535

3636
find_package(CUDA REQUIRED)
@@ -83,13 +83,13 @@ target_link_libraries(pro protobuf pthread plugin_list)
8383
target_link_libraries(pro ${OpenCV_LIBS})
8484

8585
if("${HAS_PYTHON}" STREQUAL "ON")
86-
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/python/trtpy)
87-
add_library(trtpyc SHARED ${cpp_srcs})
88-
target_link_libraries(trtpyc nvinfer nvinfer_plugin)
89-
target_link_libraries(trtpyc cuda cublas cudart cudnn)
90-
target_link_libraries(trtpyc protobuf pthread plugin_list)
91-
target_link_libraries(trtpyc ${OpenCV_LIBS})
92-
target_link_libraries(trtpyc "${PythonName}")
86+
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/example/python/pytrt)
87+
add_library(pytrtc SHARED ${cpp_srcs})
88+
target_link_libraries(pytrtc nvinfer nvinfer_plugin)
89+
target_link_libraries(pytrtc cuda cublas cudart cudnn)
90+
target_link_libraries(pytrtc protobuf pthread plugin_list)
91+
target_link_libraries(pytrtc ${OpenCV_LIBS})
92+
target_link_libraries(pytrtc "${PythonName}")
9393
target_link_libraries(pro "${PythonName}")
9494
endif()
9595

@@ -100,6 +100,13 @@ add_custom_target(
100100
COMMAND ./pro yolo
101101
)
102102

103+
add_custom_target(
104+
yolo_gpuptr
105+
DEPENDS pro
106+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/workspace
107+
COMMAND ./pro yolo_gpuptr
108+
)
109+
103110
add_custom_target(
104111
yolo_fast
105112
DEPENDS pro
@@ -172,35 +179,35 @@ add_custom_target(
172179

173180
add_custom_target(
174181
pyscrfd
175-
DEPENDS trtpyc
176-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python
182+
DEPENDS pytrtc
183+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/example/python
177184
COMMAND python test_scrfd.py
178185
)
179186

180187
add_custom_target(
181188
pyinstall
182-
DEPENDS trtpyc
183-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python
189+
DEPENDS pytrtc
190+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/example/python
184191
COMMAND python setup.py install
185192
)
186193

187194
add_custom_target(
188195
pytorch
189-
DEPENDS trtpyc
190-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python
196+
DEPENDS pytrtc
197+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/example/python
191198
COMMAND python test_torch.py
192199
)
193200

194201
add_custom_target(
195202
pyyolov5
196-
DEPENDS trtpyc
197-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python
203+
DEPENDS pytrtc
204+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/example/python
198205
COMMAND python test_yolov5.py
199206
)
200207

201208
add_custom_target(
202209
pycenternet
203-
DEPENDS trtpyc
204-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python
210+
DEPENDS pytrtc
211+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/example/python
205212
COMMAND python test_centernet.py
206213
)

Makefile

+24-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lean_tensor_rt := /datav/lean/TensorRT-8.2.3.0-cuda11.4-cudnn8.2
2020
lean_cudnn := /datav/lean/cudnn8.2.4.15-cuda11.4
2121
lean_opencv := /datav/lean/opencv-4.2.0
2222
lean_cuda := /datav/lean/cuda-11.2
23-
use_python := false
23+
use_python := true
2424
python_root := /datav/software/anaconda3
2525
python_name := python3.9
2626

@@ -77,7 +77,7 @@ ifneq ($(MAKECMDGOALS), clean)
7777
endif
7878

7979
pro : workspace/pro
80-
trtpyc : python/trtpy/libtrtpyc.so
80+
pytrtc : example-python/pytrt/libpytrtc.so
8181
expath : library_path.txt
8282

8383
library_path.txt :
@@ -88,7 +88,7 @@ workspace/pro : $(cpp_objs) $(cu_objs)
8888
@mkdir -p $(dir $@)
8989
@$(cc) $^ -o $@ $(link_flags)
9090

91-
python/trtpy/libtrtpyc.so : $(cpp_objs) $(cu_objs)
91+
example-python/pytrt/libpytrtc.so : $(cpp_objs) $(cu_objs)
9292
@echo Link $@
9393
@mkdir -p $(dir $@)
9494
@$(cc) -shared $^ -o $@ $(link_flags)
@@ -116,6 +116,9 @@ objs/%.cu.mk : src/%.cu
116116
yolo : workspace/pro
117117
@cd workspace && ./pro yolo
118118

119+
yolo_gpuptr : workspace/pro
120+
@cd workspace && ./pro yolo_gpuptr
121+
119122
dyolo : workspace/pro
120123
@cd workspace && ./pro dyolo
121124

@@ -179,38 +182,38 @@ lesson : workspace/pro
179182
plugin : workspace/pro
180183
@cd workspace && ./pro plugin
181184

182-
pytorch : trtpyc
183-
@cd python && python test_torch.py
185+
pytorch : pytrtc
186+
@cd example-python && python test_torch.py
184187

185-
pyscrfd : trtpyc
186-
@cd python && python test_scrfd.py
188+
pyscrfd : pytrtc
189+
@cd example-python && python test_scrfd.py
187190

188-
pyretinaface : trtpyc
189-
@cd python && python test_retinaface.py
191+
pyretinaface : pytrtc
192+
@cd example-python && python test_retinaface.py
190193

191-
pycenternet : trtpyc
192-
@cd python && python test_centernet.py
194+
pycenternet : pytrtc
195+
@cd example-python && python test_centernet.py
193196

194-
pyyolov5 : trtpyc
195-
@cd python && python test_yolov5.py
197+
pyyolov5 : pytrtc
198+
@cd example-python && python test_yolov5.py
196199

197-
pyyolox : trtpyc
198-
@cd python && python test_yolox.py
200+
pyyolox : pytrtc
201+
@cd example-python && python test_yolox.py
199202

200-
pyarcface : trtpyc
201-
@cd python && python test_arcface.py
203+
pyarcface : pytrtc
204+
@cd example-python && python test_arcface.py
202205

203-
pyinstall : trtpyc
204-
@cd python && python setup.py install
206+
pyinstall : pytrtc
207+
@cd example-python && python setup.py install
205208

206209
clean :
207-
@rm -rf objs workspace/pro python/trtpy/libtrtpyc.so python/build python/dist python/trtpy.egg-info python/trtpy/__pycache__
210+
@rm -rf objs workspace/pro example-python/pytrt/libpytrtc.so example-python/build example-python/dist example-python/pytrt.egg-info example-python/pytrt/__pycache__
208211
@rm -rf workspace/single_inference
209212
@rm -rf workspace/scrfd_result workspace/retinaface_result
210213
@rm -rf workspace/YoloV5_result workspace/YoloX_result
211214
@rm -rf workspace/face/library_draw workspace/face/result
212215
@rm -rf build
213-
@rm -rf python/trtpy/libplugin_list.so
216+
@rm -rf example-python/pytrt/libplugin_list.so
214217
@rm -rf library_path.txt
215218

216219
.PHONY : clean yolo alphapose fall debug

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
3535
- Python Interface:
3636
```python
37-
import trtpy
37+
import pytrt
3838
3939
model = models.resnet18(True).eval().to(device)
4040
trt_model = tp.from_torch(model, input)
@@ -46,7 +46,7 @@
4646
import os
4747
import cv2
4848
import numpy as np
49-
import trtpy as tp
49+
import pytrt as tp
5050

5151
engine_file = "yolov5s.fp32.trtmodel"
5252
if not os.path.exists(engine_file):
@@ -222,7 +222,7 @@
222222
- CMakeLists.txt:
223223
- `set(HAS_PYTHON ON)` in CMakeLists.txt
224224
- Type in `make pyinstall -j8`
225-
- Complied files are in `python/trtpy/libtrtpyc.so`
225+
- Complied files are in `python/pytrt/libpytrtc.so`
226226

227227
</details>
228228

@@ -247,11 +247,11 @@
247247
<summary>Windows: Compile for Python</summary>
248248

249249

250-
1. Compile trtpyc.pyd. Choose python in visual studio to compile
251-
2. Copy dll and execute 'python/copy_dll_to_trtpy.bat'
250+
1. Compile pytrtc.pyd. Choose python in visual studio to compile
251+
2. Copy dll and execute 'python/copy_dll_to_pytrt.bat'
252252
3. Execute the example in python dir by 'python test_yolov5.py'
253253
- if installation is needed, switch to target env(e.g. your conda env) then 'python setup.py install', which has to be followed by step 1 and step 2.
254-
- the compiled files are in `python/trtpy/libtrtpyc.pyd`
254+
- the compiled files are in `python/pytrt/libpytrtc.pyd`
255255

256256
</details>
257257

@@ -677,10 +677,10 @@ check the great details in tutorial/2.0
677677

678678
- Just one line of code to export onnx and trtmodel. And save them for usage in the future.
679679
```python
680-
import trtpy
680+
import pytrt
681681

682682
model = models.resnet18(True).eval()
683-
trtpy.from_torch(
683+
pytrt.from_torch(
684684
model,
685685
dummy_input,
686686
max_batch_size=16,
@@ -696,7 +696,7 @@ trtpy.from_torch(
696696

697697
- YoloX TensorRT Inference
698698
```python
699-
import trtpy
699+
import pytrt
700700

701701
yolo = tp.Yolo(engine_file, type=tp.YoloType.X) # engine_file is the trtmodel file
702702
image = cv2.imread("inference/car.jpg")
@@ -705,7 +705,7 @@ bboxes = yolo.commit(image).get()
705705

706706
- Seamless Inference from Pytorch to TensorRT
707707
```python
708-
import trtpy
708+
import pytrt
709709

710710
model = models.resnet18(True).eval().to(device) # pt model
711711
trt_model = tp.from_torch(model, input)

README.zh-cn.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ auto box = engine->commit(image).get(); // 得到的是vector<Box>
3333
3434
- Python接口
3535
```python
36-
import trtpy
36+
import pytrt as tp
3737
3838
model = models.resnet18(True).eval().to(device)
3939
trt_model = tp.from_torch(model, input)
@@ -45,7 +45,7 @@ trt_out = trt_model(input)
4545
import os
4646
import cv2
4747
import numpy as np
48-
import trtpy as tp
48+
import pytrt as tp
4949

5050
engine_file = "yolov5s.fp32.trtmodel"
5151
if not os.path.exists(engine_file):
@@ -225,7 +225,7 @@ trt_out = trt_model(input)
225225
- CMakeLists.txt方式:
226226
- 在CMakeLists.txt中修改`set(HAS_PYTHON ON)`
227227
- 执行编译`make pyinstall -j8`
228-
- 编译后的文件,在`python/trtpy/libtrtpyc.so`
228+
- 编译后的文件,在`python/pytrt/libpytrtc.so`
229229

230230
</details>
231231

@@ -240,18 +240,18 @@ trt_out = trt_model(input)
240240
- 根据型号参考这里:https://developer.nvidia.com/zh-cn/cuda-gpus#compute
241241
5. 配置依赖或者下载依赖到lean中。配置VC++目录->包含目录和引用目录
242242
6. 配置环境,调试->环境,设置PATH路径
243-
7. 编译并运行案例,其中Debug为调试,Release为发布,Python为trtpyc模块
243+
7. 编译并运行案例,其中Debug为调试,Release为发布,Python为pytrtc模块
244244

245245
</details>
246246

247247
<details>
248248
<summary>Windows下Python编译</summary>
249249

250-
1. 编译trtpyc.pyd,在visual studio中选择python进行编译
251-
2. 复制dll,执行python/copy_dll_to_trtpy.bat
250+
1. 编译pytrtc.pyd,在visual studio中选择python进行编译
251+
2. 复制dll,执行python/copy_dll_to_pytrt.bat
252252
3. 在python目录下执行案例,python test_yolov5.py
253253
- 如果需要进行安装,则在python目录下,切换到目标环境后,执行`python setup.py install`。(注意,执行了1、2两步后才行)
254-
- 编译后的文件,在`python/trtpy/libtrtpyc.pyd`
254+
- 编译后的文件,在`python/pytrt/libpytrtc.pyd`
255255

256256
</details>
257257

@@ -658,10 +658,10 @@ cout << feature << endl; // 1x512
658658
659659
- 使用Python接口可以一句话导出Onnx和trtmodel,一次性调试发生的问题,解决问题。并储存onnx为后续部署使用
660660
```python
661-
import trtpy
661+
import pytrt
662662
663663
model = models.resnet18(True).eval()
664-
trtpy.from_torch(
664+
pytrt.from_torch(
665665
model,
666666
dummy_input,
667667
max_batch_size=16,
@@ -677,7 +677,7 @@ trtpy.from_torch(
677677
678678
- YoloX的tensorRT推理
679679
```python
680-
import trtpy
680+
import pytrt
681681
682682
yolo = tp.Yolo(engine_file, type=tp.YoloType.X)
683683
image = cv2.imread("inference/car.jpg")
@@ -686,7 +686,7 @@ bboxes = yolo.commit(image).get()
686686
687687
- Pytorch的无缝对接
688688
```python
689-
import trtpy
689+
import pytrt
690690
691691
model = models.resnet18(True).eval().to(device)
692692
trt_model = tp.from_torch(model, input)

0 commit comments

Comments
 (0)