update
Browse files
README.md
CHANGED
|
@@ -11,29 +11,48 @@ tags:
|
|
| 11 |
- onnx
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# ONNX -
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
## Usage
|
| 18 |
|
| 19 |
```
|
| 20 |
# onnxruntime-gpu for run it on GPU
|
| 21 |
-
pip install onnxruntime opencv-python numpy
|
| 22 |
```
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
```
|
| 28 |
-
python3 PP-DocLayout_plus-L/src/example.py
|
| 29 |
```
|
| 30 |
|
| 31 |
```
|
| 32 |
-
0.
|
| 33 |
-
0.
|
| 34 |
-
0.
|
| 35 |
-
0.
|
| 36 |
-
0.
|
| 37 |
```
|
| 38 |
|
| 39 |
Note:
|
|
@@ -45,3 +64,52 @@ the box count is in the second output.
|
|
| 45 |
full map in [PP-DocLayout_plus-L/src/example.py](PP-DocLayout_plus-L/src/example.py).
|
| 46 |
- Boxes overlap by design (no NMS in the model): filter by score (0.3 in the example) and handle<br>
|
| 47 |
the containment on your side if needed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
- onnx
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# ONNX - Paddle
|
| 15 |
+
|
| 16 |
+
| Model | FP32 | Task |
|
| 17 |
+
| --- | --- | --- |
|
| 18 |
+
| PP-DocLayout_plus-L | pp-docLayout_plus-l.onnx | layout detection |
|
| 19 |
+
| PP-OCRv6_medium_det | pp-ocrV6_medium_det.onnx | text line detection |
|
| 20 |
+
| PP-OCRv6_medium_rec | pp-ocrV6_medium_rec.onnx | text recognition |
|
| 21 |
|
| 22 |
## Usage
|
| 23 |
|
| 24 |
```
|
| 25 |
# onnxruntime-gpu for run it on GPU
|
| 26 |
+
pip install onnxruntime opencv-python numpy pyclipper
|
| 27 |
```
|
| 28 |
|
| 29 |
+
Every model folder has the same layout:
|
| 30 |
+
|
| 31 |
+
- `src/helper.py` = onnx session builder (provider selection, threads, memory options)
|
| 32 |
+
- `src/example.py` = full pipeline: image preprocess, inference, postprocess
|
| 33 |
+
- `onnx/` = the model file
|
| 34 |
+
|
| 35 |
+
Run the commands from the repository root.
|
| 36 |
+
|
| 37 |
+
Test images used by the examples:
|
| 38 |
+
|
| 39 |
+
- [jp_1.jpg](https://github.com/cimo/One_workspace/blob/main/file/test/jp_1.jpg) = full page
|
| 40 |
+
- [det_box_0294.jpg](https://github.com/cimo/One_workspace/blob/main/file/test/det_box_0294.jpg) = single text line
|
| 41 |
+
|
| 42 |
+
## PP-DocLayout_plus-L
|
| 43 |
+
|
| 44 |
+
- [PP-DocLayout_plus-L/src/example.py](PP-DocLayout_plus-L/src/example.py)
|
| 45 |
|
| 46 |
```
|
| 47 |
+
python3 PP-DocLayout_plus-L/src/example.py jp_1.jpg
|
| 48 |
```
|
| 49 |
|
| 50 |
```
|
| 51 |
+
0.936555 | header | [530, 62, 1213, 104]
|
| 52 |
+
0.910084 | table | [1066, 176, 1692, 260]
|
| 53 |
+
0.891657 | footer | [1066, 1157, 1198, 1175]
|
| 54 |
+
0.886924 | table | [54, 395, 1694, 799]
|
| 55 |
+
0.827543 | text | [55, 804, 1029, 959]
|
| 56 |
```
|
| 57 |
|
| 58 |
Note:
|
|
|
|
| 64 |
full map in [PP-DocLayout_plus-L/src/example.py](PP-DocLayout_plus-L/src/example.py).
|
| 65 |
- Boxes overlap by design (no NMS in the model): filter by score (0.3 in the example) and handle<br>
|
| 66 |
the containment on your side if needed.
|
| 67 |
+
|
| 68 |
+
## PP-OCRv6_medium_det
|
| 69 |
+
|
| 70 |
+
- [PP-OCRv6_medium_det/src/example.py](PP-OCRv6_medium_det/src/example.py)
|
| 71 |
+
|
| 72 |
+
```
|
| 73 |
+
python3 PP-OCRv6_medium_det/src/example.py jp_1.jpg
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
```
|
| 77 |
+
0.965487 | [[60, 1158], [850, 1158], [850, 1176], [60, 1176]]
|
| 78 |
+
0.827508 | [[1069, 1156], [1200, 1156], [1200, 1176], [1069, 1176]]
|
| 79 |
+
0.916008 | [[64, 1128], [837, 1128], [837, 1149], [64, 1149]]
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Note:
|
| 83 |
+
- Input = BGR image (plain `cv2.imread`, no channel swap) normalized with the ImageNet mean / std,<br>
|
| 84 |
+
CHW with batch dimension.
|
| 85 |
+
- Feed = `x`, the only input, with a fully dynamic shape.
|
| 86 |
+
- Resize = longest side capped to 960 (4000 hard limit), then both sides rounded to a multiple of 32.
|
| 87 |
+
- Output = a single probability map `[1, 1, height, width]`, the DB postprocess is on your side:<br>
|
| 88 |
+
binarize at 0.2, `cv2.findContours`, minimum area box, score as the mean probability inside the box,<br>
|
| 89 |
+
keep it over 0.45, expand it with pyclipper (unclip ratio 1.4) and rescale to the original image.
|
| 90 |
+
- Output row = `[score, [4 corner points]]` clockwise from the top-left corner, already in the original<br>
|
| 91 |
+
image space. Boxes are quads, not axis aligned: a rotated line keeps its rotation.
|
| 92 |
+
- Crop the quads and feed them to PP-OCRv6_medium_rec to get the text.
|
| 93 |
+
|
| 94 |
+
## PP-OCRv6_medium_rec
|
| 95 |
+
|
| 96 |
+
- [PP-OCRv6_medium_rec/src/example.py](PP-OCRv6_medium_rec/src/example.py)
|
| 97 |
+
|
| 98 |
+
```
|
| 99 |
+
python3 PP-OCRv6_medium_rec/src/example.py det_box_0294.jpg
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
```
|
| 103 |
+
0.953031 | (ε₯葨ε(δΈ)γ15γθ₯γγγ―ε₯葨ε(δΊ)γ10γεγ―ε₯葨ε(δΈ)γ16γθ₯γγγ―ε₯葨ε(δΊ)γ11γ)
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
Note:
|
| 107 |
+
- Input = a single cropped text line, not a full page: use the boxes from PP-OCRv6_medium_det.
|
| 108 |
+
- Input = BGR image (plain `cv2.imread`, no channel swap) resized to height 48 keeping the aspect ratio,<br>
|
| 109 |
+
scaled to 0..1 then normalized to -1..1, right padded with zeros, CHW with batch dimension.
|
| 110 |
+
- Feed = `x`, the only input, with a dynamic width (minimum 320, capped at 3200).
|
| 111 |
+
- Output = `[1, timeStep, 18710]` already softmaxed, decoded with a greedy CTC: drop the repeats first,<br>
|
| 112 |
+
then the blank at index 0.
|
| 113 |
+
- Character map = index 0 is the blank, 1..18708 are the lines of<br>
|
| 114 |
+
[PP-OCRv6_medium_rec/onnx/dictionary.txt](PP-OCRv6_medium_rec/onnx/dictionary.txt), 18709 is the space.
|
| 115 |
+
- Score = mean probability of the kept time steps.
|