Files
FastDeploy/tools/common_tools/common_tools.py
yunyaoXYY 712d7fd71b [Quantization] Improve the usage of FastDeploy tools. (#660)
* Add PaddleOCR Support

* Add PaddleOCR Support

* Add PaddleOCRv3 Support

* Add PaddleOCRv3 Support

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Add PaddleOCRv3 Support

* Add PaddleOCRv3 Supports

* Add PaddleOCRv3 Suport

* Fix Rec diff

* Remove useless functions

* Remove useless comments

* Add PaddleOCRv2 Support

* Add PaddleOCRv3 & PaddleOCRv2 Support

* remove useless parameters

* Add utils of sorting det boxes

* Fix code naming convention

* Fix code naming convention

* Fix code naming convention

* Fix bug in the Classify process

* Imporve OCR Readme

* Fix diff in Cls model

* Update Model Download Link in Readme

* Fix diff in PPOCRv2

* Improve OCR readme

* Imporve OCR readme

* Improve OCR readme

* Improve OCR readme

* Imporve OCR readme

* Improve OCR readme

* Fix conflict

* Add readme for OCRResult

* Improve OCR readme

* Add OCRResult readme

* Improve OCR readme

* Improve OCR readme

* Add Model Quantization Demo

* Fix Model Quantization Readme

* Fix Model Quantization Readme

* Add the function to do PTQ quantization

* Improve quant tools readme

* Improve quant tool readme

* Improve quant tool readme

* Add PaddleInference-GPU for OCR Rec model

* Add QAT method to fastdeploy-quantization tool

* Remove examples/slim for now

* Move configs folder

* Add Quantization Support for Classification Model

* Imporve ways of importing preprocess

* Upload YOLO Benchmark on readme

* Upload YOLO Benchmark on readme

* Upload YOLO Benchmark on readme

* Improve Quantization configs and readme

* Add support for multi-inputs model

* Add backends and params file for YOLOv7

* Add quantized model deployment support for YOLO series

* Fix YOLOv5 quantize readme

* Fix YOLO quantize readme

* Fix YOLO quantize readme

* Improve quantize YOLO readme

* Improve quantize YOLO readme

* Improve quantize YOLO readme

* Improve quantize YOLO readme

* Improve quantize YOLO readme

* Fix bug, change Fronted to ModelFormat

* Change Fronted to ModelFormat

* Add examples to deploy quantized paddleclas models

* Fix readme

* Add quantize Readme

* Add quantize Readme

* Add quantize Readme

* Modify readme of quantization tools

* Modify readme of quantization tools

* Improve quantization tools readme

* Improve quantization readme

* Improve PaddleClas quantized model deployment  readme

* Add PPYOLOE-l quantized deployment examples

* Improve quantization tools readme

* Improve Quantize Readme

* Fix conflicts

* Fix conflicts

* improve readme

* Improve quantization tools and readme

* Improve quantization tools and readme

* Add quantized deployment examples for PaddleSeg model

* Fix cpp readme

* Fix memory leak of reader_wrapper function

* Fix model file name in PaddleClas quantization examples

* Update Runtime and E2E benchmark

* Update Runtime and E2E benchmark

* Rename quantization tools to auto compression tools

* Remove PPYOLOE data when deployed on MKLDNN

* Fix readme

* Support PPYOLOE with OR without NMS and update readme

* Update Readme

* Update configs and readme

* Update configs and readme

* Add Paddle-TensorRT backend in quantized model deploy examples

* Support PPYOLOE+ series

* Add reused_input_tensors for PPYOLOE

* Improve fastdeploy tools usage

* improve fastdeploy tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* remove modify

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Improve fastdeploy auto compression tool

* Remove extra requirements for fd-auto-compress package

* Imporve fastdeploy-tools package

* Install fastdeploy-tools package when build fastdeploy-python

* Imporve quantization readme
2022-11-23 10:13:50 +08:00

129 lines
4.5 KiB
Python
Executable File

import argparse
import ast
def argsparser():
parser = argparse.ArgumentParser(description=__doc__)
## argumentments for auto compression
parser.add_argument('--auto_compress', default=False, action='store_true')
parser.add_argument(
'--config_path',
type=str,
default=None,
help="path of compression strategy config.")
parser.add_argument(
'--method',
type=str,
default=None,
help="choose PTQ or QAT as quantization method")
parser.add_argument(
'--save_dir',
type=str,
default='./output',
help="directory to save model.")
parser.add_argument(
'--devices',
type=str,
default='gpu',
help="which device used to compress.")
## arguments for other x2paddle
parser.add_argument('--convert', default=False, action='store_true')
parser.add_argument(
'--framework',
type=str,
default=None,
help="define which deeplearning framework(tensorflow/caffe/onnx)")
parser.add_argument(
'--model',
type=str,
default=None,
help="define model file path for tensorflow or onnx")
parser.add_argument(
"--prototxt",
"-p",
type=str,
default=None,
help="prototxt file of caffe model")
parser.add_argument(
"--weight",
"-w",
type=str,
default=None,
help="weight file of caffe model")
parser.add_argument(
"--caffe_proto",
"-c",
type=str,
default=None,
help="optional: the .py file compiled by caffe proto file of caffe model"
)
parser.add_argument(
"--input_shape_dict",
"-isd",
type=str,
default=None,
help="define input shapes, e.g --input_shape_dict=\"{'image':[1, 3, 608, 608]}\" or" \
"--input_shape_dict=\"{'image':[1, 3, 608, 608], 'im_shape': [1, 2], 'scale_factor': [1, 2]}\"")
parser.add_argument(
"--enable_code_optim",
"-co",
type=ast.literal_eval,
default=False,
help="Turn on code optimization")
## arguments for other tools
return parser
def main():
args = argsparser().parse_args()
if args.auto_compress == True:
try:
from .auto_compression.fd_auto_compress.fd_auto_compress import auto_compress
print("Welcome to use FastDeploy Auto Compression Toolkit!")
auto_compress(args)
except ImportError:
print(
"Can not start auto compresssion successfully! Please check if you have installed it!"
)
if args.convert == True:
try:
import platform
import logging
v0, v1, v2 = platform.python_version().split('.')
if not (int(v0) >= 3 and int(v1) >= 5):
logging.info("[ERROR] python>=3.5 is required")
return
import paddle
v0, v1, v2 = paddle.__version__.split('.')
logging.info("paddle.__version__ = {}".format(paddle.__version__))
if v0 == '0' and v1 == '0' and v2 == '0':
logging.info(
"[WARNING] You are use develop version of paddlepaddle")
elif int(v0) != 2 or int(v1) < 0:
logging.info("[ERROR] paddlepaddle>=2.0.0 is required")
return
from x2paddle.convert import tf2paddle, caffe2paddle, onnx2paddle
if args.framework == "tensorflow":
assert args.model is not None, "--model should be defined while convert tensorflow model"
tf2paddle(args.model, args.save_dir)
elif args.framework == "caffe":
assert args.prototxt is not None and args.weight is not None, "--prototxt and --weight should be defined while convert caffe model"
caffe2paddle(args.prototxt, args.weight, args.save_dir,
args.caffe_proto)
elif args.framework == "onnx":
assert args.model is not None, "--model should be defined while convert onnx model"
onnx2paddle(
args.model,
args.save_dir,
input_shape_dict=args.input_shape_dict)
else:
raise Exception(
"--framework only support tensorflow/caffe/onnx now")
except ImportError:
print(
"Model convert failed! Please check if you have installed it!")
if __name__ == '__main__':
main()