From 3f2d384faa95a1ad90b0475494f0624f2b900670 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 11 May 2020 15:27:52 +0800 Subject: [PATCH 1/9] =?UTF-8?q?add=20doc=E3=80=81infer=5Fdet.py=E3=80=81re?= =?UTF-8?q?quirments.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/det/det_db_mv3.yml | 1 + doc/detection.md | 69 ++++++++++++++++ doc/installation.md | 25 ++++++ requirments.txt | 3 + tools/infer/predict_system.py | 26 +++++- tools/infer/utility.py | 16 ++-- tools/infer_det.py | 148 ++++++++++++++++++++++++++++++++++ 7 files changed, 281 insertions(+), 7 deletions(-) create mode 100644 doc/detection.md create mode 100644 doc/installation.md create mode 100644 requirments.txt create mode 100755 tools/infer_det.py diff --git a/configs/det/det_db_mv3.yml b/configs/det/det_db_mv3.yml index a41c901e75..197b12044b 100755 --- a/configs/det/det_db_mv3.yml +++ b/configs/det/det_db_mv3.yml @@ -12,6 +12,7 @@ Global: image_shape: [3, 640, 640] reader_yml: ./configs/det/det_db_icdar15_reader.yml pretrain_weights: ./pretrain_models/MobileNetV3_pretrained/MobileNetV3_large_x0_5_pretrained/ + checkpoints: save_res_path: ./output/predicts_db.txt Architecture: diff --git a/doc/detection.md b/doc/detection.md new file mode 100644 index 0000000000..b8b8a9cc38 --- /dev/null +++ b/doc/detection.md @@ -0,0 +1,69 @@ +# 文字检测 + +本节以icdar15数据集为例,介绍PaddleOCR中检测模型的使用方式。 + +## 3.1 数据准备 +icdar2015数据集可以从[官网](https://rrc.cvc.uab.es/?ch=4&com=downloads)下载到,首次下载需注册。 + +将下载到的数据集解压到工作目录下,假设解压在/PaddleOCR/train_data/ 下。另外,PaddleOCR将零散的标注文件整理成单独的标注文件 +,您可以通过wget的方式进行下载。 +``` +wget -P /PaddleOCR/train_data/ 训练标注文件链接 +wget -P /PaddleOCR/train_data/ 测试标注文件链接 +``` + +解压数据集和下载标注文件后,/PaddleOCR/train_data/ 有两个文件夹和两个文件,分别是: +``` +/PaddleOCR/train_data/ + └─ icdar_c4_train_imgs/ icdar数据集的训练数据 + └─ ch4_test_images/ icdar数据集的测试数据 + └─ train_icdar2015_label.txt icdar数据集的训练标注 + └─ test_icdar2015_label.txt icdar数据集的测试标注 +``` + +提供的标注文件格式为: +``` +" 图像文件名 json.dumps编码的图像标注信息" +ch4_test_images/img_61.jpg [{"transcription": "MASA", "points": [[310, 104], [416, 141], [418, 216], [312, 179]], ...}] +``` +json.dumps编码前的图像标注信息是包含多个字典的list,字典中的points表示文本框的位置,如果您想在其他数据集上训练PaddleOCR, +可以按照上述形式构建标注文件。 + + +## 3.2 快速启动训练 + +首先下载pretrain model,目前支持两种backbone,分别是MobileNetV3、ResNet50,您可以根据需求使用PaddleClas中的模型更换 +backbone。 +``` +# 下载MobileNetV3的预训练模型 +wget -P /PaddleOCR/pretrained_model/ 模型链接 +# 下载ResNet50的预训练模型 +wget -P /PaddleOCR/pretrained_model/ 模型链接 +``` + +**启动训练** +``` +cd PaddleOCR/ +python3 tools/train.py -c configs/det/det_db_mv3.yml +``` + +上述指令中,通过-c 选择训练使用configs/det/det_db_mv3.yml配置文件。 +有关配置文件的详细解释,请参考[链接]()。 + +您也可以通过-o参数在不需要修改yml文件的情况下,改变训练的参数,比如,调整训练的学习率为0.0001 +``` +python3 tools/train.py -c configs/det/det_db_mv3.yml -o Optimizer.base_lr=0.0001 +``` + + +## 3.3 指标评估 + +PaddleOCR计算三个OCR检测相关的指标,分别是:Precision、Recall、Hmean。 + +运行如下代码,根据配置文件det_db_mv3.yml中save_res_path指定的测试集检测结果文件,计算评估指标。 + +``` +python3 tools/eval.py -c configs/det/det_db_mv3.yml -o checkpoints ./output/best_accuracy +``` + +## 3.4 测试检测效果 diff --git a/doc/installation.md b/doc/installation.md new file mode 100644 index 0000000000..5eca1dfe6a --- /dev/null +++ b/doc/installation.md @@ -0,0 +1,25 @@ +### 2.1 快速安装 + +我们提供了PaddleOCR开发环境的docker,您可以pull我们提供的docker运行PaddleOCR的环境。 + +1. 准备docker环境。第一次使用这个镜像,会自动下载该镜像,请耐心等待。 +``` +# 切换到工作目录下 +cd /home/Projects +# 创建一个名字为pdocr的docker容器,并将当前目录映射到容器的/data目录下 +sudo nvidia-docker run --name pdocr -v $PWD:/data --network=host -it paddlepaddle/paddle:1.7.2-gpu-cuda10.0-cudnn7 /bin/bash +``` + +2. 克隆PaddleOCR repo代码 +``` +apt-get update +apt-get install git +git clone https://github.com/PaddlePaddle/PaddleOCR +``` + +3. 安装第三方库 +``` +cd PaddleOCR +pip3 install --upgrade pip +pip3 install -r requirements.txt +``` diff --git a/requirments.txt b/requirments.txt new file mode 100644 index 0000000000..e9bf32a993 --- /dev/null +++ b/requirments.txt @@ -0,0 +1,3 @@ +shapely +imgaug +pyclipper \ No newline at end of file diff --git a/tools/infer/predict_system.py b/tools/infer/predict_system.py index defa061595..4907a7ccf0 100755 --- a/tools/infer/predict_system.py +++ b/tools/infer/predict_system.py @@ -64,15 +64,39 @@ class TextSystem(object): if dt_boxes is None: return None, None img_crop_list = [] + + dt_boxes = sorted_boxes(dt_boxes) + for bno in range(len(dt_boxes)): tmp_box = copy.deepcopy(dt_boxes[bno]) img_crop = self.get_rotate_crop_image(ori_im, tmp_box) img_crop_list.append(img_crop) rec_res, elapse = self.text_recognizer(img_crop_list) - # self.print_draw_crop_rec_res(img_crop_list, rec_res) + # self.print_draw_crop_rec_res(img_crop_list, rec_res) return dt_boxes, rec_res +def sorted_boxes(dt_boxes): + """ + Sort text boxes in order from top to bottom, left to right + args: + dt_boxes(array):detected text boxes with shape [4, 2] + return: + sorted boxes(array) with shape [4, 2] + """ + num_boxes = dt_boxes.shape[0] + sorted_boxes = sorted(dt_boxes, key=lambda x: x[0][1]) + _boxes = list(sorted_boxes) + + for i in range(num_boxes - 1): + if abs(_boxes[i+1][0][1] - _boxes[i][0][1]) < 10 and \ + (_boxes[i + 1][0][0] < _boxes[i][0][0]): + tmp = _boxes[i] + _boxes[i] = _boxes[i + 1] + _boxes[i + 1] = tmp + return _boxes + + if __name__ == "__main__": args = utility.parse_args() image_file_list = utility.get_image_file_list(args.image_dir) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index a4f9f03daa..ff9586ab76 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -106,7 +106,7 @@ def create_predictor(args, mode): # if args.use_fp16 else AnalysisConfig.Precision.Float32, # max_batch_size=args.batch_size) - config.enable_memory_optim() + # config.enable_memory_optim() # use zero copy config.switch_use_feed_fetch_ops(False) predictor = create_paddle_predictor(config) @@ -136,12 +136,16 @@ if __name__ == '__main__': args.det_model_dir = root_path + "test_models/public_v1/ch_det_mv3_db" predictor, input_tensor, output_tensors = create_predictor(args, mode='det') - print(predictor.get_input_names()) - print(predictor.get_output_names()) - print(predictor.program(), file=open("det_program.txt", 'w')) + print("det input", predictor.get_input_names()) + print("det output", predictor.get_output_names()) + # print(predictor.program(), file=open("det_program.txt", 'w')) + outputs = [] + for output_tensor in output_tensors: + output = output_tensor.copy_to_cpu() + outputs.append(output) args.rec_model_dir = root_path + "test_models/public_v1/ch_rec_mv3_crnn/" rec_predictor, input_tensor, output_tensors = create_predictor( args, mode='rec') - print(rec_predictor.get_input_names()) - print(rec_predictor.get_output_names()) + print("rec input", rec_predictor.get_input_names()) + print("rec output", rec_predictor.get_output_names()) diff --git a/tools/infer_det.py b/tools/infer_det.py new file mode 100755 index 0000000000..d616323d9d --- /dev/null +++ b/tools/infer_det.py @@ -0,0 +1,148 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import sys +import time +import numpy as np +from copy import deepcopy +import json + +# from paddle.fluid.contrib.model_stat import summary + + +def set_paddle_flags(**kwargs): + for key, value in kwargs.items(): + if os.environ.get(key, None) is None: + os.environ[key] = str(value) + + +# NOTE(paddle-dev): All of these flags should be +# set before `import paddle`. Otherwise, it would +# not take any effect. +set_paddle_flags( + FLAGS_eager_delete_tensor_gb=0, # enable GC to save memory +) + +from paddle import fluid +from ppocr.utils.utility import create_module +import program +from ppocr.utils.save_load import init_model +from ppocr.data.reader_main import reader_main + +from ppocr.utils.utility import initial_logger +logger = initial_logger() + + +def draw_det_res(dt_boxes, config, img_name, ino): + if len(dt_boxes) > 0: + img_set_path = config['TestReader']['img_set_dir'] + img_path = img_set_path + img_name + import cv2 + src_im = cv2.imread(img_path) + for box in dt_boxes: + box = box.astype(np.int32).reshape((-1, 1, 2)) + cv2.polylines(src_im, [box], True, color=(255, 255, 0), thickness=2) + save_det_path = os.path.basename(config['Global'][ + 'save_res_path']) + "/det_results/" + if not os.path.exists(save_det_path): + os.makedirs(save_det_path) + save_path = os.path.join(save_det_path, "det_{}.jpg".format(img_name)) + cv2.imwrite(save_path, src_im) + logger.info("The detected Image saved in {}".format(save_path)) + + +def main(): + config = program.load_config(FLAGS.config) + program.merge_config(FLAGS.opt) + print(config) + + # check if set use_gpu=True in paddlepaddle cpu version + use_gpu = config['Global']['use_gpu'] + program.check_gpu(use_gpu) + + place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace() + exe = fluid.Executor(place) + + det_model = create_module(config['Architecture']['function'])(params=config) + + startup_prog = fluid.Program() + eval_prog = fluid.Program() + with fluid.program_guard(eval_prog, startup_prog): + with fluid.unique_name.guard(): + _, eval_outputs = det_model(mode="test") + fetch_name_list = list(eval_outputs.keys()) + eval_fetch_list = [eval_outputs[v].name for v in fetch_name_list] + + eval_prog = eval_prog.clone(for_test=True) + exe.run(startup_prog) + + # load checkpoints + checkpoints = config['Global'].get('checkpoints') + if checkpoints: + path = checkpoints + fluid.load(eval_prog, path, exe) + logger.info("Finish initing model from {}".format(path)) + else: + raise Exception("{} not exists!".format(checkpoints)) + + save_res_path = config['Global']['save_res_path'] + with open(save_res_path, "wb") as fout: + test_reader = reader_main(config=config, mode='test') + tackling_num = 0 + for data in test_reader(): + img_num = len(data) + tackling_num = tackling_num + img_num + logger.info("tackling_num:%d", tackling_num) + img_list = [] + ratio_list = [] + img_name_list = [] + for ino in range(img_num): + img_list.append(data[ino][0]) + ratio_list.append(data[ino][1]) + img_name_list.append(data[ino][2]) + img_list = np.concatenate(img_list, axis=0) + outs = exe.run(eval_prog,\ + feed={'image': img_list},\ + fetch_list=eval_fetch_list) + + global_params = config['Global'] + postprocess_params = deepcopy(config["PostProcess"]) + postprocess_params.update(global_params) + postprocess = create_module(postprocess_params['function'])\ + (params=postprocess_params) + dt_boxes_list = postprocess(outs, ratio_list) + for ino in range(img_num): + dt_boxes = dt_boxes_list[ino] + img_name = img_name_list[ino] + dt_boxes_json = [] + for box in dt_boxes: + tmp_json = {"transcription": ""} + tmp_json['points'] = box.tolist() + dt_boxes_json.append(tmp_json) + otstr = img_name + "\t" + json.dumps(dt_boxes_json) + "\n" + fout.write(otstr.encode()) + draw_det_res(dt_boxes, config, img_name, ino) + + logger.info("success!") + + +if __name__ == '__main__': + parser = program.ArgsParser() + FLAGS = parser.parse_args() + main() From af39902217bf6d02d489d258302cbe89fb53a427 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 11 May 2020 15:33:54 +0800 Subject: [PATCH 2/9] fix tools/infer/utility.py --- tools/infer/utility.py | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index ff9586ab76..e8c76de9ff 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -99,7 +99,8 @@ def create_predictor(args, mode): config.disable_gpu() config.disable_glog_info() - config.switch_ir_optim(args.ir_optim) + # config.switch_ir_optim(args.ir_optim) + # if args.use_tensorrt: # config.enable_tensorrt_engine( # precision_mode=AnalysisConfig.Precision.Half @@ -127,25 +128,3 @@ def draw_text_det_res(dt_boxes, img_path): cv2.polylines(src_im, [box], True, color=(255, 255, 0), thickness=2) img_name_pure = img_path.split("/")[-1] cv2.imwrite("./output/%s" % img_name_pure, src_im) - - -if __name__ == '__main__': - args = parse_args() - args.use_gpu = False - root_path = "/Users/liuweiwei06/Desktop/TEST_CODES/icode/baidu/personal-code/PaddleOCR/" - args.det_model_dir = root_path + "test_models/public_v1/ch_det_mv3_db" - - predictor, input_tensor, output_tensors = create_predictor(args, mode='det') - print("det input", predictor.get_input_names()) - print("det output", predictor.get_output_names()) - # print(predictor.program(), file=open("det_program.txt", 'w')) - outputs = [] - for output_tensor in output_tensors: - output = output_tensor.copy_to_cpu() - outputs.append(output) - - args.rec_model_dir = root_path + "test_models/public_v1/ch_rec_mv3_crnn/" - rec_predictor, input_tensor, output_tensors = create_predictor( - args, mode='rec') - print("rec input", rec_predictor.get_input_names()) - print("rec output", rec_predictor.get_output_names()) From 268ed03b3ec01af8ff2de9f9329659022c13bc5e Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 11 May 2020 19:59:07 +0800 Subject: [PATCH 3/9] update detection doc and infer code --- doc/detection.md | 16 +++++++-- ppocr/data/det/db_process.py | 3 -- ppocr/data/reader_main.py | 6 ---- tools/eval_utils/eval_det_iou.py | 4 +++ tools/eval_utils/eval_det_utils.py | 8 +++++ tools/infer/utility.py | 8 ----- tools/infer_det.py | 54 ++++++++++++++++++++++++++++-- tools/program.py | 16 --------- 8 files changed, 76 insertions(+), 39 deletions(-) diff --git a/doc/detection.md b/doc/detection.md index b8b8a9cc38..6124b74f16 100644 --- a/doc/detection.md +++ b/doc/detection.md @@ -32,8 +32,8 @@ json.dumps编码前的图像标注信息是包含多个字典的list,字典中 ## 3.2 快速启动训练 -首先下载pretrain model,目前支持两种backbone,分别是MobileNetV3、ResNet50,您可以根据需求使用PaddleClas中的模型更换 -backbone。 +首先下载pretrain model,PaddleOCR的检测模型目前支持两种backbone,分别是MobileNetV3、ResNet50_vd, +您可以根据需求使用[PaddleClas](https://github.com/PaddlePaddle/PaddleClas/tree/master/ppcls/modeling/architectures)中的模型更换backbone。 ``` # 下载MobileNetV3的预训练模型 wget -P /PaddleOCR/pretrained_model/ 模型链接 @@ -63,7 +63,17 @@ PaddleOCR计算三个OCR检测相关的指标,分别是:Precision、Recall 运行如下代码,根据配置文件det_db_mv3.yml中save_res_path指定的测试集检测结果文件,计算评估指标。 ``` -python3 tools/eval.py -c configs/det/det_db_mv3.yml -o checkpoints ./output/best_accuracy +python3 tools/eval.py -c configs/det/det_db_mv3.yml -o checkpoints="./output/best_accuracy" ``` ## 3.4 测试检测效果 + +测试单张图像的检测效果 +``` +python3 tools/infer_det.py -c config/det/det_db_mv3.yml -o TestReader.single_img_path="./demo.jpg" +``` + +测试文件夹下所有图像的检测效果 +``` +python3 tools/infer_det.py -c config/det/det_db_mv3.yml -o TestReader.single_img_path="./demo_img/" +``` diff --git a/ppocr/data/det/db_process.py b/ppocr/data/det/db_process.py index 2a6393a166..faca9ac209 100644 --- a/ppocr/data/det/db_process.py +++ b/ppocr/data/det/db_process.py @@ -124,9 +124,6 @@ class DBProcessTest(object): def resize_image_type0(self, im): """ resize image to a size multiple of 32 which is required by the network - :param im: the resized image - :param max_side_len: limit of max image size to avoid out of memory in gpu - :return: the resized image and the resize ratio """ max_side_len = self.max_side_len h, w, _ = im.shape diff --git a/ppocr/data/reader_main.py b/ppocr/data/reader_main.py index 323620bc59..55bd1e0842 100755 --- a/ppocr/data/reader_main.py +++ b/ppocr/data/reader_main.py @@ -73,9 +73,3 @@ def reader_main(config=None, mode=None): return paddle.reader.multiprocess_reader(readers, False) else: return function(mode) - - -def test_reader(image_shape, img_path): - img = cv2.imread(img_path) - norm_img = process_image(img, image_shape) - return norm_img diff --git a/tools/eval_utils/eval_det_iou.py b/tools/eval_utils/eval_det_iou.py index c6dacb3e1b..2f5ff2f10f 100644 --- a/tools/eval_utils/eval_det_iou.py +++ b/tools/eval_utils/eval_det_iou.py @@ -3,6 +3,10 @@ from collections import namedtuple import numpy as np from shapely.geometry import Polygon +""" +reference from : +https://github.com/MhLiao/DB/blob/3c32b808d4412680310d3d28eeb6a2d5bf1566c5/concern/icdar2015_eval/detection/iou.py#L8 +""" class DetectionIoUEvaluator(object): diff --git a/tools/eval_utils/eval_det_utils.py b/tools/eval_utils/eval_det_utils.py index 015cba99fb..f0be714fc0 100644 --- a/tools/eval_utils/eval_det_utils.py +++ b/tools/eval_utils/eval_det_utils.py @@ -98,6 +98,14 @@ def load_label_infor(label_file_path, do_ignore=False): def cal_det_metrics(gt_label_path, save_res_path): + """ + calculate the detection metrics + Args: + gt_label_path(string): The groundtruth detection label file path + save_res_path(string): The saved predicted detection label path + return: + claculated metrics including Hmean、precision and recall + """ evaluator = DetectionIoUEvaluator() gt_label_infor = load_label_infor(gt_label_path, do_ignore=True) dt_label_infor = load_label_infor(save_res_path) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index e8c76de9ff..f1f7a8a0b6 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -99,15 +99,7 @@ def create_predictor(args, mode): config.disable_gpu() config.disable_glog_info() - # config.switch_ir_optim(args.ir_optim) - # if args.use_tensorrt: - # config.enable_tensorrt_engine( - # precision_mode=AnalysisConfig.Precision.Half - # if args.use_fp16 else AnalysisConfig.Precision.Float32, - # max_batch_size=args.batch_size) - - # config.enable_memory_optim() # use zero copy config.switch_use_feed_fetch_ops(False) predictor = create_paddle_predictor(config) diff --git a/tools/infer_det.py b/tools/infer_det.py index d616323d9d..7998cdb6d9 100755 --- a/tools/infer_det.py +++ b/tools/infer_det.py @@ -34,7 +34,7 @@ def set_paddle_flags(**kwargs): # NOTE(paddle-dev): All of these flags should be # set before `import paddle`. Otherwise, it would -# not take any effect. +# not take any effect. set_paddle_flags( FLAGS_eager_delete_tensor_gb=0, # enable GC to save memory ) @@ -44,6 +44,7 @@ from ppocr.utils.utility import create_module import program from ppocr.utils.save_load import init_model from ppocr.data.reader_main import reader_main +import cv2 from ppocr.utils.utility import initial_logger logger = initial_logger() @@ -67,6 +68,50 @@ def draw_det_res(dt_boxes, config, img_name, ino): logger.info("The detected Image saved in {}".format(save_path)) +def simple_reader(img_file, config): + imgs_lists = [] + if img_file is None or not os.path.exists(img_file): + raise Exception("not found any img file in {}".format(img_file)) + + img_end = ['jpg', 'png', 'jpeg', 'JPEG', 'JPG', 'bmp'] + if os.path.isfile(img_file) and img_file.split('.')[-1] in img_end: + imgs_lists.append(img_file) + elif os.path.isdir(img_file): + for single_file in os.listdir(img_file): + if single_file.split('.')[-1] in img_end: + imgs_lists.append(os.path.join(img_file, single_file)) + if len(imgs_lists) == 0: + raise Exception("not found any img file in {}".format(img_file)) + + batch_size = config['Global']['test_batch_size_per_card'] + global_params = config['Global'] + params = deepcopy(config['TestReader']) + params.update(global_params) + reader_function = params['process_function'] + process_function = create_module(reader_function)(params) + + def batch_iter_reader(): + batch_outs = [] + for img_path in imgs_lists: + img = cv2.imread(img_path) + if img.shape[-1] == 1 or len(list(img.shape)) == 2: + img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) + if img is None: + logger.info("load image error:" + img_path) + continue + outs = process_function(img) + outs.append(os.path.basename(img_path)) + print(outs[0].shape, outs[2]) + batch_outs.append(outs) + if len(batch_outs) == batch_size: + yield batch_outs + batch_outs = [] + if len(batch_outs) != 0: + yield batch_outs + + return batch_iter_reader + + def main(): config = program.load_config(FLAGS.config) program.merge_config(FLAGS.opt) @@ -103,7 +148,9 @@ def main(): save_res_path = config['Global']['save_res_path'] with open(save_res_path, "wb") as fout: - test_reader = reader_main(config=config, mode='test') + # test_reader = reader_main(config=config, mode='test') + single_img_path = config['TestReader']['single_img_path'] + test_reader = simple_reader(img_file=single_img_path, config=config) tackling_num = 0 for data in test_reader(): img_num = len(data) @@ -116,6 +163,7 @@ def main(): img_list.append(data[ino][0]) ratio_list.append(data[ino][1]) img_name_list.append(data[ino][2]) + img_list = np.concatenate(img_list, axis=0) outs = exe.run(eval_prog,\ feed={'image': img_list},\ @@ -126,7 +174,7 @@ def main(): postprocess_params.update(global_params) postprocess = create_module(postprocess_params['function'])\ (params=postprocess_params) - dt_boxes_list = postprocess(outs, ratio_list) + dt_boxes_list = postprocess({"maps": outs[0]}, ratio_list) for ino in range(img_num): dt_boxes = dt_boxes_list[ino] img_name = img_name_list[ino] diff --git a/tools/program.py b/tools/program.py index a34e56ca00..f74aacc738 100755 --- a/tools/program.py +++ b/tools/program.py @@ -185,22 +185,6 @@ def build(config, main_prog, startup_prog, mode): def build_export(config, main_prog, startup_prog): """ - Build a program using a model and an optimizer - 1. create feeds - 2. create a dataloader - 3. create a model - 4. create fetchs - 5. create an optimizer - - Args: - config(dict): config - main_prog(): main program - startup_prog(): startup program - is_train(bool): train or valid - - Returns: - dataloader(): a bridge between the model and the data - fetchs(dict): dict of model outputs(included loss and measures) """ with fluid.program_guard(main_prog, startup_prog): with fluid.unique_name.guard(): From f7bea718aa5ac2d4993d09bd36526d008092c1e7 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 11 May 2020 21:18:39 +0800 Subject: [PATCH 4/9] update doc and requirments --- doc/detection.md | 1 - doc/installation.md | 7 ++----- requirments.txt | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/doc/detection.md b/doc/detection.md index 6124b74f16..03052b7652 100644 --- a/doc/detection.md +++ b/doc/detection.md @@ -55,7 +55,6 @@ python3 tools/train.py -c configs/det/det_db_mv3.yml python3 tools/train.py -c configs/det/det_db_mv3.yml -o Optimizer.base_lr=0.0001 ``` - ## 3.3 指标评估 PaddleOCR计算三个OCR检测相关的指标,分别是:Precision、Recall、Hmean。 diff --git a/doc/installation.md b/doc/installation.md index 5eca1dfe6a..b190b3e345 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -1,19 +1,16 @@ ### 2.1 快速安装 -我们提供了PaddleOCR开发环境的docker,您可以pull我们提供的docker运行PaddleOCR的环境。 - +建议使用我们提供的docker运行PaddleOCR,有关docker使用请参考[链接](https://docs.docker.com/get-started/)。 1. 准备docker环境。第一次使用这个镜像,会自动下载该镜像,请耐心等待。 ``` # 切换到工作目录下 cd /home/Projects # 创建一个名字为pdocr的docker容器,并将当前目录映射到容器的/data目录下 -sudo nvidia-docker run --name pdocr -v $PWD:/data --network=host -it paddlepaddle/paddle:1.7.2-gpu-cuda10.0-cudnn7 /bin/bash +sudo nvidia-docker run --name pdocr -v $PWD:/data --network=host -it hub.baidubce.com/paddlepaddle/paddle:latest-gpu-cuda9.0-cudnn7-dev /bin/bash ``` 2. 克隆PaddleOCR repo代码 ``` -apt-get update -apt-get install git git clone https://github.com/PaddlePaddle/PaddleOCR ``` diff --git a/requirments.txt b/requirments.txt index e9bf32a993..94e8478ffa 100644 --- a/requirments.txt +++ b/requirments.txt @@ -1,3 +1,4 @@ shapely imgaug -pyclipper \ No newline at end of file +pyclipper +lmdb \ No newline at end of file From 561c54460c24a0d08ee9d6c5ea4d7daf535b2aff Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 12 May 2020 15:04:33 +0800 Subject: [PATCH 5/9] update readme and doc --- README.md | 126 +++++++++++++++++++++++++++++++++++++++++++- doc/detection.md | 6 +-- doc/installation.md | 14 ++++- 3 files changed, 140 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4d6fb7fb86..60ab666d47 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,124 @@ -# PaddleOCR -OCR algorithms with PaddlePaddle (still under develop) + +# 简介 +PaddleOCR旨在打造一套丰富、领先、且实用的文字检测、识别模型/工具库,助力使用者训练出更好的模型,并应用落地。 + +【这里加上效果图】 + +## 文档教程 +- [快速安装](./doc/installation.md) +- [文本识别模型训练/评估/预测](./doc/detection.md) +- [文本预测模型训练/评估/预测](./doc/recognition.md) + +## 特性: +- 超轻量级模型 + -(检测模型4.1M + 识别模型4.5M = 8.6M) +- 支持竖排文字 + - (单模型同时支持横排和竖排文字识别) +- 支持长文本识别 +- 支持中英文数字组合识别 +- 提供训练代码 +- 支持模型部署 + +## 文本检测算法: + +PaddleOCR提供的文本检测算法列表: +- [EAST](https://arxiv.org/abs/1704.03155) +- [DB](https://arxiv.org/abs/1911.08947) +- [SAST](https://arxiv.org/abs/1908.05498) + +算法效果: +|模型|骨干网络|数据集|Hmean| +|-|-|-|-| +|EAST|ResNet50_vd|ICDAR2015|85.85%| +|EAST|MobileNetV3|ICDAR2015|79.08%| +|DB|ResNet50_vd|ICDAR2015|83.30%| +|DB|MobileNetV3|ICDAR2015|73.00%| + +PaddleOCR文本检测算法的训练与使用请参考[文档](./doc/detection.md)。 + +## 文本识别算法: + +PaddleOCR提供的文本识别算法列表: +- (CRNN)[https://arxiv.org/abs/1507.05717] +- [Rosetta](https://arxiv.org/abs/1910.05085) +- [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) +- [RARE](https://arxiv.org/abs/1603.03915v1) +- [SRN]((https://arxiv.org/abs/2003.12294))(百度自研) + +算法效果: + +以下指标是在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上的评测结果的平均。 + +|模型|骨干网络|ACC| +|-|-|-| +|Rosetta|Resnet34_vd|80.24%| +|Rosetta|MobileNetV3|78.16%| +|CRNN|Resnet34_vd|82.20%| +|CRNN|MobileNetV3|79.37%| +|STAR-Net|Resnet34_vd|83.93%| +|STAR-Net|MobileNetV3|81.56%| +|RARE|Resnet34_vd|84.90%| +|RARE|MobileNetV3|83.32%| + +PaddleOCR文本识别算法的训练与使用请参考[文档](./doc/recognition.md)。 + +## 端到端算法 +PaddleOCR即将开源百度自研端对端OCR模型[End2End-PSL](https://arxiv.org/abs/1909.07808),敬请关注。 +- End2End-PSL (comming soon) + + + +# 参考文献 +``` +EAST: +@inproceedings{zhou2017east, + title={EAST: an efficient and accurate scene text detector}, + author={Zhou, Xinyu and Yao, Cong and Wen, He and Wang, Yuzhi and Zhou, Shuchang and He, Weiran and Liang, Jiajun}, + booktitle={Proceedings of the IEEE conference on Computer Vision and Pattern Recognition}, + pages={5551--5560}, + year={2017} +} + +DB: +@article{liao2019real, + title={Real-time Scene Text Detection with Differentiable Binarization}, + author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang}, + journal={arXiv preprint arXiv:1911.08947}, + year={2019} +} + +DTRB: +@inproceedings{baek2019wrong, + title={What is wrong with scene text recognition model comparisons? dataset and model analysis}, + author={Baek, Jeonghun and Kim, Geewook and Lee, Junyeop and Park, Sungrae and Han, Dongyoon and Yun, Sangdoo and Oh, Seong Joon and Lee, Hwalsuk}, + booktitle={Proceedings of the IEEE International Conference on Computer Vision}, + pages={4715--4723}, + year={2019} +} + +SAST: +@inproceedings{wang2019single, + title={A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning}, + author={Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming}, + booktitle={Proceedings of the 27th ACM International Conference on Multimedia}, + pages={1277--1285}, + year={2019} +} + +SRN: +@article{yu2020towards, + title={Towards Accurate Scene Text Recognition with Semantic Reasoning Networks}, + author={Yu, Deli and Li, Xuan and Zhang, Chengquan and Han, Junyu and Liu, Jingtuo and Ding, Errui}, + journal={arXiv preprint arXiv:2003.12294}, + year={2020} +} + +end2end-psl: +@inproceedings{sun2019chinese, + title={Chinese Street View Text: Large-scale Chinese Text Reading with Partially Supervised Learning}, + author={Sun, Yipeng and Liu, Jiaming and Liu, Wei and Han, Junyu and Ding, Errui and Liu, Jingtuo}, + booktitle={Proceedings of the IEEE International Conference on Computer Vision}, + pages={9086--9095}, + year={2019} +} +``` diff --git a/doc/detection.md b/doc/detection.md index 03052b7652..f4295177bc 100644 --- a/doc/detection.md +++ b/doc/detection.md @@ -35,15 +35,15 @@ json.dumps编码前的图像标注信息是包含多个字典的list,字典中 首先下载pretrain model,PaddleOCR的检测模型目前支持两种backbone,分别是MobileNetV3、ResNet50_vd, 您可以根据需求使用[PaddleClas](https://github.com/PaddlePaddle/PaddleClas/tree/master/ppcls/modeling/architectures)中的模型更换backbone。 ``` +cd PaddleOCR/ # 下载MobileNetV3的预训练模型 -wget -P /PaddleOCR/pretrained_model/ 模型链接 +wget -P /PaddleOCR/pretrain_models/ 模型链接 # 下载ResNet50的预训练模型 -wget -P /PaddleOCR/pretrained_model/ 模型链接 +wget -P /PaddleOCR/pretrain_models/ 模型链接 ``` **启动训练** ``` -cd PaddleOCR/ python3 tools/train.py -c configs/det/det_db_mv3.yml ``` diff --git a/doc/installation.md b/doc/installation.md index b190b3e345..5fca344ea1 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -1,12 +1,17 @@ -### 2.1 快速安装 +## 快速安装 建议使用我们提供的docker运行PaddleOCR,有关docker使用请参考[链接](https://docs.docker.com/get-started/)。 1. 准备docker环境。第一次使用这个镜像,会自动下载该镜像,请耐心等待。 ``` # 切换到工作目录下 cd /home/Projects +# 首次运行需创建一个docker容器,再次运行时不需要运行当前命令 # 创建一个名字为pdocr的docker容器,并将当前目录映射到容器的/data目录下 sudo nvidia-docker run --name pdocr -v $PWD:/data --network=host -it hub.baidubce.com/paddlepaddle/paddle:latest-gpu-cuda9.0-cudnn7-dev /bin/bash + +# ctrl+P+Q可退出docker,重新进入docker使用如下命令 +sudo nvidia-docker container exec -it pdocr /bin/bash + ``` 2. 克隆PaddleOCR repo代码 @@ -20,3 +25,10 @@ cd PaddleOCR pip3 install --upgrade pip pip3 install -r requirements.txt ``` + +## 快速运行 + +``` +python3 tools/infer/predict_eval.py --image_file="./" +``` +【可视化运行结果】 From e91f370362c22e4ba700893a1677a0ed5abdff25 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 12 May 2020 15:35:10 +0800 Subject: [PATCH 6/9] update readme --- README.md | 11 ++++------- doc/detection.md | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 60ab666d47..e08448f640 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ # 简介 PaddleOCR旨在打造一套丰富、领先、且实用的文字检测、识别模型/工具库,助力使用者训练出更好的模型,并应用落地。 -【这里加上效果图】 ## 文档教程 - [快速安装](./doc/installation.md) @@ -11,7 +10,7 @@ PaddleOCR旨在打造一套丰富、领先、且实用的文字检测、识别 ## 特性: - 超轻量级模型 - -(检测模型4.1M + 识别模型4.5M = 8.6M) + - (检测模型4.1M + 识别模型4.5M = 8.6M) - 支持竖排文字 - (单模型同时支持横排和竖排文字识别) - 支持长文本识别 @@ -21,7 +20,7 @@ PaddleOCR旨在打造一套丰富、领先、且实用的文字检测、识别 ## 文本检测算法: -PaddleOCR提供的文本检测算法列表: +PaddleOCR开源的文本检测算法列表: - [EAST](https://arxiv.org/abs/1704.03155) - [DB](https://arxiv.org/abs/1911.08947) - [SAST](https://arxiv.org/abs/1908.05498) @@ -38,16 +37,14 @@ PaddleOCR文本检测算法的训练与使用请参考[文档](./doc/detection.m ## 文本识别算法: -PaddleOCR提供的文本识别算法列表: +PaddleOCR开源的文本识别算法列表: - (CRNN)[https://arxiv.org/abs/1507.05717] - [Rosetta](https://arxiv.org/abs/1910.05085) - [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) - [RARE](https://arxiv.org/abs/1603.03915v1) - [SRN]((https://arxiv.org/abs/2003.12294))(百度自研) -算法效果: - -以下指标是在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上的评测结果的平均。 +算法效果如下表所示,精度指标是在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上的评测结果的平均值。 |模型|骨干网络|ACC| |-|-|-| diff --git a/doc/detection.md b/doc/detection.md index f4295177bc..5d54d78043 100644 --- a/doc/detection.md +++ b/doc/detection.md @@ -2,7 +2,7 @@ 本节以icdar15数据集为例,介绍PaddleOCR中检测模型的使用方式。 -## 3.1 数据准备 +## 数据准备 icdar2015数据集可以从[官网](https://rrc.cvc.uab.es/?ch=4&com=downloads)下载到,首次下载需注册。 将下载到的数据集解压到工作目录下,假设解压在/PaddleOCR/train_data/ 下。另外,PaddleOCR将零散的标注文件整理成单独的标注文件 @@ -30,7 +30,7 @@ json.dumps编码前的图像标注信息是包含多个字典的list,字典中 可以按照上述形式构建标注文件。 -## 3.2 快速启动训练 +## 快速启动训练 首先下载pretrain model,PaddleOCR的检测模型目前支持两种backbone,分别是MobileNetV3、ResNet50_vd, 您可以根据需求使用[PaddleClas](https://github.com/PaddlePaddle/PaddleClas/tree/master/ppcls/modeling/architectures)中的模型更换backbone。 @@ -55,7 +55,7 @@ python3 tools/train.py -c configs/det/det_db_mv3.yml python3 tools/train.py -c configs/det/det_db_mv3.yml -o Optimizer.base_lr=0.0001 ``` -## 3.3 指标评估 +## 指标评估 PaddleOCR计算三个OCR检测相关的指标,分别是:Precision、Recall、Hmean。 @@ -65,7 +65,7 @@ PaddleOCR计算三个OCR检测相关的指标,分别是:Precision、Recall python3 tools/eval.py -c configs/det/det_db_mv3.yml -o checkpoints="./output/best_accuracy" ``` -## 3.4 测试检测效果 +## 测试检测效果 测试单张图像的检测效果 ``` From 5b4675e06dcd01eb44200594452d0464833da43d Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 12 May 2020 19:40:57 +0800 Subject: [PATCH 7/9] fix problems refer comments --- README.md | 56 ++++++++++++++++------------- doc/detection.md | 9 ++--- doc/installation.md | 7 ---- ppocr/data/det/dataset_traversal.py | 14 +++----- tools/infer/utility.py | 25 +++++++------ tools/infer_det.py | 48 +------------------------ 6 files changed, 57 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index e08448f640..2b889c2888 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,49 @@ # 简介 -PaddleOCR旨在打造一套丰富、领先、且实用的文字检测、识别模型/工具库,助力使用者训练出更好的模型,并应用落地。 - - -## 文档教程 -- [快速安装](./doc/installation.md) -- [文本识别模型训练/评估/预测](./doc/detection.md) -- [文本预测模型训练/评估/预测](./doc/recognition.md) +PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力使用者训练出更好的模型,并应用落地。 ## 特性: - 超轻量级模型 - (检测模型4.1M + 识别模型4.5M = 8.6M) -- 支持竖排文字 +- 支持竖排文字识别 - (单模型同时支持横排和竖排文字识别) - 支持长文本识别 - 支持中英文数字组合识别 - 提供训练代码 - 支持模型部署 + +## 文档教程 +- [快速安装](./doc/installation.md) +- [快速开始]() +- [文本识别模型训练/评估/预测](./doc/detection.md) +- [文本预测模型训练/评估/预测](./doc/recognition.md) +- [基于inference model预测](./doc/) + + ## 文本检测算法: PaddleOCR开源的文本检测算法列表: -- [EAST](https://arxiv.org/abs/1704.03155) -- [DB](https://arxiv.org/abs/1911.08947) -- [SAST](https://arxiv.org/abs/1908.05498) +- [x] [EAST](https://arxiv.org/abs/1704.03155) +- [x] [DB](https://arxiv.org/abs/1911.08947) +- [x] [SAST](https://arxiv.org/abs/1908.05498) +- [] + 算法效果: -|模型|骨干网络|数据集|Hmean| -|-|-|-|-| -|EAST|ResNet50_vd|ICDAR2015|85.85%| -|EAST|MobileNetV3|ICDAR2015|79.08%| -|DB|ResNet50_vd|ICDAR2015|83.30%| -|DB|MobileNetV3|ICDAR2015|73.00%| +|模型|骨干网络|Hmean| +|-|-|-| +|EAST^[1]^|ResNet50_vd|85.85%| +|EAST^[1]^|MobileNetV3|79.08%| +|DB^[2]^|ResNet50_vd|83.30%| +|DB^[2]^|MobileNetV3|73.00%| PaddleOCR文本检测算法的训练与使用请参考[文档](./doc/detection.md)。 ## 文本识别算法: PaddleOCR开源的文本识别算法列表: -- (CRNN)[https://arxiv.org/abs/1507.05717] +- [CRNN](https://arxiv.org/abs/1507.05717) - [Rosetta](https://arxiv.org/abs/1910.05085) - [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) - [RARE](https://arxiv.org/abs/1603.03915v1) @@ -59,7 +64,8 @@ PaddleOCR开源的文本识别算法列表: PaddleOCR文本识别算法的训练与使用请参考[文档](./doc/recognition.md)。 -## 端到端算法 +## TODO +**端到端OCR算法** PaddleOCR即将开源百度自研端对端OCR模型[End2End-PSL](https://arxiv.org/abs/1909.07808),敬请关注。 - End2End-PSL (comming soon) @@ -67,7 +73,7 @@ PaddleOCR即将开源百度自研端对端OCR模型[End2End-PSL](https://arxiv.o # 参考文献 ``` -EAST: +1. EAST: @inproceedings{zhou2017east, title={EAST: an efficient and accurate scene text detector}, author={Zhou, Xinyu and Yao, Cong and Wen, He and Wang, Yuzhi and Zhou, Shuchang and He, Weiran and Liang, Jiajun}, @@ -76,7 +82,7 @@ EAST: year={2017} } -DB: +2. DB: @article{liao2019real, title={Real-time Scene Text Detection with Differentiable Binarization}, author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang}, @@ -84,7 +90,7 @@ DB: year={2019} } -DTRB: +3. DTRB: @inproceedings{baek2019wrong, title={What is wrong with scene text recognition model comparisons? dataset and model analysis}, author={Baek, Jeonghun and Kim, Geewook and Lee, Junyeop and Park, Sungrae and Han, Dongyoon and Yun, Sangdoo and Oh, Seong Joon and Lee, Hwalsuk}, @@ -93,7 +99,7 @@ DTRB: year={2019} } -SAST: +4. SAST: @inproceedings{wang2019single, title={A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning}, author={Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming}, @@ -102,7 +108,7 @@ SAST: year={2019} } -SRN: +5. SRN: @article{yu2020towards, title={Towards Accurate Scene Text Recognition with Semantic Reasoning Networks}, author={Yu, Deli and Li, Xuan and Zhang, Chengquan and Han, Junyu and Liu, Jingtuo and Ding, Errui}, @@ -110,7 +116,7 @@ SRN: year={2020} } -end2end-psl: +6. end2end-psl: @inproceedings{sun2019chinese, title={Chinese Street View Text: Large-scale Chinese Text Reading with Partially Supervised Learning}, author={Sun, Yipeng and Liu, Jiaming and Liu, Wei and Han, Junyu and Ding, Errui and Liu, Jingtuo}, diff --git a/doc/detection.md b/doc/detection.md index 5d54d78043..5e55011037 100644 --- a/doc/detection.md +++ b/doc/detection.md @@ -1,6 +1,6 @@ # 文字检测 -本节以icdar15数据集为例,介绍PaddleOCR中检测模型的使用方式。 +本节以icdar15数据集为例,介绍PaddleOCR中检测模型的训练、评估与测试。 ## 数据准备 icdar2015数据集可以从[官网](https://rrc.cvc.uab.es/?ch=4&com=downloads)下载到,首次下载需注册。 @@ -26,8 +26,9 @@ wget -P /PaddleOCR/train_data/ 测试标注文件链接 " 图像文件名 json.dumps编码的图像标注信息" ch4_test_images/img_61.jpg [{"transcription": "MASA", "points": [[310, 104], [416, 141], [418, 216], [312, 179]], ...}] ``` -json.dumps编码前的图像标注信息是包含多个字典的list,字典中的points表示文本框的位置,如果您想在其他数据集上训练PaddleOCR, -可以按照上述形式构建标注文件。 +json.dumps编码前的图像标注信息是包含多个字典的list,字典中的$points$表示文本框的四个点的坐标(x, y),从左上角的点开始顺时针排列。 +$transcription$表示当前文本框的文字,在文本检测任务中并不需要这个信息。 +如果您想在其他数据集上训练PaddleOCR,可以按照上述形式构建标注文件。 ## 快速启动训练 @@ -62,7 +63,7 @@ PaddleOCR计算三个OCR检测相关的指标,分别是:Precision、Recall 运行如下代码,根据配置文件det_db_mv3.yml中save_res_path指定的测试集检测结果文件,计算评估指标。 ``` -python3 tools/eval.py -c configs/det/det_db_mv3.yml -o checkpoints="./output/best_accuracy" +python3 tools/eval.py -c configs/det/det_db_mv3.yml -o Gloabl.checkpoints="./output/best_accuracy" ``` ## 测试检测效果 diff --git a/doc/installation.md b/doc/installation.md index 5fca344ea1..25e0d0d56c 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -25,10 +25,3 @@ cd PaddleOCR pip3 install --upgrade pip pip3 install -r requirements.txt ``` - -## 快速运行 - -``` -python3 tools/infer/predict_eval.py --image_file="./" -``` -【可视化运行结果】 diff --git a/ppocr/data/det/dataset_traversal.py b/ppocr/data/det/dataset_traversal.py index 5ba01ee790..2e68d91d56 100755 --- a/ppocr/data/det/dataset_traversal.py +++ b/ppocr/data/det/dataset_traversal.py @@ -22,6 +22,7 @@ import string from ppocr.utils.utility import initial_logger logger = initial_logger() from ppocr.utils.utility import create_module +from tools.infer.utility import get_image_file_list import time @@ -72,16 +73,8 @@ class EvalTestReader(object): self.params) batch_size = self.params['test_batch_size_per_card'] - flag_test_single_img = False - if mode == "test": - single_img_path = self.params['single_img_path'] - if single_img_path is not None: - flag_test_single_img = True - img_list = [] - if flag_test_single_img: - img_list.append([single_img_path, single_img_path]) - else: + if mode != "test": img_set_dir = self.params['img_set_dir'] img_name_list_path = self.params['label_file_path'] with open(img_name_list_path, "rb") as fin: @@ -90,6 +83,9 @@ class EvalTestReader(object): img_name = line.decode().strip("\n").split("\t")[0] img_path = img_set_dir + "/" + img_name img_list.append([img_path, img_name]) + else: + img_path = self.params['single_img_path'] + img_list = get_image_file_list(img_path) def batch_iter_reader(): batch_outs = [] diff --git a/tools/infer/utility.py b/tools/infer/utility.py index f1f7a8a0b6..01477a5c4c 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -61,16 +61,21 @@ def parse_args(): return parser.parse_args() -def get_image_file_list(image_dir): - image_file_list = [] - if image_dir is None: - return image_file_list - if os.path.isfile(image_dir): - image_file_list = [image_dir] - elif os.path.isdir(image_dir): - for single_file in os.listdir(image_dir): - image_file_list.append(os.path.join(image_dir, single_file)) - return image_file_list +def get_image_file_list(img_file): + imgs_lists = [] + if img_file is None or not os.path.exists(img_file): + raise Exception("not found any img file in {}".format(img_file)) + + img_end = ['jpg', 'png', 'jpeg', 'JPEG', 'JPG', 'bmp'] + if os.path.isfile(img_file) and img_file.split('.')[-1] in img_end: + imgs_lists.append(img_file) + elif os.path.isdir(img_file): + for single_file in os.listdir(img_file): + if single_file.split('.')[-1] in img_end: + imgs_lists.append(os.path.join(img_file, single_file)) + if len(imgs_lists) == 0: + raise Exception("not found any img file in {}".format(img_file)) + return imgs_lists def create_predictor(args, mode): diff --git a/tools/infer_det.py b/tools/infer_det.py index 7998cdb6d9..8d591a654d 100755 --- a/tools/infer_det.py +++ b/tools/infer_det.py @@ -68,50 +68,6 @@ def draw_det_res(dt_boxes, config, img_name, ino): logger.info("The detected Image saved in {}".format(save_path)) -def simple_reader(img_file, config): - imgs_lists = [] - if img_file is None or not os.path.exists(img_file): - raise Exception("not found any img file in {}".format(img_file)) - - img_end = ['jpg', 'png', 'jpeg', 'JPEG', 'JPG', 'bmp'] - if os.path.isfile(img_file) and img_file.split('.')[-1] in img_end: - imgs_lists.append(img_file) - elif os.path.isdir(img_file): - for single_file in os.listdir(img_file): - if single_file.split('.')[-1] in img_end: - imgs_lists.append(os.path.join(img_file, single_file)) - if len(imgs_lists) == 0: - raise Exception("not found any img file in {}".format(img_file)) - - batch_size = config['Global']['test_batch_size_per_card'] - global_params = config['Global'] - params = deepcopy(config['TestReader']) - params.update(global_params) - reader_function = params['process_function'] - process_function = create_module(reader_function)(params) - - def batch_iter_reader(): - batch_outs = [] - for img_path in imgs_lists: - img = cv2.imread(img_path) - if img.shape[-1] == 1 or len(list(img.shape)) == 2: - img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) - if img is None: - logger.info("load image error:" + img_path) - continue - outs = process_function(img) - outs.append(os.path.basename(img_path)) - print(outs[0].shape, outs[2]) - batch_outs.append(outs) - if len(batch_outs) == batch_size: - yield batch_outs - batch_outs = [] - if len(batch_outs) != 0: - yield batch_outs - - return batch_iter_reader - - def main(): config = program.load_config(FLAGS.config) program.merge_config(FLAGS.opt) @@ -148,9 +104,7 @@ def main(): save_res_path = config['Global']['save_res_path'] with open(save_res_path, "wb") as fout: - # test_reader = reader_main(config=config, mode='test') - single_img_path = config['TestReader']['single_img_path'] - test_reader = simple_reader(img_file=single_img_path, config=config) + test_reader = reader_main(config=config, mode='test') tackling_num = 0 for data in test_reader(): img_num = len(data) From b2e2bb98fb8a46898723281e0e69b18d0e7286dc Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 12 May 2020 21:12:52 +0800 Subject: [PATCH 8/9] fix problems responding to inference --- README.md | 54 +++++++++++++++++++-------- configs/det/det_db_mv3.yml | 1 + doc/inference.md | 58 +++++++++++++++++++++++++++++ ppocr/data/det/dataset_traversal.py | 2 +- ppocr/utils/utility.py | 18 +++++++++ tools/export_model.py | 7 +++- tools/infer/utility.py | 17 --------- 7 files changed, 123 insertions(+), 34 deletions(-) create mode 100644 doc/inference.md diff --git a/README.md b/README.md index 2b889c2888..6a9adfa608 100644 --- a/README.md +++ b/README.md @@ -15,39 +15,63 @@ PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力 ## 文档教程 - [快速安装](./doc/installation.md) -- [快速开始]() - [文本识别模型训练/评估/预测](./doc/detection.md) - [文本预测模型训练/评估/预测](./doc/recognition.md) - [基于inference model预测](./doc/) +### **快速开始** + +下载inference模型 +``` +# 创建inference模型保存目录 +mkdir inference && cd inference && mkdir det && mkdir rec +# 下载检测inference模型 +wget -P ./inference/det 检测inference模型链接 +# 下载识别inference模型 +wget -P ./inferencee/rec 识别inference模型链接 +``` + +实现文本检测、识别串联推理,预测$image_dir$指定的单张图像: +``` +export PYTHONPATH=. +python tools/infer/predict_eval.py --image_dir="/Demo.jpg" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" +``` +在执行预测时,通过参数det_model_dir以及rec_model_dir设置存储inference 模型的路径。 + +实现文本检测、识别串联推理,预测$image_dir$指指定文件夹下的所有图像: +``` +python tools/infer/predict_eval.py --image_dir="/test_imgs/" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" +``` + + ## 文本检测算法: PaddleOCR开源的文本检测算法列表: -- [x] [EAST](https://arxiv.org/abs/1704.03155) -- [x] [DB](https://arxiv.org/abs/1911.08947) -- [x] [SAST](https://arxiv.org/abs/1908.05498) -- [] +- [x] [EAST](https://arxiv.org/abs/1704.03155) +- [x] [DB](https://arxiv.org/abs/1911.08947) +- [ ] [SAST](https://arxiv.org/abs/1908.05498) 算法效果: |模型|骨干网络|Hmean| |-|-|-| -|EAST^[1]^|ResNet50_vd|85.85%| -|EAST^[1]^|MobileNetV3|79.08%| -|DB^[2]^|ResNet50_vd|83.30%| -|DB^[2]^|MobileNetV3|73.00%| +|EAST|ResNet50_vd|85.85%| +|EAST|MobileNetV3|79.08%| +|DB|ResNet50_vd|83.30%| +|DB|MobileNetV3|73.00%| PaddleOCR文本检测算法的训练与使用请参考[文档](./doc/detection.md)。 ## 文本识别算法: PaddleOCR开源的文本识别算法列表: -- [CRNN](https://arxiv.org/abs/1507.05717) -- [Rosetta](https://arxiv.org/abs/1910.05085) -- [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) -- [RARE](https://arxiv.org/abs/1603.03915v1) -- [SRN]((https://arxiv.org/abs/2003.12294))(百度自研) +- [x] [CRNN](https://arxiv.org/abs/1507.05717) +- [x] [DTRB](https://arxiv.org/abs/1904.01906) +- [ ] [Rosetta](https://arxiv.org/abs/1910.05085) +- [ ] [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) +- [ ] [RARE](https://arxiv.org/abs/1603.03915v1) +- [ ] [SRN]((https://arxiv.org/abs/2003.12294))(百度自研) 算法效果如下表所示,精度指标是在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上的评测结果的平均值。 @@ -67,7 +91,7 @@ PaddleOCR文本识别算法的训练与使用请参考[文档](./doc/recognition ## TODO **端到端OCR算法** PaddleOCR即将开源百度自研端对端OCR模型[End2End-PSL](https://arxiv.org/abs/1909.07808),敬请关注。 -- End2End-PSL (comming soon) +- [ ] End2End-PSL (comming soon) diff --git a/configs/det/det_db_mv3.yml b/configs/det/det_db_mv3.yml index 197b12044b..45e2ee17b7 100755 --- a/configs/det/det_db_mv3.yml +++ b/configs/det/det_db_mv3.yml @@ -14,6 +14,7 @@ Global: pretrain_weights: ./pretrain_models/MobileNetV3_pretrained/MobileNetV3_large_x0_5_pretrained/ checkpoints: save_res_path: ./output/predicts_db.txt + save_inference_dir: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/doc/inference.md b/doc/inference.md new file mode 100644 index 0000000000..d44a96d7e2 --- /dev/null +++ b/doc/inference.md @@ -0,0 +1,58 @@ + +# 基于inference model的推理 + +inference 模型(fluid.io.save_inference_model保存的模型) +一般是模型训练完成后保存的固化模型,多用于预测部署。 +训练过程中保存的模型是checkpoints模型,保存的是模型的参数,多用于恢复训练等。 +与checkpoints模型相比,inference 模型会额外保存模型的结构信息,在预测部署、加速推理上性能优越。 + +PaddleOCR提供了将checkpoints转换成inference model的实现。 + + +## 文本检测模型推理 + +将文本检测模型训练过程中保存的模型,转换成inference model,可以使用如下命令: + +``` +python tools/export_model.py -c configs/det/det_db_mv3.yml -o Global.checkpoints="./output/best_accuracy" \ + Global.save_inference_dir="./inference/det/" +``` + +推理模型保存在$./inference/det/model$, $./inference/det/params$ + +使用保存的inference model实现在单张图像上的预测: + +``` +python tools/infer/predict_det.py --image_dir="/demo.jpg" --det_model_dir="./inference/det/" +``` + + +## 文本识别模型推理 + +将文本识别模型训练过程中保存的模型,转换成inference model,可以使用如下命令: + +``` +python tools/export_model.py -c configs/rec/rec_chinese_lite_train.yml -o Global.checkpoints="./output/best_accuracy" \ + Global.save_inference_dir="./inference/rec/" +``` + +推理模型保存在$./inference/rec/model$, $./inference/rec/params$ + +使用保存的inference model实现在单张图像上的预测: + +``` +python tools/infer/predict_rec.py --image_dir="/demo.jpg" --rec_model_dir="./inference/rec/" +``` + +## 文本检测、识别串联推理 + +实现文本检测、识别串联推理,预测$image_dir$指定的单张图像: +``` +python tools/infer/predict_eval.py --image_dir="/Demo.jpg" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" +``` + +实现文本检测、识别串联推理,预测$image_dir$指指定文件夹下的所有图像: + +``` +python tools/infer/predict_eval.py --image_dir="/test_imgs/" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" +``` diff --git a/ppocr/data/det/dataset_traversal.py b/ppocr/data/det/dataset_traversal.py index 2e68d91d56..0feedeeb65 100755 --- a/ppocr/data/det/dataset_traversal.py +++ b/ppocr/data/det/dataset_traversal.py @@ -22,7 +22,7 @@ import string from ppocr.utils.utility import initial_logger logger = initial_logger() from ppocr.utils.utility import create_module -from tools.infer.utility import get_image_file_list +from ppocr.utils.utility import get_image_file_list import time diff --git a/ppocr/utils/utility.py b/ppocr/utils/utility.py index 6a81465c1f..c824d4404a 100755 --- a/ppocr/utils/utility.py +++ b/ppocr/utils/utility.py @@ -13,6 +13,7 @@ # limitations under the License. import logging +import os def initial_logger(): @@ -55,6 +56,23 @@ def get_check_reader_params(mode): return check_params +def get_image_file_list(img_file): + imgs_lists = [] + if img_file is None or not os.path.exists(img_file): + raise Exception("not found any img file in {}".format(img_file)) + + img_end = ['jpg', 'png', 'jpeg', 'JPEG', 'JPG', 'bmp'] + if os.path.isfile(img_file) and img_file.split('.')[-1] in img_end: + imgs_lists.append(img_file) + elif os.path.isdir(img_file): + for single_file in os.listdir(img_file): + if single_file.split('.')[-1] in img_end: + imgs_lists.append(os.path.join(img_file, single_file)) + if len(imgs_lists) == 0: + raise Exception("not found any img file in {}".format(img_file)) + return imgs_lists + + from paddle import fluid diff --git a/tools/export_model.py b/tools/export_model.py index 6c924f3fb2..11a2744b39 100644 --- a/tools/export_model.py +++ b/tools/export_model.py @@ -71,14 +71,19 @@ def main(): init_model(config, eval_program, exe) + save_inference_dir = config['Global']['save_inference_dir'] + if not os.path.exists(save_inference_dir): + os.makedirs(save_inference_dir) fluid.io.save_inference_model( - dirname="./output/", + dirname=save_inference_dir, feeded_var_names=feeded_var_names, main_program=eval_program, target_vars=target_vars, executor=exe, model_filename='model', params_filename='params') + print("inference model saved in {}/model and {}/params".format( + save_inference_dir, save_inference_dir)) print("save success, output_name_list:", fetches_var_name) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 01477a5c4c..6d56a99080 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -61,23 +61,6 @@ def parse_args(): return parser.parse_args() -def get_image_file_list(img_file): - imgs_lists = [] - if img_file is None or not os.path.exists(img_file): - raise Exception("not found any img file in {}".format(img_file)) - - img_end = ['jpg', 'png', 'jpeg', 'JPEG', 'JPG', 'bmp'] - if os.path.isfile(img_file) and img_file.split('.')[-1] in img_end: - imgs_lists.append(img_file) - elif os.path.isdir(img_file): - for single_file in os.listdir(img_file): - if single_file.split('.')[-1] in img_end: - imgs_lists.append(os.path.join(img_file, single_file)) - if len(imgs_lists) == 0: - raise Exception("not found any img file in {}".format(img_file)) - return imgs_lists - - def create_predictor(args, mode): if mode == "det": model_dir = args.det_model_dir From ab8fd7d9477840a1d0e3ca63dc97f365776a26a6 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 12 May 2020 21:26:28 +0800 Subject: [PATCH 9/9] remove README for now --- README.md | 153 +------------------------------------------------- doc/README.md | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 151 deletions(-) create mode 100644 doc/README.md diff --git a/README.md b/README.md index 6a9adfa608..4d6fb7fb86 100644 --- a/README.md +++ b/README.md @@ -1,151 +1,2 @@ - -# 简介 -PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力使用者训练出更好的模型,并应用落地。 - -## 特性: -- 超轻量级模型 - - (检测模型4.1M + 识别模型4.5M = 8.6M) -- 支持竖排文字识别 - - (单模型同时支持横排和竖排文字识别) -- 支持长文本识别 -- 支持中英文数字组合识别 -- 提供训练代码 -- 支持模型部署 - - -## 文档教程 -- [快速安装](./doc/installation.md) -- [文本识别模型训练/评估/预测](./doc/detection.md) -- [文本预测模型训练/评估/预测](./doc/recognition.md) -- [基于inference model预测](./doc/) - -### **快速开始** - -下载inference模型 -``` -# 创建inference模型保存目录 -mkdir inference && cd inference && mkdir det && mkdir rec -# 下载检测inference模型 -wget -P ./inference/det 检测inference模型链接 -# 下载识别inference模型 -wget -P ./inferencee/rec 识别inference模型链接 -``` - -实现文本检测、识别串联推理,预测$image_dir$指定的单张图像: -``` -export PYTHONPATH=. -python tools/infer/predict_eval.py --image_dir="/Demo.jpg" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" -``` -在执行预测时,通过参数det_model_dir以及rec_model_dir设置存储inference 模型的路径。 - -实现文本检测、识别串联推理,预测$image_dir$指指定文件夹下的所有图像: -``` -python tools/infer/predict_eval.py --image_dir="/test_imgs/" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" -``` - - - -## 文本检测算法: - -PaddleOCR开源的文本检测算法列表: -- [x] [EAST](https://arxiv.org/abs/1704.03155) -- [x] [DB](https://arxiv.org/abs/1911.08947) -- [ ] [SAST](https://arxiv.org/abs/1908.05498) - - -算法效果: -|模型|骨干网络|Hmean| -|-|-|-| -|EAST|ResNet50_vd|85.85%| -|EAST|MobileNetV3|79.08%| -|DB|ResNet50_vd|83.30%| -|DB|MobileNetV3|73.00%| - -PaddleOCR文本检测算法的训练与使用请参考[文档](./doc/detection.md)。 - -## 文本识别算法: - -PaddleOCR开源的文本识别算法列表: -- [x] [CRNN](https://arxiv.org/abs/1507.05717) -- [x] [DTRB](https://arxiv.org/abs/1904.01906) -- [ ] [Rosetta](https://arxiv.org/abs/1910.05085) -- [ ] [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) -- [ ] [RARE](https://arxiv.org/abs/1603.03915v1) -- [ ] [SRN]((https://arxiv.org/abs/2003.12294))(百度自研) - -算法效果如下表所示,精度指标是在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上的评测结果的平均值。 - -|模型|骨干网络|ACC| -|-|-|-| -|Rosetta|Resnet34_vd|80.24%| -|Rosetta|MobileNetV3|78.16%| -|CRNN|Resnet34_vd|82.20%| -|CRNN|MobileNetV3|79.37%| -|STAR-Net|Resnet34_vd|83.93%| -|STAR-Net|MobileNetV3|81.56%| -|RARE|Resnet34_vd|84.90%| -|RARE|MobileNetV3|83.32%| - -PaddleOCR文本识别算法的训练与使用请参考[文档](./doc/recognition.md)。 - -## TODO -**端到端OCR算法** -PaddleOCR即将开源百度自研端对端OCR模型[End2End-PSL](https://arxiv.org/abs/1909.07808),敬请关注。 -- [ ] End2End-PSL (comming soon) - - - -# 参考文献 -``` -1. EAST: -@inproceedings{zhou2017east, - title={EAST: an efficient and accurate scene text detector}, - author={Zhou, Xinyu and Yao, Cong and Wen, He and Wang, Yuzhi and Zhou, Shuchang and He, Weiran and Liang, Jiajun}, - booktitle={Proceedings of the IEEE conference on Computer Vision and Pattern Recognition}, - pages={5551--5560}, - year={2017} -} - -2. DB: -@article{liao2019real, - title={Real-time Scene Text Detection with Differentiable Binarization}, - author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang}, - journal={arXiv preprint arXiv:1911.08947}, - year={2019} -} - -3. DTRB: -@inproceedings{baek2019wrong, - title={What is wrong with scene text recognition model comparisons? dataset and model analysis}, - author={Baek, Jeonghun and Kim, Geewook and Lee, Junyeop and Park, Sungrae and Han, Dongyoon and Yun, Sangdoo and Oh, Seong Joon and Lee, Hwalsuk}, - booktitle={Proceedings of the IEEE International Conference on Computer Vision}, - pages={4715--4723}, - year={2019} -} - -4. SAST: -@inproceedings{wang2019single, - title={A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning}, - author={Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming}, - booktitle={Proceedings of the 27th ACM International Conference on Multimedia}, - pages={1277--1285}, - year={2019} -} - -5. SRN: -@article{yu2020towards, - title={Towards Accurate Scene Text Recognition with Semantic Reasoning Networks}, - author={Yu, Deli and Li, Xuan and Zhang, Chengquan and Han, Junyu and Liu, Jingtuo and Ding, Errui}, - journal={arXiv preprint arXiv:2003.12294}, - year={2020} -} - -6. end2end-psl: -@inproceedings{sun2019chinese, - title={Chinese Street View Text: Large-scale Chinese Text Reading with Partially Supervised Learning}, - author={Sun, Yipeng and Liu, Jiaming and Liu, Wei and Han, Junyu and Ding, Errui and Liu, Jingtuo}, - booktitle={Proceedings of the IEEE International Conference on Computer Vision}, - pages={9086--9095}, - year={2019} -} -``` +# PaddleOCR +OCR algorithms with PaddlePaddle (still under develop) diff --git a/doc/README.md b/doc/README.md new file mode 100644 index 0000000000..6a9adfa608 --- /dev/null +++ b/doc/README.md @@ -0,0 +1,151 @@ + +# 简介 +PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力使用者训练出更好的模型,并应用落地。 + +## 特性: +- 超轻量级模型 + - (检测模型4.1M + 识别模型4.5M = 8.6M) +- 支持竖排文字识别 + - (单模型同时支持横排和竖排文字识别) +- 支持长文本识别 +- 支持中英文数字组合识别 +- 提供训练代码 +- 支持模型部署 + + +## 文档教程 +- [快速安装](./doc/installation.md) +- [文本识别模型训练/评估/预测](./doc/detection.md) +- [文本预测模型训练/评估/预测](./doc/recognition.md) +- [基于inference model预测](./doc/) + +### **快速开始** + +下载inference模型 +``` +# 创建inference模型保存目录 +mkdir inference && cd inference && mkdir det && mkdir rec +# 下载检测inference模型 +wget -P ./inference/det 检测inference模型链接 +# 下载识别inference模型 +wget -P ./inferencee/rec 识别inference模型链接 +``` + +实现文本检测、识别串联推理,预测$image_dir$指定的单张图像: +``` +export PYTHONPATH=. +python tools/infer/predict_eval.py --image_dir="/Demo.jpg" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" +``` +在执行预测时,通过参数det_model_dir以及rec_model_dir设置存储inference 模型的路径。 + +实现文本检测、识别串联推理,预测$image_dir$指指定文件夹下的所有图像: +``` +python tools/infer/predict_eval.py --image_dir="/test_imgs/" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" +``` + + + +## 文本检测算法: + +PaddleOCR开源的文本检测算法列表: +- [x] [EAST](https://arxiv.org/abs/1704.03155) +- [x] [DB](https://arxiv.org/abs/1911.08947) +- [ ] [SAST](https://arxiv.org/abs/1908.05498) + + +算法效果: +|模型|骨干网络|Hmean| +|-|-|-| +|EAST|ResNet50_vd|85.85%| +|EAST|MobileNetV3|79.08%| +|DB|ResNet50_vd|83.30%| +|DB|MobileNetV3|73.00%| + +PaddleOCR文本检测算法的训练与使用请参考[文档](./doc/detection.md)。 + +## 文本识别算法: + +PaddleOCR开源的文本识别算法列表: +- [x] [CRNN](https://arxiv.org/abs/1507.05717) +- [x] [DTRB](https://arxiv.org/abs/1904.01906) +- [ ] [Rosetta](https://arxiv.org/abs/1910.05085) +- [ ] [STAR-Net](http://www.bmva.org/bmvc/2016/papers/paper043/index.html) +- [ ] [RARE](https://arxiv.org/abs/1603.03915v1) +- [ ] [SRN]((https://arxiv.org/abs/2003.12294))(百度自研) + +算法效果如下表所示,精度指标是在IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE数据集上的评测结果的平均值。 + +|模型|骨干网络|ACC| +|-|-|-| +|Rosetta|Resnet34_vd|80.24%| +|Rosetta|MobileNetV3|78.16%| +|CRNN|Resnet34_vd|82.20%| +|CRNN|MobileNetV3|79.37%| +|STAR-Net|Resnet34_vd|83.93%| +|STAR-Net|MobileNetV3|81.56%| +|RARE|Resnet34_vd|84.90%| +|RARE|MobileNetV3|83.32%| + +PaddleOCR文本识别算法的训练与使用请参考[文档](./doc/recognition.md)。 + +## TODO +**端到端OCR算法** +PaddleOCR即将开源百度自研端对端OCR模型[End2End-PSL](https://arxiv.org/abs/1909.07808),敬请关注。 +- [ ] End2End-PSL (comming soon) + + + +# 参考文献 +``` +1. EAST: +@inproceedings{zhou2017east, + title={EAST: an efficient and accurate scene text detector}, + author={Zhou, Xinyu and Yao, Cong and Wen, He and Wang, Yuzhi and Zhou, Shuchang and He, Weiran and Liang, Jiajun}, + booktitle={Proceedings of the IEEE conference on Computer Vision and Pattern Recognition}, + pages={5551--5560}, + year={2017} +} + +2. DB: +@article{liao2019real, + title={Real-time Scene Text Detection with Differentiable Binarization}, + author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang}, + journal={arXiv preprint arXiv:1911.08947}, + year={2019} +} + +3. DTRB: +@inproceedings{baek2019wrong, + title={What is wrong with scene text recognition model comparisons? dataset and model analysis}, + author={Baek, Jeonghun and Kim, Geewook and Lee, Junyeop and Park, Sungrae and Han, Dongyoon and Yun, Sangdoo and Oh, Seong Joon and Lee, Hwalsuk}, + booktitle={Proceedings of the IEEE International Conference on Computer Vision}, + pages={4715--4723}, + year={2019} +} + +4. SAST: +@inproceedings{wang2019single, + title={A Single-Shot Arbitrarily-Shaped Text Detector based on Context Attended Multi-Task Learning}, + author={Wang, Pengfei and Zhang, Chengquan and Qi, Fei and Huang, Zuming and En, Mengyi and Han, Junyu and Liu, Jingtuo and Ding, Errui and Shi, Guangming}, + booktitle={Proceedings of the 27th ACM International Conference on Multimedia}, + pages={1277--1285}, + year={2019} +} + +5. SRN: +@article{yu2020towards, + title={Towards Accurate Scene Text Recognition with Semantic Reasoning Networks}, + author={Yu, Deli and Li, Xuan and Zhang, Chengquan and Han, Junyu and Liu, Jingtuo and Ding, Errui}, + journal={arXiv preprint arXiv:2003.12294}, + year={2020} +} + +6. end2end-psl: +@inproceedings{sun2019chinese, + title={Chinese Street View Text: Large-scale Chinese Text Reading with Partially Supervised Learning}, + author={Sun, Yipeng and Liu, Jiaming and Liu, Wei and Han, Junyu and Ding, Errui and Liu, Jingtuo}, + booktitle={Proceedings of the IEEE International Conference on Computer Vision}, + pages={9086--9095}, + year={2019} +} +```