|
|
@@ -9,18 +9,47 @@ comments: true
|
|
|
|
|
|
## 二、支持模型列表
|
|
|
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>Avg-BLEU</th>
|
|
|
+<th>GPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小 (M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+<td>UniMERNet</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/UniMERNet_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/UniMERNet_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>0.8613</td>
|
|
|
+<td>2266.96</td>
|
|
|
+<td>1.4 G</td>
|
|
|
+<td>UniMERNet是由上海AI Lab研发的一款公式识别模型。该模型采用Donut Swin作为编码器,MBartDecoder作为解码器,并通过在包含简单公式、复杂公式、扫描捕捉公式和手写公式在内的一百万数据集上进行训练,大幅提升了模型对真实场景公式的识别准确率</td>
|
|
|
+<tr>
|
|
|
+<td>PP-FormulaNet-S</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-FormulaNet-S_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-FormulaNet-S_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>0.8712</td>
|
|
|
+<td>202.25</td>
|
|
|
+<td>167.9 M</td>
|
|
|
+<td rowspan="2">PP-FormulaNet 是由百度飞桨视觉团队开发的一款先进的公式识别模型。PP-FormulaNet-S 版本采用了 PP-HGNetV2-B4 作为其骨干网络,通过并行掩码和模型蒸馏等技术,大幅提升了模型的推理速度,同时保持了较高的识别精度,特别适合对推理速度有较高要求的应用场景。而 PP-FormulaNet-L 版本则基于 Vary_VIT_B 作为骨干网络,并在大规模公式数据集上进行了深入训练,在复杂公式的识别方面,相较于PP-FormulaNet-S表现出显著的提升。 </td>
|
|
|
+
|
|
|
+</tr>
|
|
|
+<td>PP-FormulaNet-L</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-FormulaNet-L_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-FormulaNet-L_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>0.9213</td>
|
|
|
+<td>1976.52</td>
|
|
|
+<td>535.2 M</td>
|
|
|
+</table>
|
|
|
+
|
|
|
+<b>注:以上精度指标测量自 PaddleX 内部自建公式识别测试集。所有模型 GPU 推理耗时基于 Tesla V100 GPUs 机器,精度类型为 FP32</b>
|
|
|
+
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
|
|
<th>模型</th><th>模型下载链接</th>
|
|
|
-<th>normed edit distance</th>
|
|
|
<th>BLEU score</th>
|
|
|
+<th>normed edit distance</th>
|
|
|
<th>ExpRate (%)</th>
|
|
|
<th>模型存储大小 (M)</th>
|
|
|
<th>介绍</th>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
-<td>LaTeX_OCR_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/LaTeX_OCR_rec_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/LaTeX_OCR_rec_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>LaTeX_OCR_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/LaTeX_OCR_rec_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/LaTeX_OCR_rec_pretrained.pdparams">训练模型</a></td>
|
|
|
<td>0.8821</td>
|
|
|
<td>0.0823</td>
|
|
|
<td>40.01</td>
|
|
|
@@ -31,6 +60,8 @@ comments: true
|
|
|
|
|
|
<b>注:以上精度指标测量自 LaTeX-OCR公式识别测试集。</b>
|
|
|
|
|
|
+
|
|
|
+
|
|
|
## 三、快速集成
|
|
|
> ❗ 在快速集成前,请先安装 PaddleX 的 wheel 包,详细请参考 [PaddleX本地安装教程](../../../installation/installation.md)
|
|
|
|
|
|
@@ -38,12 +69,184 @@ wheel 包的安装后,几行代码即可完成公式识别模块的推理,
|
|
|
|
|
|
```bash
|
|
|
from paddlex import create_model
|
|
|
-model = create_model("LaTeX_OCR_rec")
|
|
|
-output = model.predict("general_formula_rec_001.png", batch_size=1)
|
|
|
+model = create_model(model_name="PP-FormulaNet-S")
|
|
|
+output = model.predict(input="general_formula_rec_001.png", batch_size=1)
|
|
|
for res in output:
|
|
|
- res.print(json_format=False)
|
|
|
- res.save_to_json("./output/res.json")
|
|
|
+ res.print()
|
|
|
+ res.save_to_img(save_path="./output/")
|
|
|
+ res.save_to_json(save_path="./output/res.json")
|
|
|
```
|
|
|
+运行后,得到的结果为:
|
|
|
+```bash
|
|
|
+{'res': {'input_path': 'general_formula_rec_001.png', 'rec_formula': '\\zeta_{0}(\\nu)=-{\\frac{\\nu\\varrho^{-2\\nu}}{\\pi}}\\int_{\\mu}^{\\infty}d\\omega\\int_{C_{+}}d z{\\frac{2z^{2}}{(z^{2}+\\omega^{2})^{\\nu+1}}}\\ \\ {vec\\Psi}(\\omega;z)e^{i\\epsilon z}\\quad,'}}
|
|
|
+```
|
|
|
+运行结果参数含义如下:
|
|
|
+- `input_path`:表示输入待预测公式图像的路径
|
|
|
+- `rec_formula`:表示公式图像的预测LaTeX源码
|
|
|
+
|
|
|
+
|
|
|
+可视化图片如下:
|
|
|
+
|
|
|
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/refs/heads/main/images/modules/formula_recog/general_formula_rec_001_res.png">
|
|
|
+
|
|
|
+<b> 注:如果您需要对公式识别产线进行可视化,需要运行如下命令来对LaTeX渲染环境进行安装:</b>
|
|
|
+```bash
|
|
|
+sudo apt-get update
|
|
|
+sudo apt-get install texlive texlive-latex-base texlive-latex-extra -y
|
|
|
+```
|
|
|
+
|
|
|
+相关方法、参数等说明如下:
|
|
|
+
|
|
|
+* `create_model`实例化公式识别模型(此处以`PP-FormulaNet-S`为例),具体说明如下:
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>可选项</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td><code>model_name</code></td>
|
|
|
+<td>模型名称</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>所有PaddleX支持的模型名称</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>model_dir</code></td>
|
|
|
+<td>模型存储路径</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>无</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+* 其中,`model_name` 必须指定,指定 `model_name` 后,默认使用 PaddleX 内置的模型参数,在此基础上,指定 `model_dir` 时,使用用户自定义的模型。
|
|
|
+
|
|
|
+* 调用文本识别模型的 `predict()` 方法进行推理预测,`predict()` 方法参数有 `input` 和 `batch_size`,具体说明如下:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>可选项</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td><code>input</code></td>
|
|
|
+<td>待预测数据,支持多种输入类型</td>
|
|
|
+<td><code>Python Var</code>/<code>str</code>/<code>dict</code>/<code>list</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>Python变量</b>,如<code>numpy.ndarray</code>表示的图像数据</li>
|
|
|
+ <li><b>文件路径</b>,如图像文件的本地路径:<code>/root/data/img.jpg</code></li>
|
|
|
+ <li><b>URL链接</b>,如图像文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_formula_rec_001.png">示例</a></li>
|
|
|
+ <li><b>本地目录</b>,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code></li>
|
|
|
+ <li><b>字典</b>,字典的<code>key</code>需与具体任务对应,如图像分类任务对应<code>\"img\"</code>,字典的<code>val</code>支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code></li>
|
|
|
+ <li><b>列表</b>,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code>,<code>[{\"img\": \"/root/data1\"}, {\"img\": \"/root/data2/img.jpg\"}]</code></li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>batch_size</code></td>
|
|
|
+<td>批大小</td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>任意整数</td>
|
|
|
+<td>1</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+* 对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`json`文件的操作:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>方法</th>
|
|
|
+<th>方法说明</th>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td rowspan = "3"><code>print()</code></td>
|
|
|
+<td rowspan = "3">打印结果到终端</td>
|
|
|
+<td><code>format_json</code></td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>是否对输出内容进行使用 <code>JSON</code> 缩进格式化</td>
|
|
|
+<td><code>True</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>indent</code></td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
|
|
|
+<td>4</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>ensure_ascii</code></td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
|
|
|
+<td><code>False</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td rowspan = "3"><code>save_to_json()</code></td>
|
|
|
+<td rowspan = "3">将结果保存为json格式的文件</td>
|
|
|
+<td><code>save_path</code></td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>indent</code></td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
|
|
|
+<td>4</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>ensure_ascii</code></td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
|
|
|
+<td><code>False</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>save_to_img()</code></td>
|
|
|
+<td>将结果保存为图像格式的文件</td>
|
|
|
+<td><code>save_path</code></td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>属性</th>
|
|
|
+<th>属性说明</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td rowspan = "1"><code>json</code></td>
|
|
|
+<td rowspan = "1">获取预测的<code>json</code>格式的结果</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td rowspan = "1"><code>img</code></td>
|
|
|
+<td rowspan = "1">获取格式为<code>dict</code>的可视化图像</td>
|
|
|
+</tr>
|
|
|
+
|
|
|
+</table>
|
|
|
+
|
|
|
+
|
|
|
关于更多 PaddleX 的单模型推理的 API 的使用方法,可以参考的使用方法,可以参考[PaddleX单模型Python脚本使用说明](../../instructions/model_python_API.md)。
|
|
|
|
|
|
## 四、二次开发
|
|
|
@@ -63,7 +266,7 @@ tar -xf ./dataset/ocr_rec_latexocr_dataset_example.tar -C ./dataset/
|
|
|
一行命令即可完成数据校验:
|
|
|
|
|
|
```bash
|
|
|
-python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=check_dataset \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example
|
|
|
```
|
|
|
@@ -108,7 +311,7 @@ python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
},
|
|
|
"dataset_path": "./dataset/ocr_rec_latexocr_dataset_example",
|
|
|
"show_type": "image",
|
|
|
- "dataset_type": "LaTeXOCRDataset"
|
|
|
+ "dataset_type": "FormulaRecDataset"
|
|
|
}
|
|
|
</code></pre>
|
|
|
<p>上述校验结果中,check_pass 为 True 表示数据集格式符合要求,其他部分指标的说明如下:</p>
|
|
|
@@ -127,34 +330,34 @@ python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
<details><summary>👉 <b>格式转换/数据集划分详情(点击展开)</b></summary>
|
|
|
|
|
|
<p><b>(1)数据集格式转换</b></p>
|
|
|
-<p>公式识别支持 <code>MSTextRecDataset</code>格式的数据集转换为 <code>LaTeXOCRDataset</code>格式(<code>PKL</code>格式),数据集格式转换的参数可以通过修改配置文件中 <code>CheckDataset</code> 下的字段进行设置,配置文件中部分参数的示例说明如下:</p>
|
|
|
+<p>公式识别支持 <code>FormulaRecDataset</code>格式的数据集转换为 <code>LaTeXOCRDataset</code>格式(<code>PKL</code>格式),数据集格式转换的参数可以通过修改配置文件中 <code>CheckDataset</code> 下的字段进行设置,配置文件中部分参数的示例说明如下:</p>
|
|
|
<ul>
|
|
|
<li><code>CheckDataset</code>:</li>
|
|
|
<li><code>convert</code>:</li>
|
|
|
-<li><code>enable</code>: 是否进行数据集格式转换,公式识别支持 <code>MSTextRecDataset</code>格式的数据集转换为 <code>LaTeXOCRDataset</code>格式,默认为 <code>True</code>;</li>
|
|
|
-<li><code>src_dataset_type</code>: 如果进行数据集格式转换,则需设置源数据集格式,默认为 <code>MSTextRecDataset</code>;</li>
|
|
|
+<li><code>enable</code>: 是否进行数据集格式转换,公式识别支持 <code>FormulaRecDataset</code>格式的数据集转换为 <code>LaTeXOCRDataset</code>格式,默认为 <code>True</code>;</li>
|
|
|
+<li><code>src_dataset_type</code>: 如果进行数据集格式转换,则需设置源数据集格式,默认为 <code>FormulaRecDataset</code>;</li>
|
|
|
</ul>
|
|
|
-<p>例如,您想将 <code>MSTextRecDataset</code>格式的数据集转换为 <code>LaTeXOCRDataset</code>格式,则需将配置文件修改为:</p>
|
|
|
+<p>例如,您想将 <code>FormulaRecDataset</code>格式的数据集转换为 <code>LaTeXOCRDataset</code>格式,则需将配置文件修改为:</p>
|
|
|
<pre><code class="language-bash">......
|
|
|
CheckDataset:
|
|
|
......
|
|
|
convert:
|
|
|
enable: True
|
|
|
- src_dataset_type: MSTextRecDataset
|
|
|
+ src_dataset_type: FormulaRecDataset
|
|
|
......
|
|
|
</code></pre>
|
|
|
<p>随后执行命令:</p>
|
|
|
-<pre><code class="language-bash">python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+<pre><code class="language-bash">python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=check_dataset \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example
|
|
|
</code></pre>
|
|
|
<p>数据转换执行之后,原有标注文件会被在原路径下重命名为 <code>xxx.bak</code>。</p>
|
|
|
<p>以上参数同样支持通过追加命令行参数的方式进行设置:</p>
|
|
|
-<pre><code class="language-bash">python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+<pre><code class="language-bash">python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=check_dataset \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example \
|
|
|
-o CheckDataset.convert.enable=True \
|
|
|
- -o CheckDataset.convert.src_dataset_type=MSTextRecDataset
|
|
|
+ -o CheckDataset.convert.src_dataset_type=FormulaRecDataset
|
|
|
</code></pre>
|
|
|
<p><b>(2)数据集划分</b></p>
|
|
|
<p>数据集划分的参数可以通过修改配置文件中 <code>CheckDataset</code> 下的字段进行设置,配置文件中部分参数的示例说明如下:</p>
|
|
|
@@ -175,13 +378,13 @@ CheckDataset:
|
|
|
......
|
|
|
</code></pre>
|
|
|
<p>随后执行命令:</p>
|
|
|
-<pre><code class="language-bash">python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+<pre><code class="language-bash">python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=check_dataset \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example
|
|
|
</code></pre>
|
|
|
<p>数据划分执行之后,原有标注文件会被在原路径下重命名为 <code>xxx.bak</code>。</p>
|
|
|
<p>以上参数同样支持通过追加命令行参数的方式进行设置:</p>
|
|
|
-<pre><code class="language-bash">python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+<pre><code class="language-bash">python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=check_dataset \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example \
|
|
|
-o CheckDataset.split.enable=True \
|
|
|
@@ -190,19 +393,26 @@ CheckDataset:
|
|
|
</code></pre></details>
|
|
|
|
|
|
### 4.2 模型训练
|
|
|
-一条命令即可完成模型的训练,以此处公式识别模型 LaTeX_OCR_rec 的训练为例:
|
|
|
+一条命令即可完成模型的训练,以此处公式识别模型 PP-FormulaNet-S 的训练为例:
|
|
|
|
|
|
```bash
|
|
|
-python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+FLAGS_json_format_model=1 python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=train \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example
|
|
|
```
|
|
|
需要如下几步:
|
|
|
|
|
|
-* 指定模型的`.yaml` 配置文件路径(此处为`LaTeX_OCR_rec.yaml`,训练其他模型时,需要的指定相应的配置文件,模型和配置的文件的对应关系,可以查阅[PaddleX模型列表(CPU/GPU)](../../../support_list/models_list.md))
|
|
|
+* 指定模型的`.yaml` 配置文件路径(此处为`PP-FormulaNet-S.yaml`,训练其他模型时,需要的指定相应的配置文件,模型和配置的文件的对应关系,可以查阅[PaddleX模型列表(CPU/GPU)](../../../support_list/models_list.md))
|
|
|
* 指定模式为模型训练:`-o Global.mode=train`
|
|
|
* 指定训练数据集路径:`-o Global.dataset_dir`
|
|
|
其他相关参数均可通过修改`.yaml`配置文件中的`Global`和`Train`下的字段来进行设置,也可以通过在命令行中追加参数来进行调整。如指定前 2 卡 gpu 训练:`-o Global.device=gpu:0,1`;设置训练轮次数为 10:`-o Train.epochs_iters=10`。更多可修改的参数及其详细解释,可以查阅模型对应任务模块的配置文件说明[PaddleX通用模型配置文件参数说明](../../instructions/config_parameters_common.md)。
|
|
|
+* 除 LaTeX_OCR_rec外, 公式识别模型只支持导出json格式的模型,因此训练时需要设置参数`FLAGS_json_format_model=1`。
|
|
|
+* 对于 PP-FormulaNet-S、PP-FormulaNet-L、UniMERNet 模型,在训练还需要安装额外的Linux包,具体命令如下:
|
|
|
+```bash
|
|
|
+sudo apt-get update
|
|
|
+sudo apt-get install libmagickwand-dev
|
|
|
+python -m pip install Wand
|
|
|
+```
|
|
|
|
|
|
<details><summary>👉 <b>更多说明(点击展开)</b></summary>
|
|
|
|
|
|
@@ -224,13 +434,13 @@ python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
在完成模型训练后,可以对指定的模型权重文件在验证集上进行评估,验证模型精度。使用 PaddleX 进行模型评估,一条命令即可完成模型的评估:
|
|
|
|
|
|
```bash
|
|
|
-python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=evaluate \
|
|
|
-o Global.dataset_dir=./dataset/ocr_rec_latexocr_dataset_example
|
|
|
```
|
|
|
与模型训练类似,需要如下几步:
|
|
|
|
|
|
-* 指定模型的`.yaml` 配置文件路径(此处为`LaTeX_OCR_rec.yaml`)
|
|
|
+* 指定模型的`.yaml` 配置文件路径(此处为`PP-FormulaNet-S.yaml`)
|
|
|
* 指定模式为模型评估:`-o Global.mode=evaluate`
|
|
|
* 指定验证数据集路径:`-o Global.dataset_dir`
|
|
|
其他相关参数均可通过修改`.yaml`配置文件中的`Global`和`Evaluate`下的字段来进行设置,详细请参考[PaddleX通用模型配置文件参数说明](../../instructions/config_parameters_common.md)。
|
|
|
@@ -247,14 +457,14 @@ python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
|
|
|
* 通过命令行的方式进行推理预测,只需如下一条命令。运行以下代码前,请您下载[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_formula_rec_001.png)到本地。
|
|
|
```bash
|
|
|
-python main.py -c paddlex/configs/formula_recognition/LaTeX_OCR_rec.yaml \
|
|
|
+python main.py -c paddlex/configs/modules/formula_recognition/PP-FormulaNet-S.yaml \
|
|
|
-o Global.mode=predict \
|
|
|
-o Predict.model_dir="./output/best_accuracy/inference" \
|
|
|
-o Predict.input="general_formula_rec_001.png"
|
|
|
```
|
|
|
与模型训练和评估类似,需要如下几步:
|
|
|
|
|
|
-* 指定模型的`.yaml` 配置文件路径(此处为`LaTeX_OCR_rec.yaml`)
|
|
|
+* 指定模型的`.yaml` 配置文件路径(此处为`PP-FormulaNet-S.yaml`)
|
|
|
* 指定模式为模型推理预测:`-o Global.mode=predict`
|
|
|
* 指定模型权重路径:`-o Predict.model_dir="./output/best_accuracy/inference"`
|
|
|
* 指定输入数据路径:`-o Predict.input="..."`
|