PP-DocLayout and PP-LCNet for RK3588: document layout and page orientation

Compiled models for the Rockchip RK3588 / RK3588S NPU, ready to load: no ONNX export, no conversion. They are .rnpu files, fp16 builds made by the NPU compiler of RCDL and run by RCDL's own NPU runtime, which drives the board's rknpu kernel driver directly. librknnrt and rknn-toolkit2 are not involved, and there is no .rknn build of these models. RCDL is a C++17 / Python library that drives the NPU, RGA and VPU on these boards as one zero-copy pipeline. Its NPU stack is described in docs/OPEN_NPU.md.

Upstream: three document models from PaddleOCR. PP-DocLayout_plus-L (RT-DETR-L at 800, 20 layout classes) is the published ONNX cut before its post-processing. PP-DocLayout-S (PicoDet-S at 480, 23 classes) and PP-LCNet_x1_0_doc_ori (page orientation) are paddle2onnx exports (opset 16) of the published inference models.

Redistributable, including commercially. All three are Apache-2.0, and the class lists come from the models' own published configuration. See Licence.

Files

file what it is input size
pp_doclayout_plus_l_800_fp16.rnpu layout, 20 classes, 300 queries, no NMS 800×800 RGB, stretched 94.3 MB
pp_doclayout_s_480_fp16.rnpu fast layout, 23 classes, NMS on the CPU 480×480 RGB, stretched 2.8 MB
pp_lcnet_doc_ori_224_fp16.rnpu page orientation: turned 0, 90, 180 or 270° 224×224 RGB, centre crop 3.4 MB
pp_doclayout_plus_l_labels.txt PP-DocLayout_plus-L's 20 class names, in index order 186 B
pp_doclayout_s_labels.txt PP-DocLayout-S's 23 class names, in index order 218 B

All three take uint8 RGB with the normalisation inside the build. The classes are paragraph and document titles, text, abstracts, tables, images, charts, formulas and their numbers, headers, footers, footnotes, seals, references and more. The two label sets differ: PP-DocLayout-S adds table_title, chart_title, header_image and footer_image, and has no reference_content.

Measured on RK3588S and RK3588

model infer, RK3588S whole task, RK3588S infer, RK3588 whole task, RK3588 result on doc_page.jpg
PP-DocLayout_plus-L 415.18 ms 417.4 ms 408.68 ms 411.2 ms 4 paragraph_title, 4 text, 1 header, 1 image, 1 figure_title, 1 formula, 1 formula_number, 1 number
PP-DocLayout-S 19.56 ms 21.6 ms 19.27 ms 21.4 ms 4 text, 3 paragraph_title, 1 header, 1 image
PP-LCNet doc_ori 2.76 ms 3.2 ms 2.81 ms 3.2 ms the page turned four ways: 4 of 4 read right, top score 0.93 each

From RCDL's benchmark: RCDL 0.3.0 conda packages on RCDL's own NPU runtime, NPU driver 0.9.8, one NPU core, the performance CPU governor with the process pinned to the A76 cores, median of nine runs after at least a second of warm-up. The RK3588S ran BSP kernel 6.1.118, the RK3588 6.1.141. Infer is the model run as the runtime times it: its NPU segments and the CPU operators between them. Whole task adds the resize into the input tensor and the decode. doc_page.jpg is a test page with titles, text, an image and a formula.

