yolov5量化具体流程

1、环境配置

1.1、Pytorch Quantization安装

方式1:pip直接安装

pip install pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com

方式2:源码编译安装

git clone https://github.com/NVIDIA/TensorRT.git
cd tools/pytorch-quantization
pip install -r requirements.txt
# for CUDA 10.2 users
pip install torch>=1.9.1
# for CUDA 11.1 users
pip install torch>=1.9.1+cu111
# Python version >= 3.7, GCC version >= 5.4 required
python setup.py install

1.2、trex安装

git clone https://github.com/NVIDIA/TensorRT.git
cd TensorRT/tools/experimental/trt-engine-explorer
python -m pip install -e .

1.3、graphviz安装

sudo apt-get --yes install graphviz

1、敏感层分析

先进性敏感层分析确定那些层不进行量化:

python quant_flow_ptq_sensitive_int8.py

确定敏感层后,将其设定为--sensitive-layer的超参

3、PTQ

python quant_flow_ptq_int8.py

这样便可以得到ONNX文件

4、QAT

python quant_flow_qat_int8.py

5、绘制engine

process_engine.py [-h] [--print_only] [--build_engine] [--profile_engine] [--draw_engine] input outdir [trtexec [trtexec ...]]

python TensorRT/tools/experimental/trt-engine-explorer/utils/process_engine.py yolov5_ptq_int8.onnx yolov5n_ptq_int8 int8

以下便是SVG结果的输出[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gpvdCLpp-1680896501199)(null)]

你可能感兴趣的:(随笔,python,深度学习,pytorch)