mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Bug Fix] Fix PPOCR dynamic input shape bug (#667)
* Imporve OCR Readme * Improve OCR Readme * Improve OCR Readme * Improve OCR Readme * Improve OCR Readme * Add Initialize function to PP-OCR * Add Initialize function to PP-OCR * Add Initialize function to PP-OCR * Make all the model links come from PaddleOCR * Improve OCR readme * Improve OCR readme * Improve OCR readme * Improve OCR readme * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add comments to create API docs * Improve OCR comments * Rename OCR and add comments * Make sure previous python example works * Make sure previous python example works * Fix Rec model bug * Fix Rec model bug * Fix rec model bug * Add SetTrtMaxBatchSize function for TensorRT * Add SetTrtMaxBatchSize Pybind * Add set_trt_max_batch_size python function * Set TRT dynamic shape in PPOCR examples * Set TRT dynamic shape in PPOCR examples * Set TRT dynamic shape in PPOCR examples * Fix PPOCRv2 python example * Fix PPOCR dynamic input shape bug * Remove useless code Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
@@ -34,11 +34,12 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model
|
|||||||
auto rec_option = option;
|
auto rec_option = option;
|
||||||
|
|
||||||
// If use TRT backend, the dynamic shape will be set as follow.
|
// If use TRT backend, the dynamic shape will be set as follow.
|
||||||
det_option.SetTrtInputShape("x", {1, 3, 50, 50}, {1, 3, 640, 640},
|
// We recommend that users set the length and height of the detection model to a multiple of 32.
|
||||||
{1, 3, 1536, 1536});
|
det_option.SetTrtInputShape("x", {1, 3, 64,64}, {1, 3, 640, 640},
|
||||||
cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {1, 3, 48, 320}, {1, 3, 48, 1024});
|
{1, 3, 960, 960});
|
||||||
rec_option.SetTrtInputShape("x", {1, 3, 32, 10}, {1, 3, 32, 320},
|
cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {10, 3, 48, 320}, {64, 3, 48, 1024});
|
||||||
{1, 3, 32, 2304});
|
rec_option.SetTrtInputShape("x", {1, 3, 32, 10}, {10, 3, 32, 320},
|
||||||
|
{64, 3, 32, 2304});
|
||||||
|
|
||||||
// Users could save TRT cache file to disk as follow.
|
// Users could save TRT cache file to disk as follow.
|
||||||
// det_option.SetTrtCacheFile(det_model_dir + sep + "det_trt_cache.trt");
|
// det_option.SetTrtCacheFile(det_model_dir + sep + "det_trt_cache.trt");
|
||||||
@@ -103,6 +104,11 @@ int main(int argc, char* argv[]) {
|
|||||||
} else if (flag == 2) {
|
} else if (flag == 2) {
|
||||||
option.UseGpu();
|
option.UseGpu();
|
||||||
option.UseTrtBackend();
|
option.UseTrtBackend();
|
||||||
|
} else if (flag == 3) {
|
||||||
|
option.UseGpu();
|
||||||
|
option.UseTrtBackend();
|
||||||
|
option.EnablePaddleTrtCollectShape();
|
||||||
|
option.EnablePaddleToTrt();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string det_model_dir = argv[1];
|
std::string det_model_dir = argv[1];
|
||||||
|
@@ -72,6 +72,12 @@ def build_option(args):
|
|||||||
assert args.device.lower(
|
assert args.device.lower(
|
||||||
) == "gpu", "TensorRT backend require inference on device GPU."
|
) == "gpu", "TensorRT backend require inference on device GPU."
|
||||||
option.use_trt_backend()
|
option.use_trt_backend()
|
||||||
|
elif args.backend.lower() == "pptrt":
|
||||||
|
assert args.device.lower(
|
||||||
|
) == "gpu", "Paddle-TensorRT backend require inference on device GPU."
|
||||||
|
option.use_trt_backend()
|
||||||
|
option.enable_paddle_trt_collect_shape()
|
||||||
|
option.enable_paddle_to_trt()
|
||||||
elif args.backend.lower() == "ort":
|
elif args.backend.lower() == "ort":
|
||||||
option.use_ort_backend()
|
option.use_ort_backend()
|
||||||
elif args.backend.lower() == "paddle":
|
elif args.backend.lower() == "paddle":
|
||||||
@@ -100,27 +106,30 @@ rec_label_file = args.rec_label_file
|
|||||||
# 用户也可根据自行需求分别配置
|
# 用户也可根据自行需求分别配置
|
||||||
runtime_option = build_option(args)
|
runtime_option = build_option(args)
|
||||||
|
|
||||||
|
# 当使用TRT时,分别给三个模型的runtime设置动态shape,并完成模型的创建.
|
||||||
|
# 注意: 需要在检测模型创建完成后,再设置分类模型的动态输入并创建分类模型, 识别模型同理.
|
||||||
|
# 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
|
||||||
det_option = runtime_option
|
det_option = runtime_option
|
||||||
cls_option = runtime_option
|
det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
|
||||||
rec_option = runtime_option
|
[1, 3, 960, 960])
|
||||||
|
|
||||||
# 当使用TRT时,分别给三个Runtime设置动态shape
|
|
||||||
det_option.set_trt_input_shape("x", [1, 3, 50, 50], [1, 3, 640, 640],
|
|
||||||
[1, 3, 1536, 1536])
|
|
||||||
cls_option.set_trt_input_shape("x", [1, 3, 48, 10], [1, 3, 48, 320],
|
|
||||||
[1, 3, 48, 1024])
|
|
||||||
rec_option.set_trt_input_shape("x", [1, 3, 32, 10], [1, 3, 32, 320],
|
|
||||||
[1, 3, 32, 2304])
|
|
||||||
|
|
||||||
# 用户可以把TRT引擎文件保存至本地
|
# 用户可以把TRT引擎文件保存至本地
|
||||||
# det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
|
# det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
|
||||||
# cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
|
|
||||||
# rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
|
|
||||||
|
|
||||||
det_model = fd.vision.ocr.DBDetector(
|
det_model = fd.vision.ocr.DBDetector(
|
||||||
det_model_file, det_params_file, runtime_option=det_option)
|
det_model_file, det_params_file, runtime_option=det_option)
|
||||||
|
|
||||||
|
cls_option = runtime_option
|
||||||
|
cls_option.set_trt_input_shape("x", [1, 3, 48, 10], [10, 3, 48, 320],
|
||||||
|
[64, 3, 48, 1024])
|
||||||
|
# 用户可以把TRT引擎文件保存至本地
|
||||||
|
# cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
|
||||||
cls_model = fd.vision.ocr.Classifier(
|
cls_model = fd.vision.ocr.Classifier(
|
||||||
cls_model_file, cls_params_file, runtime_option=cls_option)
|
cls_model_file, cls_params_file, runtime_option=cls_option)
|
||||||
|
|
||||||
|
rec_option = runtime_option
|
||||||
|
rec_option.set_trt_input_shape("x", [1, 3, 32, 10], [10, 3, 32, 320],
|
||||||
|
[64, 3, 32, 2304])
|
||||||
|
# 用户可以把TRT引擎文件保存至本地
|
||||||
|
# rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
|
||||||
rec_model = fd.vision.ocr.Recognizer(
|
rec_model = fd.vision.ocr.Recognizer(
|
||||||
rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
|
rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
|
||||||
|
|
||||||
|
@@ -34,11 +34,12 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model
|
|||||||
auto rec_option = option;
|
auto rec_option = option;
|
||||||
|
|
||||||
// If use TRT backend, the dynamic shape will be set as follow.
|
// If use TRT backend, the dynamic shape will be set as follow.
|
||||||
det_option.SetTrtInputShape("x", {1, 3, 50, 50}, {1, 3, 640, 640},
|
// We recommend that users set the length and height of the detection model to a multiple of 32.
|
||||||
{1, 3, 1536, 1536});
|
det_option.SetTrtInputShape("x", {1, 3, 64,64}, {1, 3, 640, 640},
|
||||||
cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {1, 3, 48, 320}, {1, 3, 48, 1024});
|
{1, 3, 960, 960});
|
||||||
rec_option.SetTrtInputShape("x", {1, 3, 48, 10}, {1, 3, 48, 320},
|
cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {10, 3, 48, 320}, {64, 3, 48, 1024});
|
||||||
{1, 3, 48, 2304});
|
rec_option.SetTrtInputShape("x", {1, 3, 48, 10}, {10, 3, 48, 320},
|
||||||
|
{64, 3, 48, 2304});
|
||||||
|
|
||||||
// Users could save TRT cache file to disk as follow.
|
// Users could save TRT cache file to disk as follow.
|
||||||
// det_option.SetTrtCacheFile(det_model_dir + sep + "det_trt_cache.trt");
|
// det_option.SetTrtCacheFile(det_model_dir + sep + "det_trt_cache.trt");
|
||||||
@@ -103,6 +104,11 @@ int main(int argc, char* argv[]) {
|
|||||||
} else if (flag == 2) {
|
} else if (flag == 2) {
|
||||||
option.UseGpu();
|
option.UseGpu();
|
||||||
option.UseTrtBackend();
|
option.UseTrtBackend();
|
||||||
|
} else if (flag == 3) {
|
||||||
|
option.UseGpu();
|
||||||
|
option.UseTrtBackend();
|
||||||
|
option.EnablePaddleTrtCollectShape();
|
||||||
|
option.EnablePaddleToTrt();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string det_model_dir = argv[1];
|
std::string det_model_dir = argv[1];
|
||||||
|
@@ -72,6 +72,12 @@ def build_option(args):
|
|||||||
assert args.device.lower(
|
assert args.device.lower(
|
||||||
) == "gpu", "TensorRT backend require inference on device GPU."
|
) == "gpu", "TensorRT backend require inference on device GPU."
|
||||||
option.use_trt_backend()
|
option.use_trt_backend()
|
||||||
|
elif args.backend.lower() == "pptrt":
|
||||||
|
assert args.device.lower(
|
||||||
|
) == "gpu", "Paddle-TensorRT backend require inference on device GPU."
|
||||||
|
option.use_trt_backend()
|
||||||
|
option.enable_paddle_trt_collect_shape()
|
||||||
|
option.enable_paddle_to_trt()
|
||||||
elif args.backend.lower() == "ort":
|
elif args.backend.lower() == "ort":
|
||||||
option.use_ort_backend()
|
option.use_ort_backend()
|
||||||
elif args.backend.lower() == "paddle":
|
elif args.backend.lower() == "paddle":
|
||||||
@@ -100,27 +106,30 @@ rec_label_file = args.rec_label_file
|
|||||||
# 用户也可根据自行需求分别配置
|
# 用户也可根据自行需求分别配置
|
||||||
runtime_option = build_option(args)
|
runtime_option = build_option(args)
|
||||||
|
|
||||||
|
# 当使用TRT时,分别给三个模型的runtime设置动态shape,并完成模型的创建.
|
||||||
|
# 注意: 需要在检测模型创建完成后,再设置分类模型的动态输入并创建分类模型, 识别模型同理.
|
||||||
|
# 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
|
||||||
det_option = runtime_option
|
det_option = runtime_option
|
||||||
cls_option = runtime_option
|
det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
|
||||||
rec_option = runtime_option
|
[1, 3, 960, 960])
|
||||||
|
|
||||||
# 当使用TRT时,分别给三个Runtime设置动态shape
|
|
||||||
det_option.set_trt_input_shape("x", [1, 3, 50, 50], [1, 3, 640, 640],
|
|
||||||
[1, 3, 1536, 1536])
|
|
||||||
cls_option.set_trt_input_shape("x", [1, 3, 48, 10], [1, 3, 48, 320],
|
|
||||||
[1, 3, 48, 1024])
|
|
||||||
rec_option.set_trt_input_shape("x", [1, 3, 48, 10], [1, 3, 48, 320],
|
|
||||||
[1, 3, 48, 2304])
|
|
||||||
|
|
||||||
# 用户可以把TRT引擎文件保存至本地
|
# 用户可以把TRT引擎文件保存至本地
|
||||||
# det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
|
# det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
|
||||||
# cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
|
|
||||||
# rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
|
|
||||||
|
|
||||||
det_model = fd.vision.ocr.DBDetector(
|
det_model = fd.vision.ocr.DBDetector(
|
||||||
det_model_file, det_params_file, runtime_option=det_option)
|
det_model_file, det_params_file, runtime_option=det_option)
|
||||||
|
|
||||||
|
cls_option = runtime_option
|
||||||
|
cls_option.set_trt_input_shape("x", [1, 3, 48, 10], [10, 3, 48, 320],
|
||||||
|
[64, 3, 48, 1024])
|
||||||
|
# 用户可以把TRT引擎文件保存至本地
|
||||||
|
# cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
|
||||||
cls_model = fd.vision.ocr.Classifier(
|
cls_model = fd.vision.ocr.Classifier(
|
||||||
cls_model_file, cls_params_file, runtime_option=cls_option)
|
cls_model_file, cls_params_file, runtime_option=cls_option)
|
||||||
|
|
||||||
|
rec_option = runtime_option
|
||||||
|
rec_option.set_trt_input_shape("x", [1, 3, 48, 10], [10, 3, 48, 320],
|
||||||
|
[64, 3, 48, 2304])
|
||||||
|
# 用户可以把TRT引擎文件保存至本地
|
||||||
|
# rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
|
||||||
rec_model = fd.vision.ocr.Recognizer(
|
rec_model = fd.vision.ocr.Recognizer(
|
||||||
rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
|
rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user