diff --git a/PPOCRLabel/README.md b/PPOCRLabel/README.md index 9fc5f3437af0076bdbe2afedf8c194009c2c0e72..61ebbe926c0a1c9c2922d0f3070e2c39f884e68e 100644 --- a/PPOCRLabel/README.md +++ b/PPOCRLabel/README.md @@ -54,7 +54,10 @@ PPOCRLabel can be started in two ways: whl package and Python script. The whl pa ```bash pip install PPOCRLabel # install -PPOCRLabel # run + +# Select label mode and run +PPOCRLabel # [Normal mode] for [detection + recognition] labeling +PPOCRLabel --kie True # [KIE mode] for [detection + recognition + keyword extraction] labeling ``` > If you getting this error `OSError: [WinError 126] The specified module could not be found` when you install shapely on windows. Please try to download Shapely whl file using http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely. @@ -67,13 +70,18 @@ PPOCRLabel # run ```bash pip3 install PPOCRLabel pip3 install trash-cli -PPOCRLabel + +# Select label mode and run +PPOCRLabel # [Normal mode] for [detection + recognition] labeling +PPOCRLabel --kie True # [KIE mode] for [detection + recognition + keyword extraction] labeling ``` #### MacOS ```bash pip3 install PPOCRLabel pip3 install opencv-contrib-python-headless==4.2.0.32 + +# Select label mode and run PPOCRLabel # [Normal mode] for [detection + recognition] labeling PPOCRLabel --kie True # [KIE mode] for [detection + recognition + keyword extraction] labeling ``` @@ -90,6 +98,8 @@ pip3 install dist/PPOCRLabel-1.0.2-py2.py3-none-any.whl ```bash cd ./PPOCRLabel # Switch to the PPOCRLabel directory + +# Select label mode and run python PPOCRLabel.py # [Normal mode] for [detection + recognition] labeling python PPOCRLabel.py --kie True # [KIE mode] for [detection + recognition + keyword extraction] labeling ``` diff --git a/PPOCRLabel/README_ch.md b/PPOCRLabel/README_ch.md index 67c2e877288a73b07e5dd1ca90993bde8a96bf20..18ffea53f95869d2fa65159ab934a55b662d6f5b 100644 --- a/PPOCRLabel/README_ch.md +++ b/PPOCRLabel/README_ch.md @@ -57,7 +57,10 @@ PPOCRLabel可通过whl包与Python脚本两种方式启动,whl包形式启动 ```bash pip install PPOCRLabel # 安装 -PPOCRLabel --lang ch # 运行 + +# 选择标签模式来启动 +PPOCRLabel --lang ch # 启动【普通模式】,用于打【检测+识别】场景的标签 +PPOCRLabel --lang ch --kie True # 启动 【KIE 模式】,用于打【检测+识别+关键字提取】场景的标签 ``` > 注意:通过whl包安装PPOCRLabel会自动下载 `paddleocr` whl包,其中shapely依赖可能会出现 `[winRrror 126] 找不到指定模块的问题。` 的错误,建议从[这里](https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely)下载并安装 ##### Ubuntu Linux @@ -65,13 +68,18 @@ PPOCRLabel --lang ch # 运行 ```bash pip3 install PPOCRLabel pip3 install trash-cli -PPOCRLabel --lang ch + +# 选择标签模式来启动 +PPOCRLabel --lang ch # 启动【普通模式】,用于打【检测+识别】场景的标签 +PPOCRLabel --lang ch --kie True # 启动 【KIE 模式】,用于打【检测+识别+关键字提取】场景的标签 ``` ##### MacOS ```bash pip3 install PPOCRLabel pip3 install opencv-contrib-python-headless==4.2.0.32 # 如果下载过慢请添加"-i https://mirror.baidu.com/pypi/simple" + +# 选择标签模式来启动 PPOCRLabel --lang ch # 启动【普通模式】,用于打【检测+识别】场景的标签 PPOCRLabel --lang ch --kie True # 启动 【KIE 模式】,用于打【检测+识别+关键字提取】场景的标签 ``` @@ -92,6 +100,8 @@ pip3 install dist/PPOCRLabel-1.0.2-py2.py3-none-any.whl -i https://mirror.baidu. ```bash cd ./PPOCRLabel # 切换到PPOCRLabel目录 + +# 选择标签模式来启动 python PPOCRLabel.py --lang ch # 启动【普通模式】,用于打【检测+识别】场景的标签 python PPOCRLabel.py --lang ch --kie True # 启动 【KIE 模式】,用于打【检测+识别+关键字提取】场景的标签 ``` diff --git a/deploy/cpp_infer/include/ocr_det.h b/deploy/cpp_infer/include/ocr_det.h index e5a31ed8e5ab6397c4fa67388252e2baef8b9dd7..657ab25d8854ec54c27d71485fe9eeddc65013c3 100644 --- a/deploy/cpp_infer/include/ocr_det.h +++ b/deploy/cpp_infer/include/ocr_det.h @@ -45,8 +45,9 @@ public: const double &det_db_thresh, const double &det_db_box_thresh, const double &det_db_unclip_ratio, - const bool &use_polygon_score, const bool &visualize, - const bool &use_tensorrt, const std::string &precision) { + const bool &use_polygon_score, const bool &use_dilation, + const bool &visualize, const bool &use_tensorrt, + const std::string &precision) { this->use_gpu_ = use_gpu; this->gpu_id_ = gpu_id; this->gpu_mem_ = gpu_mem; @@ -59,6 +60,7 @@ public: this->det_db_box_thresh_ = det_db_box_thresh; this->det_db_unclip_ratio_ = det_db_unclip_ratio; this->use_polygon_score_ = use_polygon_score; + this->use_dilation_ = use_dilation; this->visualize_ = visualize; this->use_tensorrt_ = use_tensorrt; @@ -71,7 +73,8 @@ public: void LoadModel(const std::string &model_dir); // Run predictor - void Run(cv::Mat &img, std::vector>> &boxes, std::vector *times); + void Run(cv::Mat &img, std::vector>> &boxes, + std::vector *times); private: std::shared_ptr predictor_; @@ -88,6 +91,7 @@ private: double det_db_box_thresh_ = 0.5; double det_db_unclip_ratio_ = 2.0; bool use_polygon_score_ = false; + bool use_dilation_ = false; bool visualize_ = true; bool use_tensorrt_ = false; diff --git a/deploy/cpp_infer/readme.md b/deploy/cpp_infer/readme.md index d901366235db21727ceac88528d83ae1120fd030..725197ad5cf9c7bf54be445f2bb3698096e7f9fb 100644 --- a/deploy/cpp_infer/readme.md +++ b/deploy/cpp_infer/readme.md @@ -4,16 +4,20 @@ C++在性能计算上优于python,因此,在大多数CPU、GPU部署场景,多采用C++的部署方式,本节将介绍如何在Linux\Windows (CPU\GPU)环境下配置C++环境并完成 PaddleOCR模型部署。 -* [1. 准备环境](#1) - + [1.0 运行准备](#10) - + [1.1 编译opencv库](#11) - + [1.2 下载或者编译Paddle预测库](#12) - - [1.2.1 直接下载安装](#121) - - [1.2.2 预测库源码编译](#122) -* [2 开始运行](#2) - + [2.1 将模型导出为inference model](#21) - + [2.2 编译PaddleOCR C++预测demo](#22) - + [2.3运行demo](#23) +- [服务器端C++预测](#服务器端c预测) + - [1. 准备环境](#1-准备环境) + - [1.0 运行准备](#10-运行准备) + - [1.1 编译opencv库](#11-编译opencv库) + - [1.2 下载或者编译Paddle预测库](#12-下载或者编译paddle预测库) + - [1.2.1 直接下载安装](#121-直接下载安装) + - [1.2.2 预测库源码编译](#122-预测库源码编译) + - [2 开始运行](#2-开始运行) + - [2.1 将模型导出为inference model](#21-将模型导出为inference-model) + - [2.2 编译PaddleOCR C++预测demo](#22-编译paddleocr-c预测demo) + - [2.3 运行demo](#23-运行demo) + - [1. 只调用检测:](#1-只调用检测) + - [2. 只调用识别:](#2-只调用识别) + - [3. 调用串联:](#3-调用串联) @@ -103,7 +107,7 @@ opencv3/ #### 1.2.1 直接下载安装 -* [Paddle预测库官网](https://paddle-inference.readthedocs.io/en/latest/user_guides/download_lib.html) 上提供了不同cuda版本的Linux预测库,可以在官网查看并选择合适的预测库版本(*建议选择paddle版本>=2.0.1版本的预测库* )。 +* [Paddle预测库官网](https://paddleinference.paddlepaddle.org.cn/user_guides/download_lib.html#linux) 上提供了不同cuda版本的Linux预测库,可以在官网查看并选择合适的预测库版本(*建议选择paddle版本>=2.0.1版本的预测库* )。 * 下载之后使用下面的方法解压。 @@ -249,7 +253,7 @@ CUDNN_LIB_DIR=/your_cudnn_lib_dir |gpu_id|int|0|GPU id,使用GPU时有效| |gpu_mem|int|4000|申请的GPU内存| |cpu_math_library_num_threads|int|10|CPU预测时的线程数,在机器核数充足的情况下,该值越大,预测速度越快| -|use_mkldnn|bool|true|是否使用mkldnn库| +|enable_mkldnn|bool|true|是否使用mkldnn库| - 检测模型相关 diff --git a/deploy/cpp_infer/readme_en.md b/deploy/cpp_infer/readme_en.md index 8c5a323af40e64f77e76cba23fd5c4408c643de5..f4cfab24350c1a6be3d8ebebf6b47b0baaa4f26e 100644 --- a/deploy/cpp_infer/readme_en.md +++ b/deploy/cpp_infer/readme_en.md @@ -78,7 +78,7 @@ opencv3/ #### 1.2.1 Direct download and installation -[Paddle inference library official website](https://paddle-inference.readthedocs.io/en/latest/user_guides/download_lib.html). You can review and select the appropriate version of the inference library on the official website. +[Paddle inference library official website](https://paddleinference.paddlepaddle.org.cn/user_guides/download_lib.html#linux). You can review and select the appropriate version of the inference library on the official website. * After downloading, use the following command to extract files. @@ -231,7 +231,7 @@ More parameters are as follows, |gpu_id|int|0|GPU id when use_gpu is true| |gpu_mem|int|4000|GPU memory requested| |cpu_math_library_num_threads|int|10|Number of threads when using CPU inference. When machine cores is enough, the large the value, the faster the inference speed| -|use_mkldnn|bool|true|Whether to use mkdlnn library| +|enable_mkldnn|bool|true|Whether to use mkdlnn library| - Detection related parameters diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index b7a199b548beca881e4ab69491adcc9351f52c0f..664b10b2f579fd8681c65dcf1ded5ebe53d0424c 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -28,14 +28,14 @@ #include #include -#include #include +#include #include #include #include -#include #include "auto_log/autolog.h" +#include DEFINE_bool(use_gpu, false, "Infering with GPU or CPU."); DEFINE_int32(gpu_id, 0, "Device id of GPU to execute."); @@ -51,9 +51,10 @@ DEFINE_string(image_dir, "", "Dir of input image."); DEFINE_string(det_model_dir, "", "Path of det inference model."); DEFINE_int32(max_side_len, 960, "max_side_len of input image."); DEFINE_double(det_db_thresh, 0.3, "Threshold of det_db_thresh."); -DEFINE_double(det_db_box_thresh, 0.5, "Threshold of det_db_box_thresh."); -DEFINE_double(det_db_unclip_ratio, 1.6, "Threshold of det_db_unclip_ratio."); +DEFINE_double(det_db_box_thresh, 0.6, "Threshold of det_db_box_thresh."); +DEFINE_double(det_db_unclip_ratio, 1.5, "Threshold of det_db_unclip_ratio."); DEFINE_bool(use_polygon_score, false, "Whether use polygon score."); +DEFINE_bool(use_dilation, false, "Whether use the dilation on output map."); DEFINE_bool(visualize, true, "Whether show the detection results."); // classification related DEFINE_bool(use_angle_cls, false, "Whether use use_angle_cls."); @@ -62,281 +63,260 @@ DEFINE_double(cls_thresh, 0.9, "Threshold of cls_thresh."); // recognition related DEFINE_string(rec_model_dir, "", "Path of rec inference model."); DEFINE_int32(rec_batch_num, 6, "rec_batch_num."); -DEFINE_string(char_list_file, "../../ppocr/utils/ppocr_keys_v1.txt", "Path of dictionary."); - +DEFINE_string(char_list_file, "../../ppocr/utils/ppocr_keys_v1.txt", + "Path of dictionary."); using namespace std; using namespace cv; using namespace PaddleOCR; - -static bool PathExists(const std::string& path){ +static bool PathExists(const std::string &path) { #ifdef _WIN32 struct _stat buffer; return (_stat(path.c_str(), &buffer) == 0); #else struct stat buffer; return (stat(path.c_str(), &buffer) == 0); -#endif // !_WIN32 +#endif // !_WIN32 } - int main_det(std::vector cv_all_img_names) { - std::vector time_info = {0, 0, 0}; - DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_threads, - FLAGS_enable_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, - FLAGS_det_db_box_thresh, FLAGS_det_db_unclip_ratio, - FLAGS_use_polygon_score, FLAGS_visualize, - FLAGS_use_tensorrt, FLAGS_precision); - - for (int i = 0; i < cv_all_img_names.size(); ++i) { -// LOG(INFO) << "The predict img: " << cv_all_img_names[i]; - - cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); - if (!srcimg.data) { - std::cerr << "[ERROR] image read failed! image path: " << cv_all_img_names[i] << endl; - exit(1); - } - std::vector>> boxes; - std::vector det_times; - - det.Run(srcimg, boxes, &det_times); - - time_info[0] += det_times[0]; - time_info[1] += det_times[1]; - time_info[2] += det_times[2]; - - if (FLAGS_benchmark) { - cout << cv_all_img_names[i] << '\t'; - for (int n = 0; n < boxes.size(); n++) { - for (int m = 0; m < boxes[n].size(); m++) { - cout << boxes[n][m][0] << ' ' << boxes[n][m][1] << ' '; - } - } - cout << endl; - } + std::vector time_info = {0, 0, 0}; + DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, + FLAGS_gpu_mem, FLAGS_cpu_threads, FLAGS_enable_mkldnn, + FLAGS_max_side_len, FLAGS_det_db_thresh, + FLAGS_det_db_box_thresh, FLAGS_det_db_unclip_ratio, + FLAGS_use_polygon_score, FLAGS_use_dilation, FLAGS_visualize, + FLAGS_use_tensorrt, FLAGS_precision); + + for (int i = 0; i < cv_all_img_names.size(); ++i) { + // LOG(INFO) << "The predict img: " << cv_all_img_names[i]; + + cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); + if (!srcimg.data) { + std::cerr << "[ERROR] image read failed! image path: " + << cv_all_img_names[i] << endl; + exit(1); } - + std::vector>> boxes; + std::vector det_times; + + det.Run(srcimg, boxes, &det_times); + + time_info[0] += det_times[0]; + time_info[1] += det_times[1]; + time_info[2] += det_times[2]; + if (FLAGS_benchmark) { - AutoLogger autolog("ocr_det", - FLAGS_use_gpu, - FLAGS_use_tensorrt, - FLAGS_enable_mkldnn, - FLAGS_cpu_threads, - 1, - "dynamic", - FLAGS_precision, - time_info, - cv_all_img_names.size()); - autolog.report(); + cout << cv_all_img_names[i] << '\t'; + for (int n = 0; n < boxes.size(); n++) { + for (int m = 0; m < boxes[n].size(); m++) { + cout << boxes[n][m][0] << ' ' << boxes[n][m][1] << ' '; + } + } + cout << endl; } - return 0; -} + } + if (FLAGS_benchmark) { + AutoLogger autolog("ocr_det", FLAGS_use_gpu, FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, FLAGS_cpu_threads, 1, "dynamic", + FLAGS_precision, time_info, cv_all_img_names.size()); + autolog.report(); + } + return 0; +} int main_rec(std::vector cv_all_img_names) { - std::vector time_info = {0, 0, 0}; - - std::string char_list_file = FLAGS_char_list_file; - if (FLAGS_benchmark) - char_list_file = FLAGS_char_list_file.substr(6); - cout << "label file: " << char_list_file << endl; - - CRNNRecognizer rec(FLAGS_rec_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_threads, - FLAGS_enable_mkldnn, char_list_file, - FLAGS_use_tensorrt, FLAGS_precision, FLAGS_rec_batch_num); + std::vector time_info = {0, 0, 0}; - std::vector img_list; - for (int i = 0; i < cv_all_img_names.size(); ++i) { - LOG(INFO) << "The predict img: " << cv_all_img_names[i]; + std::string char_list_file = FLAGS_char_list_file; + if (FLAGS_benchmark) + char_list_file = FLAGS_char_list_file.substr(6); + cout << "label file: " << char_list_file << endl; - cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); - if (!srcimg.data) { - std::cerr << "[ERROR] image read failed! image path: " << cv_all_img_names[i] << endl; - exit(1); - } - img_list.push_back(srcimg); - } - std::vector rec_times; - rec.Run(img_list, &rec_times); - time_info[0] += rec_times[0]; - time_info[1] += rec_times[1]; - time_info[2] += rec_times[2]; - - if (FLAGS_benchmark) { - AutoLogger autolog("ocr_rec", - FLAGS_use_gpu, - FLAGS_use_tensorrt, - FLAGS_enable_mkldnn, - FLAGS_cpu_threads, - FLAGS_rec_batch_num, - "dynamic", - FLAGS_precision, - time_info, - cv_all_img_names.size()); - autolog.report(); + CRNNRecognizer rec(FLAGS_rec_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, + FLAGS_gpu_mem, FLAGS_cpu_threads, FLAGS_enable_mkldnn, + char_list_file, FLAGS_use_tensorrt, FLAGS_precision, + FLAGS_rec_batch_num); + + std::vector img_list; + for (int i = 0; i < cv_all_img_names.size(); ++i) { + LOG(INFO) << "The predict img: " << cv_all_img_names[i]; + + cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); + if (!srcimg.data) { + std::cerr << "[ERROR] image read failed! image path: " + << cv_all_img_names[i] << endl; + exit(1); } - return 0; -} + img_list.push_back(srcimg); + } + std::vector rec_times; + rec.Run(img_list, &rec_times); + time_info[0] += rec_times[0]; + time_info[1] += rec_times[1]; + time_info[2] += rec_times[2]; + if (FLAGS_benchmark) { + AutoLogger autolog("ocr_rec", FLAGS_use_gpu, FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, FLAGS_cpu_threads, + FLAGS_rec_batch_num, "dynamic", FLAGS_precision, + time_info, cv_all_img_names.size()); + autolog.report(); + } + return 0; +} int main_system(std::vector cv_all_img_names) { - std::vector time_info_det = {0, 0, 0}; - std::vector time_info_rec = {0, 0, 0}; - - DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_threads, - FLAGS_enable_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, - FLAGS_det_db_box_thresh, FLAGS_det_db_unclip_ratio, - FLAGS_use_polygon_score, FLAGS_visualize, - FLAGS_use_tensorrt, FLAGS_precision); - - Classifier *cls = nullptr; - if (FLAGS_use_angle_cls) { - cls = new Classifier(FLAGS_cls_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_threads, - FLAGS_enable_mkldnn, FLAGS_cls_thresh, - FLAGS_use_tensorrt, FLAGS_precision); - } + std::vector time_info_det = {0, 0, 0}; + std::vector time_info_rec = {0, 0, 0}; - std::string char_list_file = FLAGS_char_list_file; - if (FLAGS_benchmark) - char_list_file = FLAGS_char_list_file.substr(6); - cout << "label file: " << char_list_file << endl; - - CRNNRecognizer rec(FLAGS_rec_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_threads, - FLAGS_enable_mkldnn, char_list_file, - FLAGS_use_tensorrt, FLAGS_precision, FLAGS_rec_batch_num); - - for (int i = 0; i < cv_all_img_names.size(); ++i) { - LOG(INFO) << "The predict img: " << cv_all_img_names[i]; - - cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); - if (!srcimg.data) { - std::cerr << "[ERROR] image read failed! image path: " << cv_all_img_names[i] << endl; - exit(1); - } - std::vector>> boxes; - std::vector det_times; - std::vector rec_times; - - det.Run(srcimg, boxes, &det_times); - time_info_det[0] += det_times[0]; - time_info_det[1] += det_times[1]; - time_info_det[2] += det_times[2]; - - std::vector img_list; - for (int j = 0; j < boxes.size(); j++) { - cv::Mat crop_img; - crop_img = Utility::GetRotateCropImage(srcimg, boxes[j]); - if (cls != nullptr) { - crop_img = cls->Run(crop_img); - } - img_list.push_back(crop_img); - } + DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, + FLAGS_gpu_mem, FLAGS_cpu_threads, FLAGS_enable_mkldnn, + FLAGS_max_side_len, FLAGS_det_db_thresh, + FLAGS_det_db_box_thresh, FLAGS_det_db_unclip_ratio, + FLAGS_use_polygon_score, FLAGS_use_dilation, FLAGS_visualize, + FLAGS_use_tensorrt, FLAGS_precision); + + Classifier *cls = nullptr; + if (FLAGS_use_angle_cls) { + cls = new Classifier(FLAGS_cls_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, + FLAGS_gpu_mem, FLAGS_cpu_threads, FLAGS_enable_mkldnn, + FLAGS_cls_thresh, FLAGS_use_tensorrt, FLAGS_precision); + } + + std::string char_list_file = FLAGS_char_list_file; + if (FLAGS_benchmark) + char_list_file = FLAGS_char_list_file.substr(6); + cout << "label file: " << char_list_file << endl; + + CRNNRecognizer rec(FLAGS_rec_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, + FLAGS_gpu_mem, FLAGS_cpu_threads, FLAGS_enable_mkldnn, + char_list_file, FLAGS_use_tensorrt, FLAGS_precision, + FLAGS_rec_batch_num); + + for (int i = 0; i < cv_all_img_names.size(); ++i) { + LOG(INFO) << "The predict img: " << cv_all_img_names[i]; - rec.Run(img_list, &rec_times); - time_info_rec[0] += rec_times[0]; - time_info_rec[1] += rec_times[1]; - time_info_rec[2] += rec_times[2]; + cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); + if (!srcimg.data) { + std::cerr << "[ERROR] image read failed! image path: " + << cv_all_img_names[i] << endl; + exit(1); } - - if (FLAGS_benchmark) { - AutoLogger autolog_det("ocr_det", - FLAGS_use_gpu, - FLAGS_use_tensorrt, - FLAGS_enable_mkldnn, - FLAGS_cpu_threads, - 1, - "dynamic", - FLAGS_precision, - time_info_det, - cv_all_img_names.size()); - AutoLogger autolog_rec("ocr_rec", - FLAGS_use_gpu, - FLAGS_use_tensorrt, - FLAGS_enable_mkldnn, - FLAGS_cpu_threads, - FLAGS_rec_batch_num, - "dynamic", - FLAGS_precision, - time_info_rec, - cv_all_img_names.size()); - autolog_det.report(); - std::cout << endl; - autolog_rec.report(); - } - return 0; -} + std::vector>> boxes; + std::vector det_times; + std::vector rec_times; + det.Run(srcimg, boxes, &det_times); + time_info_det[0] += det_times[0]; + time_info_det[1] += det_times[1]; + time_info_det[2] += det_times[2]; -void check_params(char* mode) { - if (strcmp(mode, "det")==0) { - if (FLAGS_det_model_dir.empty() || FLAGS_image_dir.empty()) { - std::cout << "Usage[det]: ./ppocr --det_model_dir=/PATH/TO/DET_INFERENCE_MODEL/ " - << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; - exit(1); - } + std::vector img_list; + for (int j = 0; j < boxes.size(); j++) { + cv::Mat crop_img; + crop_img = Utility::GetRotateCropImage(srcimg, boxes[j]); + if (cls != nullptr) { + crop_img = cls->Run(crop_img); + } + img_list.push_back(crop_img); } - if (strcmp(mode, "rec")==0) { - if (FLAGS_rec_model_dir.empty() || FLAGS_image_dir.empty()) { - std::cout << "Usage[rec]: ./ppocr --rec_model_dir=/PATH/TO/REC_INFERENCE_MODEL/ " - << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; - exit(1); - } + + rec.Run(img_list, &rec_times); + time_info_rec[0] += rec_times[0]; + time_info_rec[1] += rec_times[1]; + time_info_rec[2] += rec_times[2]; + } + + if (FLAGS_benchmark) { + AutoLogger autolog_det("ocr_det", FLAGS_use_gpu, FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, FLAGS_cpu_threads, 1, "dynamic", + FLAGS_precision, time_info_det, + cv_all_img_names.size()); + AutoLogger autolog_rec("ocr_rec", FLAGS_use_gpu, FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, FLAGS_cpu_threads, + FLAGS_rec_batch_num, "dynamic", FLAGS_precision, + time_info_rec, cv_all_img_names.size()); + autolog_det.report(); + std::cout << endl; + autolog_rec.report(); + } + return 0; +} + +void check_params(char *mode) { + if (strcmp(mode, "det") == 0) { + if (FLAGS_det_model_dir.empty() || FLAGS_image_dir.empty()) { + std::cout << "Usage[det]: ./ppocr " + "--det_model_dir=/PATH/TO/DET_INFERENCE_MODEL/ " + << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; + exit(1); } - if (strcmp(mode, "system")==0) { - if ((FLAGS_det_model_dir.empty() || FLAGS_rec_model_dir.empty() || FLAGS_image_dir.empty()) || - (FLAGS_use_angle_cls && FLAGS_cls_model_dir.empty())) { - std::cout << "Usage[system without angle cls]: ./ppocr --det_model_dir=/PATH/TO/DET_INFERENCE_MODEL/ " - << "--rec_model_dir=/PATH/TO/REC_INFERENCE_MODEL/ " - << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; - std::cout << "Usage[system with angle cls]: ./ppocr --det_model_dir=/PATH/TO/DET_INFERENCE_MODEL/ " - << "--use_angle_cls=true " - << "--cls_model_dir=/PATH/TO/CLS_INFERENCE_MODEL/ " - << "--rec_model_dir=/PATH/TO/REC_INFERENCE_MODEL/ " - << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; - exit(1); - } + } + if (strcmp(mode, "rec") == 0) { + if (FLAGS_rec_model_dir.empty() || FLAGS_image_dir.empty()) { + std::cout << "Usage[rec]: ./ppocr " + "--rec_model_dir=/PATH/TO/REC_INFERENCE_MODEL/ " + << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; + exit(1); } - if (FLAGS_precision != "fp32" && FLAGS_precision != "fp16" && FLAGS_precision != "int8") { - cout << "precison should be 'fp32'(default), 'fp16' or 'int8'. " << endl; - exit(1); + } + if (strcmp(mode, "system") == 0) { + if ((FLAGS_det_model_dir.empty() || FLAGS_rec_model_dir.empty() || + FLAGS_image_dir.empty()) || + (FLAGS_use_angle_cls && FLAGS_cls_model_dir.empty())) { + std::cout << "Usage[system without angle cls]: ./ppocr " + "--det_model_dir=/PATH/TO/DET_INFERENCE_MODEL/ " + << "--rec_model_dir=/PATH/TO/REC_INFERENCE_MODEL/ " + << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; + std::cout << "Usage[system with angle cls]: ./ppocr " + "--det_model_dir=/PATH/TO/DET_INFERENCE_MODEL/ " + << "--use_angle_cls=true " + << "--cls_model_dir=/PATH/TO/CLS_INFERENCE_MODEL/ " + << "--rec_model_dir=/PATH/TO/REC_INFERENCE_MODEL/ " + << "--image_dir=/PATH/TO/INPUT/IMAGE/" << std::endl; + exit(1); } + } + if (FLAGS_precision != "fp32" && FLAGS_precision != "fp16" && + FLAGS_precision != "int8") { + cout << "precison should be 'fp32'(default), 'fp16' or 'int8'. " << endl; + exit(1); + } } - int main(int argc, char **argv) { - if (argc<=1 || (strcmp(argv[1], "det")!=0 && strcmp(argv[1], "rec")!=0 && strcmp(argv[1], "system")!=0)) { - std::cout << "Please choose one mode of [det, rec, system] !" << std::endl; - return -1; - } - std::cout << "mode: " << argv[1] << endl; - - // Parsing command-line - google::ParseCommandLineFlags(&argc, &argv, true); - check_params(argv[1]); - - if (!PathExists(FLAGS_image_dir)) { - std::cerr << "[ERROR] image path not exist! image_dir: " << FLAGS_image_dir << endl; - exit(1); - } - - std::vector cv_all_img_names; - cv::glob(FLAGS_image_dir, cv_all_img_names); - std::cout << "total images num: " << cv_all_img_names.size() << endl; - - if (strcmp(argv[1], "det")==0) { - return main_det(cv_all_img_names); - } - if (strcmp(argv[1], "rec")==0) { - return main_rec(cv_all_img_names); - } - if (strcmp(argv[1], "system")==0) { - return main_system(cv_all_img_names); - } + if (argc <= 1 || + (strcmp(argv[1], "det") != 0 && strcmp(argv[1], "rec") != 0 && + strcmp(argv[1], "system") != 0)) { + std::cout << "Please choose one mode of [det, rec, system] !" << std::endl; + return -1; + } + std::cout << "mode: " << argv[1] << endl; + + // Parsing command-line + google::ParseCommandLineFlags(&argc, &argv, true); + check_params(argv[1]); + + if (!PathExists(FLAGS_image_dir)) { + std::cerr << "[ERROR] image path not exist! image_dir: " << FLAGS_image_dir + << endl; + exit(1); + } + + std::vector cv_all_img_names; + cv::glob(FLAGS_image_dir, cv_all_img_names); + std::cout << "total images num: " << cv_all_img_names.size() << endl; + if (strcmp(argv[1], "det") == 0) { + return main_det(cv_all_img_names); + } + if (strcmp(argv[1], "rec") == 0) { + return main_rec(cv_all_img_names); + } + if (strcmp(argv[1], "system") == 0) { + return main_system(cv_all_img_names); + } } diff --git a/deploy/cpp_infer/src/ocr_det.cpp b/deploy/cpp_infer/src/ocr_det.cpp index a69f5ca1bd3ee7665f8b2f5610c67dd6feb7eb54..ad78999449d94dcaf2e336087de5c6837f3b233c 100644 --- a/deploy/cpp_infer/src/ocr_det.cpp +++ b/deploy/cpp_infer/src/ocr_det.cpp @@ -14,7 +14,6 @@ #include - namespace PaddleOCR { void DBDetector::LoadModel(const std::string &model_dir) { @@ -30,13 +29,10 @@ void DBDetector::LoadModel(const std::string &model_dir) { if (this->precision_ == "fp16") { precision = paddle_infer::Config::Precision::kHalf; } - if (this->precision_ == "int8") { + if (this->precision_ == "int8") { precision = paddle_infer::Config::Precision::kInt8; - } - config.EnableTensorRtEngine( - 1 << 20, 10, 3, - precision, - false, false); + } + config.EnableTensorRtEngine(1 << 20, 10, 3, precision, false, false); std::map> min_input_shape = { {"x", {1, 3, 50, 50}}, {"conv2d_92.tmp_0", {1, 96, 20, 20}}, @@ -105,7 +101,7 @@ void DBDetector::Run(cv::Mat &img, cv::Mat srcimg; cv::Mat resize_img; img.copyTo(srcimg); - + auto preprocess_start = std::chrono::steady_clock::now(); this->resize_op_.Run(img, resize_img, this->max_side_len_, ratio_h, ratio_w, this->use_tensorrt_); @@ -116,16 +112,16 @@ void DBDetector::Run(cv::Mat &img, std::vector input(1 * 3 * resize_img.rows * resize_img.cols, 0.0f); this->permute_op_.Run(&resize_img, input.data()); auto preprocess_end = std::chrono::steady_clock::now(); - + // Inference. auto input_names = this->predictor_->GetInputNames(); auto input_t = this->predictor_->GetInputHandle(input_names[0]); input_t->Reshape({1, 3, resize_img.rows, resize_img.cols}); auto inference_start = std::chrono::steady_clock::now(); input_t->CopyFromCpu(input.data()); - + this->predictor_->Run(); - + std::vector out_data; auto output_names = this->predictor_->GetOutputNames(); auto output_t = this->predictor_->GetOutputHandle(output_names[0]); @@ -136,7 +132,7 @@ void DBDetector::Run(cv::Mat &img, out_data.resize(out_num); output_t->CopyToCpu(out_data.data()); auto inference_end = std::chrono::steady_clock::now(); - + auto postprocess_start = std::chrono::steady_clock::now(); int n2 = output_shape[2]; int n3 = output_shape[3]; @@ -157,24 +153,29 @@ void DBDetector::Run(cv::Mat &img, const double maxvalue = 255; cv::Mat bit_map; cv::threshold(cbuf_map, bit_map, threshold, maxvalue, cv::THRESH_BINARY); - cv::Mat dilation_map; - cv::Mat dila_ele = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2, 2)); - cv::dilate(bit_map, dilation_map, dila_ele); + if (this->use_dilation_) { + cv::Mat dila_ele = + cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2, 2)); + cv::dilate(bit_map, bit_map, dila_ele); + } + boxes = post_processor_.BoxesFromBitmap( - pred_map, dilation_map, this->det_db_box_thresh_, - this->det_db_unclip_ratio_, this->use_polygon_score_); + pred_map, bit_map, this->det_db_box_thresh_, this->det_db_unclip_ratio_, + this->use_polygon_score_); boxes = post_processor_.FilterTagDetRes(boxes, ratio_h, ratio_w, srcimg); auto postprocess_end = std::chrono::steady_clock::now(); std::cout << "Detected boxes num: " << boxes.size() << endl; - std::chrono::duration preprocess_diff = preprocess_end - preprocess_start; + std::chrono::duration preprocess_diff = + preprocess_end - preprocess_start; times->push_back(double(preprocess_diff.count() * 1000)); std::chrono::duration inference_diff = inference_end - inference_start; times->push_back(double(inference_diff.count() * 1000)); - std::chrono::duration postprocess_diff = postprocess_end - postprocess_start; + std::chrono::duration postprocess_diff = + postprocess_end - postprocess_start; times->push_back(double(postprocess_diff.count() * 1000)); - + //// visualization if (this->visualize_) { Utility::VisualizeBboxes(srcimg, boxes); diff --git a/doc/doc_ch/detection.md b/doc/doc_ch/detection.md index 4114d9f2e6c584566dbfc6d9280074d767848ce1..9bf3bb85edfbb728b0e991b265d30a579ac84291 100644 --- a/doc/doc_ch/detection.md +++ b/doc/doc_ch/detection.md @@ -10,6 +10,7 @@ * [2.1 启动训练](#21-----) * [2.2 断点训练](#22-----) * [2.3 更换Backbone 训练](#23---backbone---) + * [2.4 知识蒸馏训练](#24---distill---) - [3. 模型评估与预测](#3--------) * [3.1 指标评估](#31-----) * [3.2 测试检测效果](#32-------) @@ -182,6 +183,15 @@ args1: args1 **注意**:如果要更换网络的其他模块,可以参考[文档](./add_new_algorithm.md)。 + + + +## 2.4 知识蒸馏训练 + +PaddleOCR支持了基于知识蒸馏的检测模型训练过程,更多内容可以参考[知识蒸馏说明文档](./knowledge_distillation.md)。 + + + # 3. 模型评估与预测 diff --git a/doc/doc_ch/recognition.md b/doc/doc_ch/recognition.md index 51a4b69af0a66a61dd99f95a29a909124e6283a1..26887f41cc73f74f592eea9d04fc9167c30fc68c 100644 --- a/doc/doc_ch/recognition.md +++ b/doc/doc_ch/recognition.md @@ -11,6 +11,7 @@ - [2.1 数据增强](#数据增强) - [2.2 通用模型训练](#通用模型训练) - [2.3 多语言模型训练](#多语言模型训练) + - [2.4 知识蒸馏训练](#知识蒸馏训练) - [3 评估](#评估) - [4 预测](#预测) - [5 转Inference模型测试](#Inference) @@ -368,6 +369,13 @@ Eval: label_file_list: ["./train_data/french_val.txt"] ... ``` + + + +### 2.4 知识蒸馏训练 + +PaddleOCR支持了基于知识蒸馏的文本识别模型训练过程,更多内容可以参考[知识蒸馏说明文档](./knowledge_distillation.md)。 + ## 3 评估 diff --git a/doc/doc_en/detection_en.md b/doc/doc_en/detection_en.md index 9f54dc06b9be16553518c301296e38e62cf1c8ec..618e20fb5e2a9a7afd67bb7d15646971b88365ee 100644 --- a/doc/doc_en/detection_en.md +++ b/doc/doc_en/detection_en.md @@ -9,6 +9,7 @@ This section uses the icdar2015 dataset as an example to introduce the training, * [2.1 Start Training](#21-start-training) * [2.2 Load Trained Model and Continue Training](#22-load-trained-model-and-continue-training) * [2.3 Training with New Backbone](#23-training-with-new-backbone) + * [2.4 Training with knowledge distillation](#24) - [3. Evaluation and Test](#3-evaluation-and-test) * [3.1 Evaluation](#31-evaluation) * [3.2 Test](#32-test) @@ -174,6 +175,11 @@ After adding the four-part modules of the network, you only need to configure th **NOTE**: More details about replace Backbone and other mudule can be found in [doc](add_new_algorithm_en.md). + +### 2.4 Training with knowledge distillation + +Knowledge distillation is supported in PaddleOCR for text detection training process. For more details, please refer to [doc](./knowledge_distillation_en.md). + ## 3. Evaluation and Test ### 3.1 Evaluation diff --git a/doc/doc_en/recognition_en.md b/doc/doc_en/recognition_en.md index 51857ba16b7773ef38452fad6aa070f2117a9086..20f4b9457b2fd05058bd2b723048f94de92605b6 100644 --- a/doc/doc_en/recognition_en.md +++ b/doc/doc_en/recognition_en.md @@ -10,6 +10,7 @@ - [2.1 Data Augmentation](#Data_Augmentation) - [2.2 General Training](#Training) - [2.3 Multi-language Training](#Multi_language) + - [2.4 Training with Knowledge Distillation](#kd) - [3. Evaluation](#EVALUATION) @@ -361,6 +362,12 @@ Eval: ... ``` + + +### 2.4 Training with Knowledge Distillation + +Knowledge distillation is supported in PaddleOCR for text recognition training process. For more details, please refer to [doc](./knowledge_distillation_en.md). + ## 3. Evalution diff --git a/ppocr/losses/basic_loss.py b/ppocr/losses/basic_loss.py index fc64c133a4ad5a97530e2ad259ad38267188f6d3..b19ce57dcaf463d8be30fd1111b521d632308786 100644 --- a/ppocr/losses/basic_loss.py +++ b/ppocr/losses/basic_loss.py @@ -95,9 +95,15 @@ class DMLLoss(nn.Layer): self.act = None self.use_log = use_log - self.jskl_loss = KLJSLoss(mode="js") + def _kldiv(self, x, target): + eps = 1.0e-10 + loss = target * (paddle.log(target + eps) - x) + # batch mean loss + loss = paddle.sum(loss) / loss.shape[0] + return loss + def forward(self, out1, out2): if self.act is not None: out1 = self.act(out1) @@ -106,9 +112,8 @@ class DMLLoss(nn.Layer): # for recognition distillation, log is needed for feature map log_out1 = paddle.log(out1) log_out2 = paddle.log(out2) - loss = (F.kl_div( - log_out1, out2, reduction='batchmean') + F.kl_div( - log_out2, out1, reduction='batchmean')) / 2.0 + loss = ( + self._kldiv(log_out1, out2) + self._kldiv(log_out2, out1)) / 2.0 else: # for detection distillation log is not needed loss = self.jskl_loss(out1, out2) diff --git a/test_tipc/configs/ch_PP-OCRv2_rec/train_infer_python.txt b/test_tipc/configs/ch_PP-OCRv2_rec/train_infer_python.txt index b2de2a5e52f75071dc0d3b8e8f26d8b87cfecfd7..188eb3ccc5f7aa2b3724dc1fb7132af090c22ffa 100644 --- a/test_tipc/configs/ch_PP-OCRv2_rec/train_infer_python.txt +++ b/test_tipc/configs/ch_PP-OCRv2_rec/train_infer_python.txt @@ -49,5 +49,5 @@ inference:tools/infer/predict_rec.py null:null --benchmark:True null:null - - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,320]}] diff --git a/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt b/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt index 9102382fd314101753fdc895d3219329b42263f9..03d749f55765b2ea9e82d538cb4e6fb3d29e0b9f 100644 --- a/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt +++ b/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt @@ -49,5 +49,5 @@ inference:tools/infer/predict_rec.py null:null --benchmark:True null:null - - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,320]}] diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec/train_infer_python.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec/train_infer_python.txt index 63d1f0583ea114ed89b7f2cdc6e2299e6bc8f2a4..5086f80d7bad4fb359f152cc1dc7195017aa31c3 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec/train_infer_python.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/train_infer_python.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/train_infer_python.txt index c5dfa46f3ef73e796d6857be987c24d89a5dd3d4..77494ac347a73f61d18c070075db476a093c3f62 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/train_infer_python.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/train_infer_python.txt @@ -48,4 +48,6 @@ inference:tools/infer/predict_rec.py --image_dir:./inference/rec_inference null:null --benchmark:True -null:null \ No newline at end of file +null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,320]}] \ No newline at end of file diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/train_infer_python.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/train_infer_python.txt index afbf2ef5e19344e8144e1cea81e3671fdd44559d..94909ec340c1bbc582dd60aa947f1905580b8966 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/train_infer_python.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/train_infer_python.txt @@ -48,4 +48,6 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ppocr_ke --image_dir:./inference/rec_inference --save_log_path:./test/output/ --benchmark:True -null:null \ No newline at end of file +null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,320]}] diff --git a/test_tipc/configs/ch_ppocr_server_v2.0_rec/train_infer_python.txt b/test_tipc/configs/ch_ppocr_server_v2.0_rec/train_infer_python.txt index c42edbee4dd2a26afff94f6028ca7a8f4170648e..78a046c503686762688ce08097d68479f1023879 100644 --- a/test_tipc/configs/ch_ppocr_server_v2.0_rec/train_infer_python.txt +++ b/test_tipc/configs/ch_ppocr_server_v2.0_rec/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] diff --git a/test_tipc/configs/rec_mtb_nrtr/train_infer_python.txt b/test_tipc/configs/rec_mtb_nrtr/train_infer_python.txt index 2adca464a63d548f2b218ed1de91692ed25da89a..de6de5a0caa36fb3ff89d8dbf5c7ff8b7965ca7f 100644 --- a/test_tipc/configs/rec_mtb_nrtr/train_infer_python.txt +++ b/test_tipc/configs/rec_mtb_nrtr/train_infer_python.txt @@ -49,4 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/EN_symbo --save_log_path:./test/output/ --benchmark:True null:null - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[1,32,100]}] diff --git a/test_tipc/configs/rec_mv3_none_bilstm_ctc_v2.0/train_infer_python.txt b/test_tipc/configs/rec_mv3_none_bilstm_ctc_v2.0/train_infer_python.txt index ac565d8c55b1924e7a39fd8e36456a74fbbce042..e67dd1509054b34bfac6a36eaaca16fa31c0f1a0 100644 --- a/test_tipc/configs/rec_mv3_none_bilstm_ctc_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_mv3_none_bilstm_ctc_v2.0/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] \ No newline at end of file diff --git a/test_tipc/configs/rec_mv3_none_none_ctc_v2.0/train_infer_python.txt b/test_tipc/configs/rec_mv3_none_none_ctc_v2.0/train_infer_python.txt index 947399a83cedc1f4262374e2c5ba5f3221561f0d..aa3e88d284fe557c109cb8d794e2caecbec7a7ee 100644 --- a/test_tipc/configs/rec_mv3_none_none_ctc_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_mv3_none_none_ctc_v2.0/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] \ No newline at end of file diff --git a/test_tipc/configs/rec_mv3_tps_bilstm_att_v2.0/train_infer_python.txt b/test_tipc/configs/rec_mv3_tps_bilstm_att_v2.0/train_infer_python.txt index 5fcfeee5e1835504d08cf24b0180a5af105be092..32df669f9779f730d78d128d8aceac022ce78616 100644 --- a/test_tipc/configs/rec_mv3_tps_bilstm_att_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_mv3_tps_bilstm_att_v2.0/train_infer_python.txt @@ -49,4 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] diff --git a/test_tipc/configs/rec_mv3_tps_bilstm_ctc_v2.0/train_infer_python.txt b/test_tipc/configs/rec_mv3_tps_bilstm_ctc_v2.0/train_infer_python.txt index ac3fce6141ccbf96169d862b8b92f59af597db56..7a3096eb1e3a94bf3967a80d49b622603ae06ff8 100644 --- a/test_tipc/configs/rec_mv3_tps_bilstm_ctc_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_mv3_tps_bilstm_ctc_v2.0/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] diff --git a/test_tipc/configs/rec_r31_sar/train_infer_python.txt b/test_tipc/configs/rec_r31_sar/train_infer_python.txt index e4d7825243378709b965f59740c0360f11bdb957..c5018500f9a58297b30729e9f68b42806a7631e2 100644 --- a/test_tipc/configs/rec_r31_sar/train_infer_python.txt +++ b/test_tipc/configs/rec_r31_sar/train_infer_python.txt @@ -49,4 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/dict90.t --save_log_path:./test/output/ --benchmark:True null:null - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,48,48,160]}] diff --git a/test_tipc/configs/rec_r34_vd_none_bilstm_ctc_v2.0/train_infer_python.txt b/test_tipc/configs/rec_r34_vd_none_bilstm_ctc_v2.0/train_infer_python.txt index 99f86872574bc300d3447efc0e4c83eaa88aab6c..02cea56fbe922bb94cceb77c079371f180cac618 100644 --- a/test_tipc/configs/rec_r34_vd_none_bilstm_ctc_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_r34_vd_none_bilstm_ctc_v2.0/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] \ No newline at end of file diff --git a/test_tipc/configs/rec_r34_vd_none_none_ctc_v2.0/train_infer_python.txt b/test_tipc/configs/rec_r34_vd_none_none_ctc_v2.0/train_infer_python.txt index fb1ece49f71338307bfdf30714cd68cb382ea5e2..5e7c1d34314cfc8aab1c97d5f6e74b0dd75f496a 100644 --- a/test_tipc/configs/rec_r34_vd_none_none_ctc_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_r34_vd_none_none_ctc_v2.0/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] \ No newline at end of file diff --git a/test_tipc/configs/rec_r34_vd_tps_bilstm_att_v2.0/train_infer_python.txt b/test_tipc/configs/rec_r34_vd_tps_bilstm_att_v2.0/train_infer_python.txt index acc9749f08b42f7fa2200da7ef865f710afc77c3..9cee5d0b7d01eb5ae04c6ae9fef9990d3788a741 100644 --- a/test_tipc/configs/rec_r34_vd_tps_bilstm_att_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_r34_vd_tps_bilstm_att_v2.0/train_infer_python.txt @@ -49,4 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] diff --git a/test_tipc/configs/rec_r34_vd_tps_bilstm_ctc_v2.0/train_infer_python.txt b/test_tipc/configs/rec_r34_vd_tps_bilstm_ctc_v2.0/train_infer_python.txt index d11850528604074e9bb3d3d92b58ec709238b24b..5b5ba0fd01c02b3b16d147edaf93495aeeaab7bf 100644 --- a/test_tipc/configs/rec_r34_vd_tps_bilstm_ctc_v2.0/train_infer_python.txt +++ b/test_tipc/configs/rec_r34_vd_tps_bilstm_ctc_v2.0/train_infer_python.txt @@ -49,3 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[3,32,100]}] diff --git a/test_tipc/configs/rec_r50_fpn_vd_none_srn/train_infer_python.txt b/test_tipc/configs/rec_r50_fpn_vd_none_srn/train_infer_python.txt index fb135df60b7716fd46a48482c0d7e8a3faca579a..187c1cc13a72c2d0ba8f7b57c2b9f5b7ba388d79 100644 --- a/test_tipc/configs/rec_r50_fpn_vd_none_srn/train_infer_python.txt +++ b/test_tipc/configs/rec_r50_fpn_vd_none_srn/train_infer_python.txt @@ -49,4 +49,5 @@ inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ic15_dic --save_log_path:./test/output/ --benchmark:True null:null - +===========================infer_benchmark_params========================== +random_infer_input:[{float32,[1,64,256]}] diff --git a/tools/infer/predict_cls.py b/tools/infer/predict_cls.py index ab3f4b04f0c306aaf7e26eb98e781938b7528275..ed2f47c04de6f4ab6a874db052e953a1ce4e0b76 100755 --- a/tools/infer/predict_cls.py +++ b/tools/infer/predict_cls.py @@ -16,7 +16,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '../..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '../..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 95a099451bb12ef537e6f942df88da91df48038f..2c389f0e49767a40dd6f397f5445d5673e8dae55 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -16,7 +16,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '../..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '../..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer/predict_e2e.py b/tools/infer/predict_e2e.py index c00d101aa601c05230da39bc19f0e5068bc80aa2..fb2859f0c7e0d3aa0b87dbe11123dfc88f4b4e8e 100755 --- a/tools/infer/predict_e2e.py +++ b/tools/infer/predict_e2e.py @@ -16,7 +16,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '../..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '../..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 575e1925c9a84b1de2d98f14567623ada6dabcb8..eebb2b3ba4a1489512de3b977ddf9f1ef8f67ec1 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -16,7 +16,7 @@ import sys from PIL import Image __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '../..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '../..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer/predict_system.py b/tools/infer/predict_system.py index b4e316d6a5edf464abd846ad2129f5373fc2a36f..63b635c1114d079478e34682d7c94c433bd21ffa 100755 --- a/tools/infer/predict_system.py +++ b/tools/infer/predict_system.py @@ -17,7 +17,7 @@ import subprocess __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '../..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '../..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_cls.py b/tools/infer_cls.py index ab6a49120b6e22621b462b680a161d70ee965e78..4be30bbb3c2f8bbf6a59179220faa942e6cc27b8 100755 --- a/tools/infer_cls.py +++ b/tools/infer_cls.py @@ -23,7 +23,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_det.py b/tools/infer_det.py index 9d2daf13ad6ad3de396ea1587c3d25cccb126eac..1acecedf3e42fe67a93644a7f06c07c8b6bea2e3 100755 --- a/tools/infer_det.py +++ b/tools/infer_det.py @@ -23,7 +23,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_e2e.py b/tools/infer_e2e.py index 96dbac8e83cb8651ca19c05d5a680a4efebc6ff6..f3d5712fdda21faf04b95b7a2d5d3092af1b5011 100755 --- a/tools/infer_e2e.py +++ b/tools/infer_e2e.py @@ -23,7 +23,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_kie.py b/tools/infer_kie.py index 16294e59cc51727f39af77d16255ef4d0f2a1bd8..0cb0b8702cbd7ea74a7b7fcff69122731578a1bd 100755 --- a/tools/infer_kie.py +++ b/tools/infer_kie.py @@ -24,7 +24,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_rec.py b/tools/infer_rec.py index adc3c1c3c49dcaad5ec8657f5d32b2eca8e10a40..02b3afd8a1b32c3c9c1e4a9a121f08b58c10151d 100755 --- a/tools/infer_rec.py +++ b/tools/infer_rec.py @@ -24,7 +24,7 @@ import json __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_table.py b/tools/infer_table.py index c73e384046d1fadbbec4bf43a63e13aa8d54fc6c..66c2da4421a313c634d27eb7a1013638a7c005ed 100644 --- a/tools/infer_table.py +++ b/tools/infer_table.py @@ -24,7 +24,7 @@ import json __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' diff --git a/tools/infer_vqa_token_ser.py b/tools/infer_vqa_token_ser.py index 5859c28f92085bda67627af2a10acc56cb36d932..83ed72b392e627c161903c3945f57be0abfabc2b 100755 --- a/tools/infer_vqa_token_ser.py +++ b/tools/infer_vqa_token_ser.py @@ -23,7 +23,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' import cv2 diff --git a/tools/infer_vqa_token_ser_re.py b/tools/infer_vqa_token_ser_re.py index fd62ace8aef35db168537580513139e429e88cc3..1e5f6f76d6b0599089069ab30f76b3479c7c90b4 100755 --- a/tools/infer_vqa_token_ser_re.py +++ b/tools/infer_vqa_token_ser_re.py @@ -23,7 +23,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) os.environ["FLAGS_allocator_strategy"] = 'auto_growth' import cv2 diff --git a/tools/train.py b/tools/train.py index 506e0f7fa87fe8afc82cbb12d553a8da4ba298e2..f6cd0e7d12cdc572dd8d2c402e03e160001a9f4a 100755 --- a/tools/train.py +++ b/tools/train.py @@ -21,7 +21,7 @@ import sys __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) -sys.path.append(os.path.abspath(os.path.join(__dir__, '..'))) +sys.path.insert(0, os.path.abspath(os.path.join(__dir__, '..'))) import yaml import paddle