cimo001 commited on
Commit
bf26b09
·
verified ·
1 Parent(s): 30c7ea4
Files changed (1) hide show
  1. README.md +111 -0
README.md ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: docling-project
4
+ pipeline_tag: object-detection
5
+ library_name: onnx
6
+ language:
7
+ - multilingual
8
+ tags:
9
+ - layout
10
+ - docling
11
+ - onnx
12
+ ---
13
+
14
+ # ONNX - Docling
15
+
16
+ | Model | FP32 | Task |
17
+ | --- | --- | --- |
18
+ | Docling-Layout-Heron | docling-layout-heron.onnx | layout detection |
19
+ | TableFormer | tableFormer_encoder.onnx, tableFormer_decoder.onnx, tableFormer_box.onnx | table structure recognition |
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ # onnxruntime-gpu for run it on GPU
25
+ pip install onnxruntime opencv-python numpy
26
+ ```
27
+
28
+ Every model folder has the same layout:
29
+
30
+ - `src/helper.py` = onnx session builder (provider selection, threads, memory options)
31
+ - `src/example.py` = full pipeline: image preprocess, inference, postprocess
32
+ - `onnx/` = the model file
33
+
34
+ Run the commands from the repository root.
35
+
36
+ Test images used by the examples:
37
+
38
+ - [jp_1.jpg](https://github.com/cimo/One_workspace/blob/main/file/test/invoice/jp_1.jpg) = full page
39
+ - [Table_1.jpg](https://github.com/cimo/One_workspace/blob/main/file/test/table/1.jpg) = single table
40
+
41
+ ## Docling-Layout-Heron
42
+
43
+ - [Docling-Layout-Heron/src/example.py](Docling-Layout-Heron/src/example.py)
44
+
45
+ ```
46
+ python3 Docling-Layout-Heron/src/example.py jp_1.jpg
47
+ ```
48
+
49
+ ```
50
+ 0.956688 | table | [1066, 852, 1692, 991]
51
+ 0.951113 | table | [57, 397, 1691, 782]
52
+ 0.932638 | table | [1063, 176, 1692, 260]
53
+ 0.929594 | page_footer | [1069, 1159, 1199, 1176]
54
+ 0.878344 | section_header | [797, 141, 953, 166]
55
+ ```
56
+
57
+ Note:
58
+ - Input = RGB image resized to 640x640 (bilinear), float32 0..1, CHW with batch dimension.
59
+ - Feed = `pixel_values`, the only input, fixed shape `[1, 3, 640, 640]`.
60
+ - Output = `logits` `[1, 300, 17]` (raw, apply the sigmoid) and `pred_boxes` `[1, 300, 4]` as<br>
61
+ `[centerX, centerY, width, height]` in the 0..1 range: multiply by the original image size.
62
+ - 17 label classes (caption, footnote, formula, list_item, page_footer, page_header, picture, section_header,<br>
63
+ table, text, title, ...): full list in [Docling-Layout-Heron/src/example.py](Docling-Layout-Heron/src/example.py).
64
+ - 300 queries per image, no NMS in the model: filter by score (0.5 in the example) and handle the overlap<br>
65
+ on your side. The same box can come out with two labels.
66
+ ## TableFormer
67
+
68
+ - [TableFormer/src/example.py](TableFormer/src/example.py)
69
+
70
+ ```
71
+ python3 TableFormer/src/example.py Table_1.jpg
72
+ ```
73
+
74
+ ```
75
+ fcel fcel fcel fcel fcel fcel fcel fcel fcel fcel nl
76
+ rhed fcel fcel fcel fcel fcel fcel fcel fcel fcel nl
77
+ rhed fcel fcel fcel fcel fcel fcel fcel fcel fcel nl
78
+ rhed fcel fcel fcel fcel fcel fcel fcel fcel fcel nl
79
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
80
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
81
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
82
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
83
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
84
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
85
+ rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl
86
+ rhed lcel lcel lcel fcel fcel fcel fcel fcel fcel nl
87
+
88
+ [24, 31, 127, 79]
89
+ [180, 33, 279, 79]
90
+ [333, 27, 436, 83]
91
+ [581, 35, 866, 84]
92
+ [1003, 6, 1094, 78]
93
+ ```
94
+
95
+ Note:
96
+ - Input = a single table crop, not a full page: use the `table` boxes from Docling-Layout-Heron.
97
+ - Input = RGB image resized to height 1024, normalized with the table mean / std (values in the example),<br>
98
+ resized to 448x448, transposed to `[channel, width, height]` (width before height) with batch dimension.
99
+ - Three graphs, exported with fixed shapes:<br>
100
+ `tableFormer_encoder.onnx` = feed `image` `[1, 3, 448, 448]`, output `memory` `[784, 1, 512]` and `box` `[1, 784, 512]`;<br>
101
+ `tableFormer_decoder.onnx` = one tag per call, feed `tag` `[1]`, `position` `[1]`, `memory` and `buffer` `[6, 1024, 1, 512]`,<br>
102
+ output `logit` `[1, 13]`, `hidden` `[1, 512]` and `state` `[6, 1, 1, 512]`;<br>
103
+ `tableFormer_box.onnx` = feed `box` and `hidden` `[32, 512]` (zero padded), output `class` `[32, 3]` and `coordinate` `[32, 4]`.
104
+ - Decode = greedy: start from `<start>`, write `state` in `buffer[:, position]` after every call, stop at `<end>`<br>
105
+ or at 1024 tags.
106
+ - Tag = OTSL: `fcel` cell with content, `ecel` empty cell, `lcel` merged with the cell on the left, `ucel` merged with<br>
107
+ the cell above, `xcel` merged with both, `ched` column header, `rhed` row header, `srow` section row, `nl` end of the row.
108
+ - The first output of the example is the grid, one line per table row. The second is one box per cell, in the same<br>
109
+ order as the cells of the grid (`lcel`, `ucel`, `xcel` and `nl` have no box), `[x1, y1, x2, y2]` in the table crop space.
110
+ - A cell merged over several columns gets a single box that goes from its first to its last column.
111
+ - The model gives the structure only: read the text with an OCR model and assign it to the cells by box overlap.