# Tensorrt-int8-quantization-pipline
a simple pipline of int8 quantization based on tensorrt.
## Example for classification <a name="classification"></a>
```
cd classification
```
#### 1、Choose a model and prepare a calibration dataset,like resnet101 training from imagenet1k.
```
wget https://hanlab.mit.edu/files/OnceForAll/ofa_cvpr_tutorial/imagenet_1k.zip
unzip 'imagenet_1k.zip'
mkdir model
```
#### 2、eval the float32 model performance.
```
python test_torch.py
```
#### 3、convert to onnx model.
```
python torch2onnx.py
```
#### 4、 quantization int8 trt model.
```
python quantization.py
```
#### 5、eval the int8 model performance.
```
python test_int8trt.py
```
or run a pipline including the above steps.
```
python tensorrt_PTA_classification_pipline.py
```
<img src="./classification/shot.jpg" width="400px" height="380px">
| model | accuracy | time | size |
| :-: |:-:| :-:|:-:|
| float32(pth)|0.759 | 0.0799 |171M|
| int8(trt)|0.738 | 0.0013 | 44M |
#### Note
You can replace resnet101 with your network. If your dataset structure is different, you need to modify some code about dataset.
```
# test_torch.py torch2onnx.py quantization.py
if __name__ == "__main__":
net = models.resnet101(pretrained=True).to('cpu')
```
or
```
# tensorrt_PTA_classification_pipline.py
if __name__ == "__main__":
net = models.resnet101(pretrained=True).to('cpu')
```
## Example for detection <a name="detection"></a>
```
cd detection
```
#### 1、Choose a model and test inference,like YOLOX-s.
```
wget wget https://github.com/Megvii-BaseDetection/storage/releases/download/0.0.1/yolox_s.onnx
python demo_onnx.py --model_path yolox_s.onnx --label_name_path coco.label --image_path dog.jpg --output_path output_onnx.jpg
```
#### 2、random sample 2k training images as calibration data, YOLOX-s training from COCO2017.
```
mkdir calibration
python sample.py --traing_data_path your_path/coco/images/train2017/ --count 2000 --calibration_path ./calibration/
```
#### 3、quantization
```
python3 -m onnxsim yolox_s.onnx yolox_s.onnx
python quantization.py
```
#### 4、test int tensort model
```
python demo_trt.py --model_path modelInt8.engine --label_name_path coco.label --image_path dog.jpg --output_path output_trt.jpg
```
| model | time | size |
| :-: |:-:| :-:|
| float32(pth)| 0.0064 |35M|
| int8(trt)| 0.0025 | 9.2M |
| float32 onnx | int8 tensorrt|
| :-: |:-:|
|<img src="./detection/show_img/output_onnx.jpg" height="60%" width="60%">|<img src="./detection/show_img/output_trt.jpg" height="60%" width="60%">|
算法部署-基于TensorRT+INT8量化加速的YOLOX目标检测算法的部署+项目源码-优质项目分享.zip
版权申诉
176 浏览量
2024-05-09
16:29:17
上传
评论
收藏 850KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/3c54a849f48044a884c4cf76b8fda72a_weixin_66442839.jpg!1)
__AtYou__
- 粉丝: 1904
- 资源: 651
最新资源
- 华为HCIA-WLAN 3.0 课程视频(13 WLAN关键报文及STA上线.mp4)
- navicat教程.docx
- 华为HCIA-WLAN 3.0 课程视频(12 CAPWAP隧道.mp4)
- 华为HCIA-WLAN 3.0 课程视频(11 WLAN典型组网方案.mp4)
- 2429550184旺泓-096-1306-SPI接口带字库例程8pin.zip
- 华为HCIA-WLAN 3.0 课程视频(10 WLAN组网架构(下).mp4)
- 华为HCIA-WLAN 3.0 课程视频(09 WLAN组网架构(上).mp4)
- 计算机组成原理-复习提纲
- 华为HCIA-WLAN 3.0 课程视频(08 WLAN基本概念.mp4)
- 华为HCIA-WLAN 3.0 课程视频(07 WLAN的关键技术(下).mp4)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)