From 1747b6f979003a1efedb7b8acc7d35861cc74f8f Mon Sep 17 00:00:00 2001 From: SWHL Date: Sun, 19 May 2024 09:29:25 +0800 Subject: [PATCH] chore(install_usage): Optimize installation document description --- .../docs/install_usage/rapidocr/install.md | 11 +- content/docs/install_usage/rapidocr/usage.md | 109 +++++++++--------- 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/content/docs/install_usage/rapidocr/install.md b/content/docs/install_usage/rapidocr/install.md index 578cb2cb..52fdfb1e 100644 --- a/content/docs/install_usage/rapidocr/install.md +++ b/content/docs/install_usage/rapidocr/install.md @@ -27,8 +27,8 @@ description: "" #### 版本情况 各个库的最新版本: -| 库 | pypi最新版本 | -| :--------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------: | +| 库 | pypi最新版本 | +| :-----: | :-----: | | `rapidocr_onnxruntime` | PyPI | | `rapidocr_openvino` | PyPI | | `rapidocr_paddle` | PyPI | @@ -42,12 +42,15 @@ pypi上各个版本的对应关系: #### 安装 -顺利的话,一行命令即可。包大小约为14M左右,包含了三个模型。因为mobile版模型较小,因此将相关模型都已打到Whl包,可直接pip安装使用。 +顺利的话,一行命令即可。包大小约为14M左右,包含了三个模型(文本检测、文本行方向分类和文本识别)。因为其中mobile版模型较小,因此将相关模型都已打到whl包,可直接pip安装使用。 -{{< alert text="请使用Python3.6及以上版本。
`rapidocr`系列库目前仅在CPU上支持较好,GPU上推理很慢,这一点可参考[link](https://rapidai.github.io/RapidOCRDocs/docs/inference_engine/onnxruntime/onnxruntime-gpu/)。因此不建议用onnxruntime-gpu版推理。推荐用[`rapidocr_paddle`](../rapidocr_paddle.md)" />}} +{{< alert text="请使用Python3.6及以上版本。
`rapidocr_onnxruntime`系列库目前仅在CPU上支持较好,GPU上推理很慢,这一点可参考[link](https://rapidai.github.io/RapidOCRDocs/docs/inference_engine/onnxruntime/onnxruntime-gpu/)。因此不建议用`onnxruntime-gpu`版推理。
GPU端推理推荐用[`rapidocr_paddle`](../rapidocr_paddle.md)" />}} ```bash {linenos=table} pip install rapidocr-onnxruntime + +# 基于OpenVINO +pip install rapidocr_openvino ``` 安装速度慢的话,可以指定国内的安装源,如使用清华源: diff --git a/content/docs/install_usage/rapidocr/usage.md b/content/docs/install_usage/rapidocr/usage.md index 145bf3eb..c17c16ba 100644 --- a/content/docs/install_usage/rapidocr/usage.md +++ b/content/docs/install_usage/rapidocr/usage.md @@ -10,62 +10,65 @@ description: "" --- ### 初始化 -类[RapidOCR](https://github.com/RapidAI/RapidOCR/blob/a981e21743f03d9bbfbe596974123fecfe8a7d62/python/rapidocr_onnxruntime/main.py#L19)是主类,其初始化函数如下: +[RapidOCR](https://github.com/RapidAI/RapidOCR/blob/a981e21743f03d9bbfbe596974123fecfe8a7d62/python/rapidocr_onnxruntime/main.py#L19)类是主类,其初始化函数如下: ```python {linenos=table} class RapidOCR: def __init__(self, config_path: Optional[str] = None, **kwargs): pass ``` 支持两种自定义传参数的方案,下面分别详细说明: -- 以`config.yaml`方式 - 1. 找到`rapidocr_onnxruntime`安装目录下的`config.yaml`文件,可以通过`pip show rapidocr_onnxruntime`找到其安装路径。 - 2. 将`config.yaml`拷贝出来,放到当前运行目录下 - 3. 按需自定义参数修改即可,具体参数解释,参见[config.yaml](../../blog/02_config_parameter.md) - ```python {linenos=table} - engine = RapidOCR(config_path="your.yaml") - ``` -- (推荐) 以具体参数传入,参数基本和[config.yaml](../../blog/02_config_parameter.md)中对应,只是个别名称有所区别。 - - {{< alert context="info" text="以下参数均有默认值,可以不传入任何参数,直接初始化使用即可。
`intra_op_num_threads`和`inter_op_num_threads`仅是rapidocr_onnxruntime版本下的,其他推理引擎,请参见各自源码" />}} - ```python {linenos=table} - class RapidOCR: - def __init__( - self, - text_score: float = 0.5, - print_verbose: bool = False, - min_height: int = 30, - width_height_ratio: float = 8, - det_use_cuda: bool = False, - det_use_dml: bool = False, - det_model_path: Optional[str] = None, - det_limit_side_len: float = 736, - det_limit_type: str = "min", - det_thresh: float = 0.3, - det_box_thresh: float = 0.5, - det_unclip_ratio: float = 1.6, - det_donot_use_dilation: bool = False, - det_score_mode: str = "fast", - cls_use_cuda: bool = False, - cls_use_dml: bool = False, - cls_model_path: Optional[str] = None, - cls_image_shape: List[int] = [3, 48, 192], - cls_label_list: List[str] = ["0", "180"], - cls_batch_num: int = 6, - cls_thresh: float = 0.9, - rec_use_cuda: bool = False, - rec_use_dml bool = False, - rec_model_path: Optional[str] = None, - rec_img_shape: List[int] = [3, 48, 320], - rec_batch_num: int = 6, - intra_op_num_threads: int = -1, - inter_op_num_threads: int = -1, - ): - pass - - engine = RapidOCR() - - res, elapse = engine(img, use_det=True, use_cls=True, use_rec=True) - ``` +#### 以`config.yaml`方式 +1. 找到`rapidocr_onnxruntime`安装目录下的`config.yaml`文件,可以通过`pip show rapidocr_onnxruntime`找到其安装路径。 +2. 将`config.yaml`拷贝出来,放到当前运行目录下 +3. 按需自定义参数修改即可,具体参数解释,参见[config.yaml](../../blog/02_config_parameter.md) + ```python {linenos=table} + engine = RapidOCR(config_path="your.yaml") + ``` +#### (推荐) 以具体参数传入 + +参数基本和[config.yaml](../../blog/02_config_parameter.md)中对应,只是个别名称有所区别。 + + {{< alert context="info" text="以下参数均有默认值,可以不传入任何参数,直接初始化使用即可。
`intra_op_num_threads`和`inter_op_num_threads`仅是`rapidocr_onnxruntime`版本下的,其他推理引擎,请参见各自源码" />}} + +```python {linenos=table} +class RapidOCR: + def __init__( + self, + text_score: float = 0.5, + print_verbose: bool = False, + min_height: int = 30, + width_height_ratio: float = 8, + det_use_cuda: bool = False, + det_use_dml: bool = False, + det_model_path: Optional[str] = None, + det_limit_side_len: float = 736, + det_limit_type: str = "min", + det_thresh: float = 0.3, + det_box_thresh: float = 0.5, + det_unclip_ratio: float = 1.6, + det_donot_use_dilation: bool = False, + det_score_mode: str = "fast", + cls_use_cuda: bool = False, + cls_use_dml: bool = False, + cls_model_path: Optional[str] = None, + cls_image_shape: List[int] = [3, 48, 192], + cls_label_list: List[str] = ["0", "180"], + cls_batch_num: int = 6, + cls_thresh: float = 0.9, + rec_use_cuda: bool = False, + rec_use_dml bool = False, + rec_model_path: Optional[str] = None, + rec_img_shape: List[int] = [3, 48, 320], + rec_batch_num: int = 6, + intra_op_num_threads: int = -1, + inter_op_num_threads: int = -1, + ): + pass + +engine = RapidOCR() + +res, elapse = engine(img, use_det=True, use_cls=True, use_rec=True) +``` ### 输入 {{< alert context="info" text="确保输入模型前的图像通道顺序为BGR。当前`LoadImage`类内部已经对此做了处理,参考下面写法即可正常使用。" />}} @@ -149,7 +152,9 @@ print(elapse) {{< /tabs >}} ### 输出 -类RapidOCR在调用时,有三个参数`use_det | use_cls | use_rec`,可以控制是否使用检测、方向分类和识别这三部分。不同的参数,决定了不同的输出,如果图像中未检测到有效文字信息,则返回`Tupule[None, None]`。详细搭配如下: +RapidOCR在调用时,有三个参数`use_det | use_cls | use_rec`,可以控制是否使用检测、方向分类和识别这三部分,不同的参数决定了不同的输出。 + +如果图像中未检测到有效文字信息,则返回`Tuple[None, None]`。详细搭配如下: {{< tabs tabTotal="6">}} {{% tab tabName="只有检测" %}} @@ -290,7 +295,7 @@ print(elapse) {{% /tab %}} {{< /tabs >}} -### 可视化查看结果 +### 可视化查看 为了便于查看检测和识别结果,该库中封装了[`VisRes`](https://github.com/RapidAI/RapidOCR/blob/a981e21743f03d9bbfbe596974123fecfe8a7d62/python/rapidocr_onnxruntime/utils.py#L351)类,可借助该类快速可视化查看结果。 {{< alert context="info" text="可视化识别结果时,需要提供字体文件。下载链接:[link](https://github.com/RapidAI/RapidOCR/releases/download/v1.1.0/FZYTK.TTF)" />}}