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P-OCRv4_mobile_det
|
| 6 |
+
- PaddlePaddle/PP-OCRv4_mobile_rec
|
| 7 |
+
- PaddlePaddle/PP-OCRv5_mobile_det
|
| 8 |
+
- PaddlePaddle/PP-OCRv5_server_rec
|
| 9 |
+
- PaddlePaddle/PP-OCRv6_medium_det
|
| 10 |
+
- PaddlePaddle/PP-OCRv6_medium_rec
|
| 11 |
+
pipeline_tag: image-to-text
|
| 12 |
+
tags:
|
| 13 |
+
- rknn
|
| 14 |
+
- rockchip
|
| 15 |
+
- rk3588
|
| 16 |
+
- npu
|
| 17 |
+
- edge
|
| 18 |
+
- ocr
|
| 19 |
+
- text-detection
|
| 20 |
+
- text-recognition
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# PP-OCR v4 · v5 · v6 for RK3588: text detection, direction and recognition
|
| 24 |
+
|
| 25 |
+
Compiled RKNN models (`.rknn`) for the **Rockchip RK3588 / RK3588S** NPU, ready
|
| 26 |
+
to load: no Paddle export, no calibration, no rknn-toolkit2. Built with
|
| 27 |
+
rknn-toolkit2 2.3.2, decoded and measured with
|
| 28 |
+
[**RCDL**](https://github.com/ruisv/rcdl). RCDL is a C++17 / Python library that
|
| 29 |
+
drives the NPU, RGA and VPU on these boards as one zero-copy pipeline.
|
| 30 |
+
|
| 31 |
+
Upstream: [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR): PP-OCRv4
|
| 32 |
+
mobile, PP-OCRv5 (mobile detection, server recognition) and PP-OCRv6 medium.
|
| 33 |
+
|
| 34 |
+
> [!TIP]
|
| 35 |
+
> **Redistributable, including commercially.** PaddleOCR is Apache-2.0 on the
|
| 36 |
+
> code and on every one of these models' cards. See [Licence](#licence).
|
| 37 |
+
|
| 38 |
+
## Files
|
| 39 |
+
|
| 40 |
+
| file | what it is | size |
|
| 41 |
+
|---|---|---|
|
| 42 |
+
| `ppocrv6_medium_det_rk3588.rknn` | text detection (DBNet), 480×480, int8 | 17.0 MB |
|
| 43 |
+
| `ppocrv6_medium_rec_logits_rk3588.rknn` | text recognition, 48×320, fp16, emits logits | 38.3 MB |
|
| 44 |
+
| `ppocrv5_det_rk3588.rknn` | text detection, v5 mobile, 480×480, int8 | 2.5 MB |
|
| 45 |
+
| `ppocrv5_server_rec_logits_rk3588.rknn` | text recognition, v5 server, 48×320, fp16, emits logits | 42.2 MB |
|
| 46 |
+
| `ppocrv4_det_rk3588.rknn` | text detection, v4 mobile, int8 | 2.5 MB |
|
| 47 |
+
| `ppocrv4_rec_rk3588.rknn` | text recognition, v4 mobile (CRNN) | 6.7 MB |
|
| 48 |
+
| `ppocr_cls_rk3588.rknn` | text-line direction, 0° or 180°, 192×48 | 0.8 MB |
|
| 49 |
+
| `ppocr_keys_v6_18710.txt` | dictionary for the v6 recogniser | 73 KB |
|
| 50 |
+
| `ppocr_keys_v5_18385.txt` | dictionary for the v5 recogniser | 72 KB |
|
| 51 |
+
| `ppocr_keys_v1_6625.txt` | dictionary for the v4 recogniser | 26 KB |
|
| 52 |
+
|
| 53 |
+
The three generations are complete stacks: a detector, then one recognition per
|
| 54 |
+
detected line. The direction classifier is shared and goes between the two.
|
| 55 |
+
|
| 56 |
+
## Measured on RK3588S
|
| 57 |
+
|
| 58 |
+
| | v4 | v5 | v6 |
|
| 59 |
+
|---|---|---|---|
|
| 60 |
+
| detection, one frame (NPU) | 42 ms | as v4 | 62 ms |
|
| 61 |
+
| recognition, one line | 36 ms | 88 ms | 40 ms |
|
| 62 |
+
| mean line confidence on the sample page | 0.661 | 0.928 | 0.930 |
|
| 63 |
+
|
| 64 |
+
librknnrt 2.3.2, NPU driver 0.9.8, one NPU core. All three detectors find the
|
| 65 |
+
same regions on the sample page, and the v5 detector measures the same as v4.
|
| 66 |
+
The difference is in the recognisers: v5 and v6 agree on the one character v4
|
| 67 |
+
reads differently, and v6 is the most confident and close to v4's speed.
|
| 68 |
+
|
| 69 |
+
## Use it
|
| 70 |
+
|
| 71 |
+
On the board (linux-aarch64):
|
| 72 |
+
|
| 73 |
+
```bash
|
| 74 |
+
conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
|
| 75 |
+
conda activate rcdl
|
| 76 |
+
hf download ruisv/rcdl-ppocr --local-dir ppocr # or curl each file from resolve/main/
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import cv2, numpy as np, rcdl
|
| 81 |
+
|
| 82 |
+
img = cv2.imread("page.jpg")
|
| 83 |
+
|
| 84 |
+
cfg = rcdl.OcrDetConfig()
|
| 85 |
+
cfg.bin_thresh, cfg.box_thresh, cfg.unclip_ratio = 0.2, 0.45, 1.4 # PP-OCRv6's own DB constants
|
| 86 |
+
det = rcdl.Engine("ppocr/ppocrv6_medium_det_rk3588.rknn").text_detector(config=cfg)
|
| 87 |
+
|
| 88 |
+
rcfg = rcdl.OcrRecConfig()
|
| 89 |
+
rcfg.apply_softmax = True # the softmax is deliberately not in this graph
|
| 90 |
+
rec = rcdl.Engine("ppocr/ppocrv6_medium_rec_logits_rk3588.rknn").text_recognizer(
|
| 91 |
+
"ppocr/ppocr_keys_v6_18710.txt", config=rcfg,
|
| 92 |
+
input_scale=1.0, input_shift=0.0, model_input="rgb888")
|
| 93 |
+
|
| 94 |
+
for box in rcdl.detect_text(det, img, "bgr888"):
|
| 95 |
+
pts = np.asarray(box.pts, np.float32).reshape(4, 2)
|
| 96 |
+
w = int(max(np.linalg.norm(pts[0] - pts[1]), np.linalg.norm(pts[3] - pts[2])))
|
| 97 |
+
h = int(max(np.linalg.norm(pts[0] - pts[3]), np.linalg.norm(pts[1] - pts[2])))
|
| 98 |
+
if w < 4 or h < 4 or h > w: # a vertical line needs rotating upright first
|
| 99 |
+
continue
|
| 100 |
+
dst = np.float32([[0, 0], [w, 0], [w, h], [0, h]])
|
| 101 |
+
crop = cv2.warpPerspective(img, cv2.getPerspectiveTransform(pts, dst), (w, h))
|
| 102 |
+
line = rcdl.recognize_text(rec, crop, "bgr888")
|
| 103 |
+
print(f"{line.score:.2f}", line.text)
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
When lines may be upside down, run the direction classifier on each crop before
|
| 107 |
+
recognising it:
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
angle = rcdl.Engine("ppocr/ppocr_cls_rk3588.rknn").text_angle_classifier()
|
| 111 |
+
r = angle.process(np.ascontiguousarray(crop), crop.shape[1], crop.shape[0], "bgr888")
|
| 112 |
+
if r.flip180:
|
| 113 |
+
crop = cv2.rotate(crop, cv2.ROTATE_180)
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## What to know before deploying
|
| 117 |
+
|
| 118 |
+
**The v5 and v6 recognisers emit logits, on purpose.** The 18k-way softmax is
|
| 119 |
+
the one operation that does not survive this runtime's fp16 path. In the graph,
|
| 120 |
+
its output sums to anywhere between 0.64 and 1.00 per step and has no peak.
|
| 121 |
+
CTC needs only the argmax, so the softmax moved to the CPU. Decode with
|
| 122 |
+
`apply_softmax=True`, and feed raw 0..255 (`input_scale=1, input_shift=0`).
|
| 123 |
+
|
| 124 |
+
**The dictionary must match the recogniser.** v6 has 18710 classes, v5 18385 and
|
| 125 |
+
v4 6625. A recogniser paired with the wrong file decodes to plausible-looking
|
| 126 |
+
wrong characters rather than failing. The right file for each one ships here.
|
| 127 |
+
|
| 128 |
+
**Use v6's own detection thresholds.** PP-OCRv6 publishes its own DB constants
|
| 129 |
+
(`bin 0.2, box 0.45, unclip 1.4`). The library defaults are the earlier
|
| 130 |
+
generations' constants.
|
| 131 |
+
|
| 132 |
+
**The direction classifier is not optional on rotated input.** A CTC recogniser
|
| 133 |
+
fed an upside-down line does not fail; it returns confident nonsense. The
|
| 134 |
+
classifier takes BGR at 192×48, with the softmax in the graph.
|
| 135 |
+
|
| 136 |
+
## Licence
|
| 137 |
+
|
| 138 |
+
Apache-2.0, on the PaddleOCR code and on every model card these builds come
|
| 139 |
+
from. The dictionaries are PaddleOCR's own files.
|
| 140 |
+
|
| 141 |
+
**RCDL itself is Apache-2.0 and is unrelated to these terms.** It is a
|
| 142 |
+
general-purpose runtime that loads any `.rknn`. The licence above applies to
|
| 143 |
+
*these weights and these compiled files* only.
|
| 144 |
+
|
| 145 |
+
How each build was made, and the input contract for every model, are
|
| 146 |
+
documented in RCDL's
|
| 147 |
+
[`docs/MODELS.md`](https://github.com/ruisv/rcdl/blob/main/docs/MODELS.md). The
|
| 148 |
+
licence status of every model RCDL has verified is in
|
| 149 |
+
[`model_zoo/`](https://github.com/ruisv/rcdl/tree/main/model_zoo).
|