From ac6b5109b76f029c42df17d90b93869ef5780d73 Mon Sep 17 00:00:00 2001 From: breezedeus Date: Wed, 10 Apr 2024 22:05:59 +0800 Subject: [PATCH 1/6] download model files from HF by default --- cnocr/consts.py | 2 +- requirements.in | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cnocr/consts.py b/cnocr/consts.py index d386269..3e35c64 100644 --- a/cnocr/consts.py +++ b/cnocr/consts.py @@ -33,7 +33,7 @@ # 模型版本只对应到第二层,第三层的改动表示模型兼容。 # 如: __version__ = '2.2.*',对应的 MODEL_VERSION 都是 '2.2' MODEL_VERSION = '.'.join(__version__.split('.', maxsplit=2)[:2]) -DOWNLOAD_SOURCE = os.environ.get('CNOCR_DOWNLOAD_SOURCE', 'CN') +DOWNLOAD_SOURCE = os.environ.get('CNOCR_DOWNLOAD_SOURCE', 'HF') IMG_STANDARD_HEIGHT = 32 CN_VOCAB_FP = Path(__file__).parent.absolute() / 'label_cn.txt' diff --git a/requirements.in b/requirements.in index 3d6dc79..7b79bba 100644 --- a/requirements.in +++ b/requirements.in @@ -15,4 +15,4 @@ torchmetrics>=0.9.0 pillow>=5.3.0 onnx onnxruntime -cnstd>=1.2.3.5 +cnstd>=1.2.3.6 diff --git a/requirements.txt b/requirements.txt index 459b336..0356353 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,7 +33,7 @@ click==8.1.7 # -r requirements.in # cnstd # wandb -cnstd==1.2.3.5 +cnstd==1.2.3.6 # via -r requirements.in coloredlogs==15.0.1 # via onnxruntime From 2e65426e93dbdd523b75dc88fd33e71cdf04f8ff Mon Sep 17 00:00:00 2001 From: breezedeus Date: Wed, 10 Apr 2024 22:09:13 +0800 Subject: [PATCH 2/6] allow more arguments --- cnocr/cli.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cnocr/cli.py b/cnocr/cli.py index 7c89ef5..e49851f 100644 --- a/cnocr/cli.py +++ b/cnocr/cli.py @@ -224,6 +224,9 @@ def visualize_example(example, fp_prefix): default='onnx', help='检测模型类型。默认值为 `onnx`', ) +@click.option( + '--det-resized-shape', type=int, default=768, help='检测模型输入图像尺寸。默认值为 768', +) @click.option( '-p', '--pretrained-model-fp', @@ -251,6 +254,9 @@ def visualize_example(example, fp_prefix): @click.option( "--draw-font-path", default='./docs/fonts/simfang.ttf', help="画出检测与识别效果图时使用的字体文件", ) +@click.option( + "--show-details", is_flag=True, default=False, help="是否打印识别结果详情。默认值为 `False`", +) @click.option( "--verbose", is_flag=True, default=False, help="是否打印详细日志信息。默认值为 `False`", ) @@ -260,12 +266,14 @@ def predict( rec_vocab_fp, det_model_name, det_model_backend, + det_resized_shape, pretrained_model_fp, context, img_file_or_dir, single_line, draw_results_dir, draw_font_path, + show_details, verbose, ): """模型预测""", @@ -298,18 +306,24 @@ def predict( # det_more_configs={'rotated_bbox': False}, ) ocr_func = ocr.ocr_for_single_line if single_line else ocr.ocr + ocr_kwargs = {} + if not single_line: + ocr_kwargs['resized_shape'] = det_resized_shape for fp in fp_list: start_time = time.time() logger.info('\n' + '=' * 10 + fp + '=' * 10) res = ocr_func( fp, - # resized_shape=2280, + **ocr_kwargs, # box_score_thresh=0.14, # min_box_size=20, ) logger.info('time cost: %f' % (time.time() - start_time)) - logger.info(res) + if show_details: + logger.info(res) + else: + logger.info('\n'.join([line_res['text'] for line_res in res])) if single_line: res = [res] @@ -329,10 +343,6 @@ def predict( fp, res, out_draw_fp=out_draw_fp, font_path=draw_font_path ) - # for line_res in res: - # preds, prob = line_res['text'], line_res['score'] - # logger.info('\npred: %s, with score %f' % (''.join(preds), prob)) - @cli.command('evaluate') @click.option( From a4f4f0e4770b6147bd73910b5c63311c0cba7d93 Mon Sep 17 00:00:00 2001 From: breezedeus Date: Wed, 10 Apr 2024 22:09:24 +0800 Subject: [PATCH 3/6] update doc --- docs/RELEASE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 32ab288..363354f 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -1,5 +1,11 @@ # Release Notes +### Update 2024.04.10:发布 V2.3.0.2 + +主要变更: + +* CN OSS 不可用了,默认下载模型地址由 `CN` 改为 `HF`。 + ### Update 2023.12.26:发布 V2.3.0.1 主要变更: From 3958df99fef801a63b89da5a3d79894143fc4dcf Mon Sep 17 00:00:00 2001 From: breezedeus Date: Wed, 10 Apr 2024 22:09:50 +0800 Subject: [PATCH 4/6] bump version --- cnocr/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cnocr/__version__.py b/cnocr/__version__.py index 872d6ee..272589c 100644 --- a/cnocr/__version__.py +++ b/cnocr/__version__.py @@ -17,4 +17,4 @@ # specific language governing permissions and limitations # under the License. -__version__ = '2.3.0.1' +__version__ = '2.3.0.2' From b571cca481c0569fe0a97bef2aec237294ccffe9 Mon Sep 17 00:00:00 2001 From: breezedeus Date: Wed, 10 Apr 2024 22:15:58 +0800 Subject: [PATCH 5/6] update docs --- README.md | 2 +- docs/models.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96620a7..2661779 100644 --- a/README.md +++ b/README.md @@ -391,7 +391,7 @@ print(ocr_out) 相比于 CnOCR V2.2.* 版本,**V2.3** 中的大部分模型都经过了重新训练和精调,精度比旧版模型更高。同时,加入了两个参数量更多的模型系列: - * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。 + * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,后续会免费开源。 * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档: **V2.3** 中的模型按使用场景可以分为以下几大类: diff --git a/docs/models.md b/docs/models.md index cfebdc4..ef87d64 100644 --- a/docs/models.md +++ b/docs/models.md @@ -45,7 +45,7 @@ CnOCR **V2.3** 重新训练了所有的模型,模型较 V2.2.* 精度更高。 同时,加入了两个参数量更多的模型系列: - * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。 + * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,后续会免费开源。 * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档: CnOCR 自己训练的模型都支持**常见简体中文、英文和数字**的识别,大家也可以基于这些模型在自己的领域数据上继续精调模型。模型列表如下: From 8cc229f6ddeee37da50a5f2ebd07837b6763ebe4 Mon Sep 17 00:00:00 2001 From: breezedeus Date: Wed, 10 Apr 2024 22:17:36 +0800 Subject: [PATCH 6/6] update docs --- README_en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_en.md b/README_en.md index 7133d39..fb838cf 100644 --- a/README_en.md +++ b/README_en.md @@ -314,7 +314,7 @@ Refer to [CnSTD](https://github.com/breezedeus/CnSTD?tab=readme-ov-file#%E5%B7%B Compared to the CnOCR V2.2.* versions, most models in **V2.3** have been retrained and fine-tuned, offering higher accuracy than the older versions. Additionally, two series of models with larger parameter volumes have been added: - * `*-densenet_lite_246-gru_base`: Currently available for **Knowledge Planet** [**CnOCR/CnSTD Private Group**](https://t.zsxq.com/FEYZRJQ) members, it will be open-sourced for free in February 2024. + * `*-densenet_lite_246-gru_base`: Currently available for **Knowledge Planet** [**CnOCR/CnSTD Private Group**](https://t.zsxq.com/FEYZRJQ) members, it will be open-sourced afterward. * `*-densenet_lite_666-gru_large`: **Pro models**, available for use after purchase. The purchase link: [https://ocr.lemonsqueezy.com](https://ocr.lemonsqueezy.com). Models in **V2.3** are categorized into the following types based on usage scenarios: