diff --git a/README.md b/README.md index 07479a9bf50e6fffdd400f46b567423e872a8f59..5eb9ed8fb43f132511e82bd56fa9831eb407c9a8 100644 --- a/README.md +++ b/README.md @@ -171,19 +171,16 @@ PaddleOCR文本识别算法的训练和使用请参考文档教程中[文本识 ![](doc/imgs_results/chinese_db_crnn_server/8.jpg) ## FAQ -1. **预测报错:got an unexpected keyword argument 'gradient_clip'** -安装的paddle版本不对,目前本项目仅支持paddle1.7,近期会适配到1.8。 - -2. **转换attention识别模型时报错:KeyError: 'predict'** +1. **转换attention识别模型时报错:KeyError: 'predict'** 问题已解,请更新到最新代码。 -3. **关于推理速度** +2. **关于推理速度** 图片中的文字较多时,预测时间会增,可以使用--rec_batch_num设置更小预测batch num,默认值为30,可以改为10或其他数值。 -4. **服务部署与移动端部署** +3. **服务部署与移动端部署** 预计6月中下旬会先后发布基于Serving的服务部署方案和基于Paddle Lite的移动端部署方案,欢迎持续关注。 -5. **自研算法发布时间** +4. **自研算法发布时间** 自研算法SAST、SRN、End2End-PSL都将在6-7月陆续发布,敬请期待。 [more](./doc/doc_ch/FAQ.md) diff --git a/README_en.md b/README_en.md index c3420302a02961b2c6e23eaa140f54902d1b3ef1..c64b65c4cb28d5010d340e5bc1f7605c437a2300 100644 --- a/README_en.md +++ b/README_en.md @@ -171,23 +171,19 @@ Please refer to the document for training guide and use of PaddleOCR text recogn ![](doc/imgs_results/chinese_db_crnn_server/8.jpg) ## FAQ -1. Prediction error:got an unexpected keyword argument 'gradient_clip' - - The installed paddle version is not correct. At present, this project only supports paddle1.7, which will be adapted to 1.8 in the near future. - -2. Error when using attention-based recognition model: KeyError: 'predict' +1. Error when using attention-based recognition model: KeyError: 'predict' The inference of recognition model based on attention loss is still being debugged. For Chinese text recognition, it is recommended to choose the recognition model based on CTC loss first. In practice, it is also found that the recognition model based on attention loss is not as effective as the one based on CTC loss. -3. About inference speed +2. About inference speed When there are a lot of texts in the picture, the prediction time will increase. You can use `--rec_batch_num` to set a smaller prediction batch size. The default value is 30, which can be changed to 10 or other values. -4. Service deployment and mobile deployment +3. Service deployment and mobile deployment It is expected that the service deployment based on Serving and the mobile deployment based on Paddle Lite will be released successively in mid-to-late June. Stay tuned for more updates. -5. Release time of self-developed algorithm +4. Release time of self-developed algorithm Baidu Self-developed algorithms such as SAST, SRN and end2end PSL will be released in June or July. Please be patient. diff --git a/configs/rec/rec_icdar15_train.yml b/configs/rec/rec_icdar15_train.yml index 934a94109cb304c5dd5e8db281f1fbf00d928e39..8aa96160f4182f94b79cf0340ade7698d4bf7e55 100755 --- a/configs/rec/rec_icdar15_train.yml +++ b/configs/rec/rec_icdar15_train.yml @@ -41,3 +41,7 @@ Optimizer: base_lr: 0.0005 beta1: 0.9 beta2: 0.999 + decay: + function: cosine_decay + step_each_epoch: 20 + total_epoch: 1000 diff --git a/doc/doc_ch/FAQ.md b/doc/doc_ch/FAQ.md index 2bae57abdd78cdbd5498f3edb15083b63d891ed4..eddc1d770962c7c0b331e2ebc70e58e51ed24e41 100644 --- a/doc/doc_ch/FAQ.md +++ b/doc/doc_ch/FAQ.md @@ -46,3 +46,7 @@ PaddleOCR已完成Windows和Mac系统适配,运行时注意两点:1、在[ 报错信息:Input(X) dims[3] and Input(Grid) dims[2] should be equal, but received X dimension[3](320) != Grid dimension[2](100) 原因:TPS模块暂时无法支持变长的输入,请设置 --rec_image_shape='3,32,100' --rec_char_type='en' 固定输入shape + +11. **自定义字典训练的模型,识别结果出现字典里没出现的字** + +预测时没有设置采用的自定义字典路径。设置方法是在预测时,通过增加输入参数rec_char_dict_path来设置。 diff --git a/doc/doc_ch/config.md b/doc/doc_ch/config.md index 644232b4573228f3c05d990359506f67a7de8df0..ae16263e5272641f95d5e8842da08ac65d7a0b12 100644 --- a/doc/doc_ch/config.md +++ b/doc/doc_ch/config.md @@ -46,3 +46,18 @@ | img_set_dir | 数据集路径 | ./train_data | \ | | label_file_path | 数据标签路径 | ./train_data/rec_gt_train.txt| \ | | infer_img | 预测图像文件夹路径 | ./infer_img | \| + +## 配置文件 Optimizer 系列参数介绍 + +以 `rec_icdar15_train.yml` 为例 + +| 字段 | 用途 | 默认值 | 备注 | +| :---------------------: | :---------------------: | :--------------: | :--------------------: | +| function | 选择优化器 | pocr.optimizer,AdamDecay | 目前只支持Adam方式 | +| base_lr | 设置初始学习率 | 0.0005 | \ | +| beta1 | 设置一阶矩估计的指数衰减率 | 0.9 | \ | +| beta2 | 设置二阶矩估计的指数衰减率 | 0.999 | \ | +| decay | 是否使用decay | \ | \ | +| function(decay) | 设置decay方式 | cosine_decay | 目前只支持cosin_decay | +| step_each_epoch | 每个epoch包含多少次迭代 | 20 | 计算方式:total_image_num / (batch_size_per_card * card_size) | +| total_epoch | 总共迭代多少个epoch | 1000 | 与Global.epoch_num 一致 | diff --git a/doc/doc_en/config_en.md b/doc/doc_en/config_en.md index e995a629f6c1552ed5325e2ebe6dc0037e54398a..41c2bb86c57146b57f451484b1d9397c4d83fbff 100644 --- a/doc/doc_en/config_en.md +++ b/doc/doc_en/config_en.md @@ -46,3 +46,18 @@ Take `rec_chinese_reader.yml` as an example: | img_set_dir | Image folder path | ./train_data | \ | | label_file_path | Groundtruth file path | ./train_data/rec_gt_train.txt| \ | | infer_img | Result folder path | ./infer_img | \| + +## Introduction to Optimizer parameters of Configuration file + +Take `rec_icdar15_train.yml` as an example: + +| Parameter | Use | Default | None | +| :---------------------: | :---------------------: | :--------------: | :--------------------: | +| function | Select Optimizer function | pocr.optimizer,AdamDecay | Only support Adam | +| base_lr | Set the base lr | 0.0005 | \ | +| beta1 | Set the exponential decay rate for the 1st moment estimates | 0.9 | \ | +| beta2 | Set the exponential decay rate for the 2nd moment estimates | 0.999 | \ | +| decay | Whether to use decay | \ | \ | +| function(decay) | Set the decay function | cosine_decay | Only support cosine_decay | +| step_each_epoch | The number of steps in an epoch. | 20 | Calculation :total_image_num / (batch_size_per_card * card_size) | +| total_epoch | The number of epochs | 1000 | Consistent with Global.epoch_num | diff --git a/ppocr/modeling/heads/det_db_head.py b/ppocr/modeling/heads/det_db_head.py index c89a1255f2bb864bb4567ec92a51a7d35faad9b0..56998044d8923a2bbda094e01b5a4eb2f5496bb3 100644 --- a/ppocr/modeling/heads/det_db_head.py +++ b/ppocr/modeling/heads/det_db_head.py @@ -115,7 +115,6 @@ class DBHead(object): initializer = fluid.initializer.Uniform(-stdv, stdv) bias_attr = fluid.ParamAttr( regularizer=regularizer, - gradient_clip=gradient_clip, initializer=initializer, name=name + "_b_attr") return bias_attr diff --git a/ppocr/optimizer.py b/ppocr/optimizer.py index a6ad1eb702b8e1c999249d0a3dd98de0efc06baf..c50b14c8d926d6e5b3798f5248ab1f80cbb57011 100755 --- a/ppocr/optimizer.py +++ b/ppocr/optimizer.py @@ -15,6 +15,9 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function import paddle.fluid as fluid +from ppocr.utils.utility import initial_logger + +logger = initial_logger() def AdamDecay(params, parameter_list=None): @@ -28,6 +31,18 @@ def AdamDecay(params, parameter_list=None): base_lr = params['base_lr'] beta1 = params['beta1'] beta2 = params['beta2'] + if 'decay' in params: + params = params['decay'] + decay_mode = params['function'] + step_each_epoch = params['step_each_epoch'] + total_epoch = params['total_epoch'] + if decay_mode == "cosine_decay": + base_lr = fluid.layers.cosine_decay( + learning_rate=base_lr, + step_each_epoch=step_each_epoch, + epochs=total_epoch) + else: + logger.info("Only support Cosine decay currently") optimizer = fluid.optimizer.Adam( learning_rate=base_lr, beta1=beta1,