mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Quantization] Improve the usage of fastdeploy tools (#722)
Improve the usage of fastdeploy tools
This commit is contained in:
@@ -3,5 +3,5 @@ requests
|
|||||||
tqdm
|
tqdm
|
||||||
numpy
|
numpy
|
||||||
opencv-python
|
opencv-python
|
||||||
fastdeploy-tools
|
fastdeploy-tools==0.0.1
|
||||||
pyyaml
|
pyyaml
|
||||||
|
@@ -26,14 +26,14 @@ python setup.py install
|
|||||||
```bash
|
```bash
|
||||||
# 通过pip安装fastdeploy-tools. 此工具包目前支持模型一键自动化压缩和模型转换的功能.
|
# 通过pip安装fastdeploy-tools. 此工具包目前支持模型一键自动化压缩和模型转换的功能.
|
||||||
# FastDeploy的python包已包含此工具, 不需重复安装.
|
# FastDeploy的python包已包含此工具, 不需重复安装.
|
||||||
pip install fastdeploy-tools==0.0.0
|
pip install fastdeploy-tools==0.0.1
|
||||||
```
|
```
|
||||||
|
|
||||||
### 一键模型自动化压缩工具的使用
|
### 一键模型自动化压缩工具的使用
|
||||||
按照以上步骤成功安装后,即可使用FastDeploy一键模型自动化压缩工具, 示例如下.
|
按照以上步骤成功安装后,即可使用FastDeploy一键模型自动化压缩工具, 示例如下.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
fastdeploy --auto_compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
||||||
```
|
```
|
||||||
详细使用文档请参考[FastDeploy一键模型自动化压缩工具](./common_tools/auto_compression/README.md)
|
详细使用文档请参考[FastDeploy一键模型自动化压缩工具](./common_tools/auto_compression/README.md)
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ python setup.py install
|
|||||||
按照以上步骤成功安装后,即可使用 FastDeploy 一键转换工具, 示例如下:
|
按照以上步骤成功安装后,即可使用 FastDeploy 一键转换工具, 示例如下:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
fastdeploy --convert --framework onnx --model yolov5s.onnx --save_dir pd_model
|
fastdeploy convert --framework onnx --model yolov5s.onnx --save_dir pd_model
|
||||||
```
|
```
|
||||||
|
|
||||||
更多详细内容可参考[X2Paddle](https://github.com/PaddlePaddle/X2Paddle)
|
更多详细内容可参考[X2Paddle](https://github.com/PaddlePaddle/X2Paddle)
|
||||||
|
@@ -26,14 +26,14 @@ python setup.py install
|
|||||||
```bash
|
```bash
|
||||||
# Installing fastdeploy-tools via pip
|
# Installing fastdeploy-tools via pip
|
||||||
# This tool is included in the python installer of FastDeploy, so you don't need to install it again.
|
# This tool is included in the python installer of FastDeploy, so you don't need to install it again.
|
||||||
pip install fastdeploy-tools==0.0.0
|
pip install fastdeploy-tools==0.0.1
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### The Usage of One-Click Model Auto Compression Tool
|
### The Usage of One-Click Model Auto Compression Tool
|
||||||
After the above steps are successfully installed, you can use FastDeploy one-click model automation compression tool, as shown in the following example.
|
After the above steps are successfully installed, you can use FastDeploy one-click model automation compression tool, as shown in the following example.
|
||||||
```bash
|
```bash
|
||||||
fastdeploy --auto_compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
||||||
```
|
```
|
||||||
For detailed documentation, please refer to [FastDeploy One-Click Model Auto Compression Tool](./common_tools/auto_compression/README_EN.md)
|
For detailed documentation, please refer to [FastDeploy One-Click Model Auto Compression Tool](./common_tools/auto_compression/README_EN.md)
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ python setup.py install
|
|||||||
After successful installation according to the above steps, you can use the FastDeploy one-click conversion tool. The example is as follows:
|
After successful installation according to the above steps, you can use the FastDeploy one-click conversion tool. The example is as follows:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
fastdeploy --convert --framework onnx --model yolov5s.onnx --save_dir pd_model
|
fastdeploy convert --framework onnx --model yolov5s.onnx --save_dir pd_model
|
||||||
```
|
```
|
||||||
|
|
||||||
For more details, please refer to[X2Paddle](https://github.com/PaddlePaddle/X2Paddle)
|
For more details, please refer to[X2Paddle](https://github.com/PaddlePaddle/X2Paddle)
|
||||||
|
@@ -40,10 +40,10 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/COCO_val_320.tar.gz
|
|||||||
tar -xvf COCO_val_320.tar.gz
|
tar -xvf COCO_val_320.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 2.使用fastdeploy --auto_compress命令,执行一键模型自动化压缩:
|
##### 2.使用fastdeploy compress命令,执行一键模型自动化压缩:
|
||||||
以下命令是对yolov5s模型进行量化, 用户若想量化其他模型, 替换config_path为configs文件夹下的其他模型配置文件即可.
|
以下命令是对yolov5s模型进行量化, 用户若想量化其他模型, 替换config_path为configs文件夹下的其他模型配置文件即可.
|
||||||
```shell
|
```shell
|
||||||
fastdeploy --auto_compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 3.参数说明
|
##### 3.参数说明
|
||||||
@@ -74,12 +74,12 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/COCO_train_320.tar
|
|||||||
tar -xvf COCO_train_320.tar
|
tar -xvf COCO_train_320.tar
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 2.使用fastdeploy --auto_compress命令,执行一键模型自动化压缩:
|
##### 2.使用fastdeploy compress命令,执行一键模型自动化压缩:
|
||||||
以下命令是对yolov5s模型进行量化, 用户若想量化其他模型, 替换config_path为configs文件夹下的其他模型配置文件即可.
|
以下命令是对yolov5s模型进行量化, 用户若想量化其他模型, 替换config_path为configs文件夹下的其他模型配置文件即可.
|
||||||
```shell
|
```shell
|
||||||
# 执行命令默认为单卡训练,训练前请指定单卡GPU, 否则在训练过程中可能会卡住.
|
# 执行命令默认为单卡训练,训练前请指定单卡GPU, 否则在训练过程中可能会卡住.
|
||||||
export CUDA_VISIBLE_DEVICES=0
|
export CUDA_VISIBLE_DEVICES=0
|
||||||
fastdeploy --auto_compress --config_path=./configs/detection/yolov5s_quant.yaml --method='QAT' --save_dir='./yolov5s_qat_model/'
|
fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='QAT' --save_dir='./yolov5s_qat_model/'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 3.参数说明
|
##### 3.参数说明
|
||||||
|
@@ -46,12 +46,12 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/COCO_val_320.tar.gz
|
|||||||
tar -xvf COCO_val_320.tar.gz
|
tar -xvf COCO_val_320.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 2. Run fastdeploy --auto_compress command to compress the model
|
##### 2. Run fastdeploy compress command to compress the model
|
||||||
|
|
||||||
The following command is to quantize the yolov5s model, if developers want to quantize other models, replace the config_path with other model configuration files in the configs folder.
|
The following command is to quantize the yolov5s model, if developers want to quantize other models, replace the config_path with other model configuration files in the configs folder.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
fastdeploy --auto_compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model/'
|
||||||
```
|
```
|
||||||
|
|
||||||
[notice] PTQ is short for post-training quantization
|
[notice] PTQ is short for post-training quantization
|
||||||
@@ -83,14 +83,14 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/COCO_val_320.tar.gz
|
|||||||
tar -xvf COCO_val_320.tar.gz
|
tar -xvf COCO_val_320.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 2.Use fastdeploy --auto_compress command to compress models
|
##### 2.Use fastdeploy compress command to compress models
|
||||||
|
|
||||||
The following command is to quantize the yolov5s model, if developers want to quantize other models, replace the config_path with other model configuration files in the configs folder.
|
The following command is to quantize the yolov5s model, if developers want to quantize other models, replace the config_path with other model configuration files in the configs folder.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Please specify the single card GPU before training, otherwise it may get stuck during the training process.
|
# Please specify the single card GPU before training, otherwise it may get stuck during the training process.
|
||||||
export CUDA_VISIBLE_DEVICES=0
|
export CUDA_VISIBLE_DEVICES=0
|
||||||
fastdeploy --auto_compress --config_path=./configs/detection/yolov5s_quant.yaml --method='QAT' --save_dir='./yolov5s_qat_model/'
|
fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='QAT' --save_dir='./yolov5s_qat_model/'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 3.Parameters
|
##### 3.Parameters
|
||||||
|
0
tools/common_tools/auto_compression/__init__.py
Normal file
0
tools/common_tools/auto_compression/__init__.py
Normal file
@@ -1 +0,0 @@
|
|||||||
import fd_auto_compress
|
|
||||||
|
@@ -22,7 +22,7 @@ import paddle
|
|||||||
from paddleslim.common import load_config, load_onnx_model
|
from paddleslim.common import load_config, load_onnx_model
|
||||||
from paddleslim.auto_compression import AutoCompression
|
from paddleslim.auto_compression import AutoCompression
|
||||||
from paddleslim.quant import quant_post_static
|
from paddleslim.quant import quant_post_static
|
||||||
from fd_auto_compress.dataset import *
|
from .dataset import *
|
||||||
|
|
||||||
|
|
||||||
def argsparser():
|
def argsparser():
|
||||||
|
@@ -4,8 +4,8 @@ import ast
|
|||||||
|
|
||||||
def argsparser():
|
def argsparser():
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument('tools', choices=['compress', 'convert'])
|
||||||
## argumentments for auto compression
|
## argumentments for auto compression
|
||||||
parser.add_argument('--auto_compress', default=False, action='store_true')
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--config_path',
|
'--config_path',
|
||||||
type=str,
|
type=str,
|
||||||
@@ -27,7 +27,6 @@ def argsparser():
|
|||||||
default='gpu',
|
default='gpu',
|
||||||
help="which device used to compress.")
|
help="which device used to compress.")
|
||||||
## arguments for other x2paddle
|
## arguments for other x2paddle
|
||||||
parser.add_argument('--convert', default=False, action='store_true')
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--framework',
|
'--framework',
|
||||||
type=str,
|
type=str,
|
||||||
@@ -76,16 +75,11 @@ def argsparser():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = argsparser().parse_args()
|
args = argsparser().parse_args()
|
||||||
if args.auto_compress == True:
|
if args.tools == "compress":
|
||||||
try:
|
from .auto_compression.fd_auto_compress.fd_auto_compress import auto_compress
|
||||||
from .auto_compression.fd_auto_compress.fd_auto_compress import auto_compress
|
print("Welcome to use FastDeploy Auto Compression Toolkit!")
|
||||||
print("Welcome to use FastDeploy Auto Compression Toolkit!")
|
auto_compress(args)
|
||||||
auto_compress(args)
|
if args.tools == "convert":
|
||||||
except ImportError:
|
|
||||||
print(
|
|
||||||
"Can not start auto compresssion successfully! Please check if you have installed it!"
|
|
||||||
)
|
|
||||||
if args.convert == True:
|
|
||||||
try:
|
try:
|
||||||
import platform
|
import platform
|
||||||
import logging
|
import logging
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import setuptools
|
import setuptools
|
||||||
|
|
||||||
long_description = "fastdeploy-tools is a toolkit for FastDeploy, including auto compression .etc.\n\n"
|
long_description = "fastdeploy-tools is a toolkit for FastDeploy, including auto compression .etc.\n\n"
|
||||||
long_description += "Usage of auto compression: fastdeploy --auto_compress --config_path=./yolov7_tiny_qat_dis.yaml --method='QAT' --save_dir='./v7_qat_outmodel/' \n"
|
long_description += "Usage of auto compression: fastdeploy compress --config_path=./yolov7_tiny_qat_dis.yaml --method='QAT' --save_dir='./v7_qat_outmodel/' \n"
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="fastdeploy-tools", # name of package
|
name="fastdeploy-tools", # name of package
|
||||||
|
version="0.0.1", #version of package
|
||||||
description="A toolkit for FastDeploy.",
|
description="A toolkit for FastDeploy.",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/plain",
|
long_description_content_type="text/plain",
|
||||||
|
Reference in New Issue
Block a user