Skip to content

Commit

Permalink
Merge pull request #323 from breezedeus/dev
Browse files Browse the repository at this point in the history
download model files from HF by default
  • Loading branch information
breezedeus authored Apr 10, 2024
2 parents d02425d + 8cc229f commit 41d9af3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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** 中的模型按使用场景可以分为以下几大类:
Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cnocr/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# specific language governing permissions and limitations
# under the License.

__version__ = '2.3.0.1'
__version__ = '2.3.0.2'
22 changes: 16 additions & 6 deletions cnocr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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`",
)
Expand All @@ -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,
):
"""模型预测""",
Expand Down Expand Up @@ -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]

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cnocr/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
@@ -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

主要变更:
Expand Down
2 changes: 1 addition & 1 deletion docs/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 自己训练的模型都支持**常见简体中文、英文和数字**的识别,大家也可以基于这些模型在自己的领域数据上继续精调模型。模型列表如下:
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ torchmetrics>=0.9.0
pillow>=5.3.0
onnx
onnxruntime
cnstd>=1.2.3.5
cnstd>=1.2.3.6
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41d9af3

Please sign in to comment.