Against the float models: the layout models on 21 pages (20 rendered pages and a Chinese product label, RCDL's OCR sample), the orientation model on 21 pages each turned four ways.

build agreement with float median score difference one / three cores, RK3588
PP-DocLayout_plus-L F1 1.000 0.0001 409 / 249 ms
PP-DocLayout-S F1 0.992 0.0016 19 / 9 ms
PP-LCNet doc_ori top-1 the same on all 84 turned pages; probabilities within 0.0005 — 3.2 / 1.3 ms

Layout detections are matched at score 0.5 by class and IoU 0.5; both sides of PP-DocLayout-S ran the same threshold and NMS. The layout times on one and three cores were taken with the boards' default governors.

Use it

On the board (linux-aarch64), with RCDL 0.3.1 or newer:

conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
conda activate rcdl
curl -LO https://huggingface.co/ruisv/rcdl-pp-doc/resolve/main/pp_doclayout_plus_l_800_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-pp-doc/resolve/main/pp_doclayout_s_480_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-pp-doc/resolve/main/pp_lcnet_doc_ori_224_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-pp-doc/resolve/main/pp_doclayout_plus_l_labels.txt
curl -LO https://huggingface.co/ruisv/rcdl-pp-doc/resolve/main/pp_doclayout_s_labels.txt
import cv2, numpy as np, rcdl

page = cv2.imread("doc_page.jpg")

# Layout, PP-DocLayout_plus-L: 20 classes, 300 queries, no NMS
names_l = open("pp_doclayout_plus_l_labels.txt").read().split()
layout = rcdl.Engine("pp_doclayout_plus_l_800_fp16.rnpu").detr_detector(coco_category_ids=False)
for d in rcdl.detect_detr(layout, page):
    print("plus-L", names_l[d.class_id], f"{d.score:.2f}", f"{d.x1:.0f} {d.y1:.0f} {d.x2:.0f} {d.y2:.0f}")

# Fast layout, PP-DocLayout-S: 23 classes, per-class NMS on the CPU
names_s = open("pp_doclayout_s_labels.txt").read().split()
fast = rcdl.Engine("pp_doclayout_s_480_fp16.rnpu").box_score_detector()
for d in rcdl.detect_boxes(fast, page):
    print("S     ", names_s[d.class_id], f"{d.score:.2f}", f"{d.x1:.0f} {d.y1:.0f} {d.x2:.0f} {d.y2:.0f}")

# Orientation: class k = the page is turned k x 90 degrees clockwise
ori = rcdl.Engine("pp_lcnet_doc_ori_224_fp16.rnpu").classifier(apply_softmax=False, top_k=4)
turns = (None, cv2.ROTATE_90_CLOCKWISE, cv2.ROTATE_180, cv2.ROTATE_90_COUNTERCLOCKWISE)
for k, r in enumerate(turns):
    img = page if r is None else np.ascontiguousarray(cv2.rotate(page, r))
    best = rcdl.classify(ori, img)[0]
    print(f"turned {90 * k:3d} -> reads {90 * best.class_id:3d}, score {best.score:.2f}")

Boxes come back in page pixels.

What to know before deploying

Pick the layout model by budget. PP-DocLayout_plus-L takes about 409 ms on one core and 249 ms on three; PP-DocLayout-S about 19 ms and 9 ms. Both match their float models closely, and on the test page the larger one also found the figure title, the formula and its number.

Index each model's output with its own label file. The two class lists are in different orders and not the same length.

Both layout models stretch the page onto their square input, as they are trained, and scale the boxes back. PP-DocLayout_plus-L answers 300 queries with no NMS; create it with coco_category_ids=False, since its classes are not COCO's. PP-DocLayout-S keeps boxes at or above conf_thresh (0.5) and runs a greedy NMS per class on the CPU at iou_thresh 0.6, the export's own value.

Orientation: class k means the page is turned k × 90° clockwise. To read it, turn it back k × 90° counter-clockwise: k = 1 is cv2.ROTATE_90_COUNTERCLOCKWISE, k = 2 cv2.ROTATE_180, k = 3 cv2.ROTATE_90_CLOCKWISE. The softmax is in the graph, so pass apply_softmax=False. The classifier's default 0.875 centre crop is the crop the build expects. A single text line turned 180° is a different job: that is PP-OCR's text direction classifier, in ruisv/rcdl-ppocr.

Time it under the performance governor. The boards default to schedutil, which clocks the CPU down while it waits for the NPU. Under it, benchmark rows that alternate NPU and CPU work measured up to about four times the numbers above, and different ones on every run. The results did not change.

.rnpu is RCDL's own format, and its NPU stack is marked experimental. The .rnpu format may still change. These files run on RK3588 / RK3588S through the rknpu driver of the vendor BSP kernels (rknpu 0.9.8, verified on kernels 6.1.118 and 6.1.141). RK3576 and RK356x are not verified, and the mainline kernel's rocket driver is not supported.

Licence

Apache-2.0, as PaddleOCR releases PP-DocLayout_plus-L, PP-DocLayout-S and PP-LCNet_x1_0_doc_ori. The two label files are the class lists from each model's published inference.yml, under the same terms.

RCDL itself is Apache-2.0 and is unrelated to these terms. It is a general-purpose runtime that loads any .rnpu or .rknn. The licence above applies to these weights and these compiled files only.

How each build was made, and the input contract for every model, are documented in RCDL's docs/MODELS.md. The licence status of every model RCDL has verified is in model_zoo/.

中文说明

PaddleOCR 的三个文档模型为 瑞芯微 RK3588 / RK3588S NPU 编译好的版本,下载后 直接加载,不用导出 ONNX,也不用转换:两个版面分析模型和一个页面方向分类模型。文件是 .rnpu 格式的 fp16 构建:由 RCDL 自研的 NPU 编译器生成,由 RCDL 自己的 NPU 运行时直接驱动板子上的 rknpu 内核驱动来运行,不需要 librknnrt,也不需要 rknn-toolkit2;这些模型没有 .rknn 版本。自研 NPU 栈的介绍见 docs/OPEN_NPU.zh.md。

上游是 PaddleOCR: PP-DocLayout_plus-L(RT-DETR-L,800 输入,20 个版面类别)取官方发布的 ONNX,在 后处理之前截断;PP-DocLayout-S(PicoDet-S,480 输入,23 类)和 PP-LCNet_x1_0_doc_ori(页面方向)由官方推理模型经 paddle2onnx(opset 16)导出。 三者都是 Apache-2.0,可以再分发,包括商用。

文件

文件 内容 输入 大小
pp_doclayout_plus_l_800_fp16.rnpu 版面分析,20 类,300 个 query,无 NMS 800×800 RGB,拉伸 94.3 MB
pp_doclayout_s_480_fp16.rnpu 快速版面分析,23 类,NMS 在 CPU 上 480×480 RGB,拉伸 2.8 MB
pp_lcnet_doc_ori_224_fp16.rnpu 页面方向:旋转了 0、90、180 还是 270° 224×224 RGB,中心裁剪 3.4 MB
pp_doclayout_plus_l_labels.txt PP-DocLayout_plus-L 的 20 个类名,按索引顺序 186 B
pp_doclayout_s_labels.txt PP-DocLayout-S 的 23 个类名,按索引顺序 218 B

三个模型都吃 uint8 RGB,归一化已经放进模型里。版面类别包括段落标题和文档标题、正文、 摘要、表格、图片、图表、公式及公式编号、页眉页脚、脚注、印章、参考文献等。两套类别 不一样:PP-DocLayout-S 多了 table_title、chart_title、header_image、 footer_image,没有 reference_content。

实测

模型 推理 RK3588S 整个任务 RK3588S 推理 RK3588 整个任务 RK3588 doc_page.jpg 上的结果
PP-DocLayout_plus-L 415.18 ms 417.4 ms 408.68 ms 411.2 ms 4 paragraph_title、4 text、1 header、1 image、1 figure_title、1 formula、1 formula_number、1 number
PP-DocLayout-S 19.56 ms 21.6 ms 19.27 ms 21.4 ms 4 text、3 paragraph_title、1 header、1 image
PP-LCNet doc_ori 2.76 ms 3.2 ms 2.81 ms 3.2 ms 同一页转四个方向:4 个全对,最高分都是 0.93

数据来自 RCDL 的 benchmark: RCDL 0.3.0 的 conda 包,自研 NPU 运行时,NPU 驱动 0.9.8,单个 NPU 核,CPU 调频策略 performance、进程绑在 A76 大核上,预热至少一秒后取九次运行的中位数。RK3588S 的 BSP 内核是 6.1.118,RK3588 是 6.1.141。「推理」是运行时自己计时的一次模型运行(NPU 段 加上夹在中间的 CPU 算子),「整个任务」再加上缩放进输入张量和解码。doc_page.jpg 是一张有标题、正文、图片和公式的测试页。

与浮点模型对比:版面模型用 21 页(20 张渲染页,加上 RCDL 的 OCR 样图:一张中文商品标签),方向模型用 21 页、每页转四个方向。

构建 与浮点模型的一致性 分数差中位数 单核 / 三核(RK3588)
PP-DocLayout_plus-L F1 1.000 0.0001 409 / 249 ms
PP-DocLayout-S F1 0.992 0.0016 19 / 9 ms
PP-LCNet doc_ori 84 张转过的页面 top-1 全部相同;概率相差不超过 0.0005 — 3.2 / 1.3 ms

版面检测按分数 0.5、类别和 IoU 0.5 匹配,PP-DocLayout-S 两边用的是同样的阈值和 NMS。两个版面模型的单核 / 三核时间是在板子默认调频策略下测的。

用法

需要 RCDL 0.3.1 或更新版本,安装、下载和调用见上面的代码。框按页面原图的像素返回。

部署前须知

  • 按时间预算选版面模型。 PP-DocLayout_plus-L 单核约 409 ms、三核 249 ms; PP-DocLayout-S 约 19 ms 和 9 ms。两者都和各自的浮点模型非常接近;在测试页上,大模型 还多找到了图题、公式和公式编号。
  • 每个模型用自己的类别文件。 两份类别表顺序不同,长度也不同。
  • 两个版面模型都把页面拉伸到正方形输入上(训练时就是这样),再把框缩放回原图。 PP-DocLayout_plus-L 回答 300 个 query,没有 NMS;它的类别不是 COCO 的,创建时要传 coco_category_ids=False。PP-DocLayout-S 保留分数不低于 conf_thresh(0.5)的框, 在 CPU 上按类别做贪心 NMS,iou_thresh 为 0.6,与导出模型自带的值相同。
  • 方向:类别 k 表示页面顺时针转了 k × 90°。 要转正,就逆时针转回 k × 90°:k = 1 用 cv2.ROTATE_90_COUNTERCLOCKWISE,k = 2 用 cv2.ROTATE_180,k = 3 用 cv2.ROTATE_90_CLOCKWISE。softmax 已在图内,要传 apply_softmax=False。分类器默认 的 0.875 中心裁剪就是这个构建要的输入。单行文字倒置 180° 是另一回事,由 PP-OCR 的文字 方向分类器处理,见 ruisv/rcdl-ppocr。
  • 测速请用 performance 调频策略。 板子默认的 schedutil 会在 CPU 等 NPU 时降频; 在它下面,NPU 和 CPU 交替工作的测试项最多慢到上表的约四倍,而且每次都不一样,结果 本身不变。
  • .rnpu 是 RCDL 自己的格式,自研 NPU 栈仍标为实验性,格式以后还可能变。这些 文件在 RK3588 / RK3588S 上通过厂商 BSP 内核的 rknpu 驱动运行(rknpu 0.9.8,已在 6.1.118 和 6.1.141 两个内核上验证);RK3576、RK356x 未验证,主线内核的 rocket 驱动不支持。

许可

PP-DocLayout_plus-L、PP-DocLayout-S 和 PP-LCNet_x1_0_doc_ori 都由 PaddleOCR 以 Apache-2.0 发布;两份类别文件取自各模型发布的 inference.yml,条款相同。RCDL 本身是 Apache-2.0,与这些条款无关:它是能加载任意 .rnpu 或 .rknn 的通用运行时,上面的 许可只适用于这些权重和这些编译好的文件。每个构建的做法和输入约定见 docs/MODELS.md,RCDL 核实过的每个模型的许可情况见 model_zoo/。

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for ruisv/rcdl-pp-doc

Finetuned
(1)
this model