dnth commited on
Commit
d9b80bc
·
verified ·
1 Parent(s): 643eb30

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +93 -0
README.md CHANGED
@@ -6,3 +6,96 @@ license: mit
6
 
7
  This repository contains code to optimize PyTorch image models using ONNX Runtime and TensorRT, achieving up to 8x faster inference speeds. Read the full blog post [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models/).
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  This repository contains code to optimize PyTorch image models using ONNX Runtime and TensorRT, achieving up to 8x faster inference speeds. Read the full blog post [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models/).
8
 
9
+ ## Installation
10
+ Create and activate a conda environment:
11
+
12
+ ```bash
13
+ conda create -n supercharge_timm_tensorrt python=3.11
14
+ conda activate supercharge_timm_tensorrt
15
+ ```
16
+ Install required packages:
17
+
18
+
19
+ ```bash
20
+ pip install timm
21
+ pip install onnx
22
+ pip install onnxruntime-gpu==1.19.2
23
+ pip install cupy-cuda12x
24
+ pip install tensorrt==10.1.0 tensorrt-cu12==10.1.0 tensorrt-cu12-bindings==10.1.0 tensorrt-cu12-libs==10.1.0
25
+ ```
26
+
27
+ Install CUDA dependencies:
28
+ ```bash
29
+ conda install -c nvidia cuda=12.2.2 cuda-tools=12.2.2 cuda-toolkit=12.2.2 cuda-version=12.2 cuda-command-line-tools=12.2.2 cuda-compiler=12.2.2 cuda-runtime=12.2.2
30
+ ```
31
+
32
+ Install cuDNN:
33
+ ```bash
34
+ conda install cudnn==9.2.1.18
35
+ ```
36
+
37
+ Set up library paths:
38
+ ```bash
39
+ export LD_LIBRARY_PATH="/home/dnth/mambaforge-pypy3/envs/supercharge_timm_tensorrt/lib:$LD_LIBRARY_PATH"
40
+ export LD_LIBRARY_PATH="/home/dnth/mambaforge-pypy3/envs/supercharge_timm_tensorrt/lib/python3.11/site-packages/tensorrt_libs:$LD_LIBRARY_PATH"
41
+ ```
42
+
43
+ ## Running the code
44
+
45
+ The following codes correspond to the steps in the blog post.
46
+
47
+ ### PyTorch latency benchmark:
48
+ ```bash
49
+ python 01_pytorch_latency_benchmark.py
50
+ ```
51
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-baseline-latency)
52
+
53
+ ### Convert model to ONNX:
54
+ ```bash
55
+ python 02_convert_to_onnx.py
56
+ ```
57
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-convert-to-onnx)
58
+
59
+ ### ONNX Runtime CPU inference:
60
+ ```bash
61
+ python 03_onnx_cpu_inference.py
62
+ ```
63
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-onnx-runtime-on-cpu)
64
+
65
+ ### ONNX Runtime CUDA inference:
66
+ ```bash
67
+ python 04_onnx_cuda_inference.py
68
+ ```
69
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-onnx-runtime-on-cuda)
70
+
71
+ ### ONNX Runtime TensorRT inference:
72
+ ```bash
73
+ python 05_onnx_trt_inference.py
74
+ ```
75
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-onnx-runtime-on-tensorrt)
76
+
77
+ ### Export preprocessing to ONNX:
78
+ ```bash
79
+ python 06_export_preprocessing_onnx.py
80
+ ```
81
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-bake-pre-processing-into-onnx)
82
+
83
+ ### Merge preprocessing and model ONNX:
84
+ ```bash
85
+ python 07_onnx_compose_merge.py
86
+ ```
87
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-bake-pre-processing-into-onnx)
88
+
89
+ ### Run inference on merged model:
90
+ ```bash
91
+ python 08_inference_merged_model.py
92
+ ```
93
+ Read more [here](https://dicksonneoh.com/portfolio/supercharge_your_pytorch_image_models//#-bake-pre-processing-into-onnx)
94
+
95
+ ### Run inference on video:
96
+ ```bash
97
+ python 09_video_inference.py sample.mp4 output.mp4 --live
98
+ ```
99
+
100
+ <video controls autoplay src="https://cdn-uploads.huggingface.co/production/uploads/6195f404c07573b03c61702c/lOmu7KaqrihRDVcQVJDi0.mp4"></video>
101
+